git.iko.soy/typeable/cabal2nix
on master help sign in
Use helpers for DerivationSource creation.
a91fac7Kevin Quick
hackage2nix/Main.hs+1−1
@@ -151,7 +151,7 @@ main = do
151
151
152 drv :: Derivation
152 drv :: Derivation
153 drv = fromGenericPackageDescription haskellResolver nixpkgsResolver targetPlatform (compilerInfo config) flagAssignment [] descr
153 drv = fromGenericPackageDescription haskellResolver nixpkgsResolver targetPlatform (compilerInfo config) flagAssignment [] descr
154− & src .~ DerivationSource "url" ("mirror://hackage/" ++ display pkgId ++ ".tar.gz") "" tarballSHA256
154+ & src .~ urlDerivationSource ("mirror://hackage/" ++ display pkgId ++ ".tar.gz") tarballSHA256
155 & editedCabalFile .~ cabalSHA256
155 & editedCabalFile .~ cabalSHA256
156 & metaSection.hydraPlatforms %~ (`Set.difference` Map.findWithDefault Set.empty name (dontDistributePackages config))
156 & metaSection.hydraPlatforms %~ (`Set.difference` Map.findWithDefault Set.empty name (dontDistributePackages config))
157 & metaSection.maintainers .~ Map.findWithDefault Set.empty name globalPackageMaintainers
157 & metaSection.maintainers .~ Map.findWithDefault Set.empty name globalPackageMaintainers
src/Distribution/Nixpkgs/Fetch.hs+14−4
@@ -6,7 +6,7 @@
6module Distribution.Nixpkgs.Fetch
6module Distribution.Nixpkgs.Fetch
7 ( Source(..)
7 ( Source(..)
8 , Hash(..)
8 , Hash(..)
9− , DerivationSource(..), fromDerivationSource
9+ , DerivationSource(..), fromDerivationSource, urlDerivationSource
10 , fetch
10 , fetch
11 , fetchWith
11 , fetchWith
12 ) where
12 ) where
@@ -68,6 +68,9 @@ instance FromJSON DerivationSource where
68 <*> o .: "sha256"
68 <*> o .: "sha256"
69 parseJSON _ = error "invalid DerivationSource"
69 parseJSON _ = error "invalid DerivationSource"
70
70
71+urlDerivationSource :: String -> String -> DerivationSource
72+urlDerivationSource url hash = DerivationSource "url" url "" hash
73+
71fromDerivationSource :: DerivationSource -> Source
74fromDerivationSource :: DerivationSource -> Source
72fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision (Certain derivHash) "."
75fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision (Certain derivHash) "."
73
76
@@ -102,17 +105,19 @@ fetch optSubModules f = runMaybeT . fetchers where
102 guard $ existsDir || existsFile
105 guard $ existsDir || existsFile
103 let path' | '/' `elem` path = path
106 let path' | '/' `elem` path = path
104 | otherwise = "./" ++ path
107 | otherwise = "./" ++ path
105− process (DerivationSource "" path' "" "", path') <|> localArchive path'
108+ process (localDerivationSource path', path') <|> localArchive path'
106
109
107 localArchive :: FilePath -> MaybeT IO (DerivationSource, a)
110 localArchive :: FilePath -> MaybeT IO (DerivationSource, a)
108 localArchive path = do
111 localArchive path = do
109 absolutePath <- liftIO $ canonicalizePath path
112 absolutePath <- liftIO $ canonicalizePath path
110 unpacked <- snd <$> fetchWith (False, "url", ["--unpack"]) (Source ("file://" ++ absolutePath) "" UnknownHash ".")
113 unpacked <- snd <$> fetchWith (False, "url", ["--unpack"]) (Source ("file://" ++ absolutePath) "" UnknownHash ".")
111− process (DerivationSource "" absolutePath "" "", unpacked)
114+ process (localDerivationSource absolutePath, unpacked)
112
115
113 process :: (DerivationSource, FilePath) -> MaybeT IO (DerivationSource, a)
116 process :: (DerivationSource, FilePath) -> MaybeT IO (DerivationSource, a)
114 process (derivSource, file) = (,) derivSource <$> f file
117 process (derivSource, file) = (,) derivSource <$> f file
115
118
119+ localDerivationSource p = DerivationSource "" p "" ""
120+
116-- | Like 'fetch', but allows to specify which script to use.
121-- | Like 'fetch', but allows to specify which script to use.
117fetchWith :: (Bool, String, [String]) -> Source -> MaybeT IO (DerivationSource, FilePath)
122fetchWith :: (Bool, String, [String]) -> Source -> MaybeT IO (DerivationSource, FilePath)
118fetchWith (supportsRev, kind, addArgs) source = do
123fetchWith (supportsRev, kind, addArgs) source = do
@@ -137,7 +142,12 @@ fetchWith (supportsRev, kind, addArgs) source = do
137 buf' = BS.unlines (reverse ls)
142 buf' = BS.unlines (reverse ls)
138 case length ls of
143 case length ls of
139 0 -> return Nothing
144 0 -> return Nothing
140− 1 -> return (Just (DerivationSource kind (sourceUrl source) "" (BS.unpack (head ls)) , sourceUrl source))
145+ 1 -> return (Just (DerivationSource { derivKind = kind
146+ , derivUrl = (sourceUrl source)
147+ , derivRevision = ""
148+ , derivHash = (BS.unpack (head ls))
149+ }
150+ , sourceUrl source))
141 _ -> case eitherDecode buf' of
151 _ -> case eitherDecode buf' of
142 Left err -> error ("invalid JSON: " ++ err ++ " in " ++ show buf')
152 Left err -> error ("invalid JSON: " ++ err ++ " in " ++ show buf')
143 Right ds -> return (Just (ds { derivKind = kind }, BS.unpack l))
153 Right ds -> return (Just (ds { derivKind = kind }, BS.unpack l))
src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+4−4
@@ -98,7 +98,7 @@ fromDB hackageDBIO pkg = do
98 vd <- maybe unknownPackageError return (DB.lookup name hackageDB >>= lookupVersion)
98 vd <- maybe unknownPackageError return (DB.lookup name hackageDB >>= lookupVersion)
99 let ds = case DB.tarballSha256 vd of
99 let ds = case DB.tarballSha256 vd of
100 Nothing -> Nothing
100 Nothing -> Nothing
101− Just hash -> Just (DerivationSource "url" url "" hash)
101+ Just hash -> Just (urlDerivationSource url hash)
102 return (ds, setCabalFileHash (DB.cabalFileSha256 vd) (DB.cabalFile vd))
102 return (ds, setCabalFileHash (DB.cabalFileSha256 vd) (DB.cabalFile vd))
103 where
103 where
104 pkgId :: Cabal.PackageIdentifier
104 pkgId :: Cabal.PackageIdentifier
@@ -144,20 +144,20 @@ sourceFromHackage optHash pkgId cabalDir = do
144 -- Use the cached hash (either from cache file or given on cmdline via sha256 opt)
144 -- Use the cached hash (either from cache file or given on cmdline via sha256 opt)
145 -- if available, otherwise download from hackage to compute hash.
145 -- if available, otherwise download from hackage to compute hash.
146 case cachedHash of
146 case cachedHash of
147− Guess hash -> return $ DerivationSource "url" url "" hash
147+ Guess hash -> return $ urlDerivationSource url hash
148 Certain hash ->
148 Certain hash ->
149 -- We need to force the hash here. If we didn't do this, then when reading the
149 -- We need to force the hash here. If we didn't do this, then when reading the
150 -- hash from the cache file, the cache file will still be open for reading
150 -- hash from the cache file, the cache file will still be open for reading
151 -- (because lazy io) when writeFile opens the file again for writing. By forcing
151 -- (because lazy io) when writeFile opens the file again for writing. By forcing
152 -- the hash here, we ensure that the file is closed before opening it again.
152 -- the hash here, we ensure that the file is closed before opening it again.
153 seq (length hash) $
153 seq (length hash) $
154− DerivationSource "url" url "" hash <$ writeFile cacheFile hash
154+ urlDerivationSource url hash <$ writeFile cacheFile hash
155 UnknownHash -> do
155 UnknownHash -> do
156 maybeHash <- runMaybeT (derivHash . fst <$> fetchWith (False, "url", []) (Source url "" UnknownHash cabalDir))
156 maybeHash <- runMaybeT (derivHash . fst <$> fetchWith (False, "url", []) (Source url "" UnknownHash cabalDir))
157 case maybeHash of
157 case maybeHash of
158 Just hash ->
158 Just hash ->
159 seq (length hash) $
159 seq (length hash) $
160− DerivationSource "url" url "" hash <$ writeFile cacheFile hash
160+ urlDerivationSource url hash <$ writeFile cacheFile hash
161 Nothing -> do
161 Nothing -> do
162 hPutStr stderr $ unlines
162 hPutStr stderr $ unlines
163 [ "*** cannot compute hash. (Not a hackage project?)"
163 [ "*** cannot compute hash. (Not a hackage project?)"