@@ -6,7 +6,7 @@
6module Distribution.Nixpkgs.Fetch
6module Distribution.Nixpkgs.Fetch
7 ( Source(..)
7 ( Source(..)
9− , DerivationSource(..), fromDerivationSource
9+ , DerivationSource(..), fromDerivationSource, urlDerivationSource
11 , fetchWith
11 , fetchWith
@@ -68,6 +68,9 @@ instance FromJSON DerivationSource where
68 <*> o .: "sha256"
68 <*> o .: "sha256"
69 parseJSON _ = error "invalid DerivationSource"
69 parseJSON _ = error "invalid DerivationSource"
71+urlDerivationSource :: String -> String -> DerivationSource
72+urlDerivationSource url hash = DerivationSource "url" url "" hash
71fromDerivationSource :: DerivationSource -> Source
74fromDerivationSource :: DerivationSource -> Source
72fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision (Certain derivHash) "."
75fromDerivationSource DerivationSource{..} = Source derivUrl derivRevision (Certain derivHash) "."
@@ -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'
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)
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
119+ localDerivationSource p = DerivationSource "" p "" ""
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))
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))