git.iko.soy/typeable/cabal2nix
on master help sign in
Use helpers for DerivationSource creation.
commita91fac7c6c1047da6f8b32b00d7dc2e18ba71351 authorKevin Quick <kquick@galois.com> dateWed 15 Aug 2018, 21:52 (8 years ago) parentb8dc5b1
3 files changed+19−9
hackage2nix/Main.hs+1−1 src/Distribution/Nixpkgs/Fetch.hs+14−4 src/Distribution/Nixpkgs/Haskell/PackageSourceSpec.hs+4−4
hackage2nix/Main.hs+1−1
@@ -151,7 +151,7 @@ main = do
151151
152152 drv :: Derivation
153153 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
155155 & editedCabalFile .~ cabalSHA256
156156 & metaSection.hydraPlatforms %~ (`Set.difference` Map.findWithDefault Set.empty name (dontDistributePackages config))
157157 & metaSection.maintainers .~ Map.findWithDefault Set.empty name globalPackageMaintainers
src/Distribution/Nixpkgs/Fetch.hs+14−4
@@ -6,7 +6,7 @@
66module Distribution.Nixpkgs.Fetch
77 ( Source(..)
88 , Hash(..)
9− , DerivationSource(..), fromDerivationSource
9+ , DerivationSource(..), fromDerivationSource, urlDerivationSource
1010 , fetch
1111 , fetchWith
1212 ) where
@@ -68,6 +68,9 @@ instance FromJSON DerivationSource where
6868 <*> o .: "sha256"
6969 parseJSON _ = error "invalid DerivationSource"
7070
71+urlDerivationSource :: String -> String -> DerivationSource
72+urlDerivationSource url hash = DerivationSource "url" url "" hash
73+
7174fromDerivationSource :: DerivationSource -> Source
7275fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision (Certain derivHash) "."
7376
@@ -102,17 +105,19 @@ fetch optSubModules f = runMaybeT . fetchers where
102105 guard $ existsDir || existsFile
103106 let path' | '/' `elem` path = path
104107 | otherwise = "./" ++ path
105− process (DerivationSource "" path' "" "", path') <|> localArchive path'
108+ process (localDerivationSource path', path') <|> localArchive path'
106109
107110 localArchive :: FilePath -> MaybeT IO (DerivationSource, a)
108111 localArchive path = do
109112 absolutePath <- liftIO $ canonicalizePath path
110113 unpacked <- snd <$> fetchWith (False, "url", ["--unpack"]) (Source ("file://" ++ absolutePath) "" UnknownHash ".")
111− process (DerivationSource "" absolutePath "" "", unpacked)
114+ process (localDerivationSource absolutePath, unpacked)
112115
113116 process :: (DerivationSource, FilePath) -> MaybeT IO (DerivationSource, a)
114117 process (derivSource, file) = (,) derivSource <$> f file
115118
119+ localDerivationSource p = DerivationSource "" p "" ""
120+
116121-- | Like 'fetch', but allows to specify which script to use.
117122fetchWith :: (Bool, String, [String]) -> Source -> MaybeT IO (DerivationSource, FilePath)
118123fetchWith (supportsRev, kind, addArgs) source = do
@@ -137,7 +142,12 @@ fetchWith (supportsRev, kind, addArgs) source = do
137142 buf' = BS.unlines (reverse ls)
138143 case length ls of
139144 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))
141151 _ -> case eitherDecode buf' of
142152 Left err -> error ("invalid JSON: " ++ err ++ " in " ++ show buf')
143153 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
9898 vd <- maybe unknownPackageError return (DB.lookup name hackageDB >>= lookupVersion)
9999 let ds = case DB.tarballSha256 vd of
100100 Nothing -> Nothing
101− Just hash -> Just (DerivationSource "url" url "" hash)
101+ Just hash -> Just (urlDerivationSource url hash)
102102 return (ds, setCabalFileHash (DB.cabalFileSha256 vd) (DB.cabalFile vd))
103103 where
104104 pkgId :: Cabal.PackageIdentifier
@@ -144,20 +144,20 @@ sourceFromHackage optHash pkgId cabalDir = do
144144 -- Use the cached hash (either from cache file or given on cmdline via sha256 opt)
145145 -- if available, otherwise download from hackage to compute hash.
146146 case cachedHash of
147− Guess hash -> return $ DerivationSource "url" url "" hash
147+ Guess hash -> return $ urlDerivationSource url hash
148148 Certain hash ->
149149 -- We need to force the hash here. If we didn't do this, then when reading the
150150 -- hash from the cache file, the cache file will still be open for reading
151151 -- (because lazy io) when writeFile opens the file again for writing. By forcing
152152 -- the hash here, we ensure that the file is closed before opening it again.
153153 seq (length hash) $
154− DerivationSource "url" url "" hash <$ writeFile cacheFile hash
154+ urlDerivationSource url hash <$ writeFile cacheFile hash
155155 UnknownHash -> do
156156 maybeHash <- runMaybeT (derivHash . fst <$> fetchWith (False, "url", []) (Source url "" UnknownHash cabalDir))
157157 case maybeHash of
158158 Just hash ->
159159 seq (length hash) $
160− DerivationSource "url" url "" hash <$ writeFile cacheFile hash
160+ urlDerivationSource url hash <$ writeFile cacheFile hash
161161 Nothing -> do
162162 hPutStr stderr $ unlines
163163 [ "*** cannot compute hash. (Not a hackage project?)"