@@ -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))