git.iko.soy/typeable/cabal2nix
on master help sign in
hackage4nix.hs: add --force flag to force re-generation of expressions even if they contain patchPhase sections, etc.
f810f16Peter Simons
src/hackage4nix.hs+8−2
@@ -29,6 +29,7 @@ data Configuration = Configuration
29 { _msgDebug :: String -> IO ()
29 { _msgDebug :: String -> IO ()
30 , _msgInfo :: String -> IO ()
30 , _msgInfo :: String -> IO ()
31 , _hackageDb :: DB.Hackage
31 , _hackageDb :: DB.Hackage
32+ , _force :: Bool
32 }
33 }
33
34
34defaultConfiguration :: Configuration
35defaultConfiguration :: Configuration
@@ -36,6 +37,7 @@ defaultConfiguration = Configuration
36 { _msgDebug = hPutStrLn stderr
37 { _msgDebug = hPutStrLn stderr
37 , _msgInfo = hPutStrLn stderr
38 , _msgInfo = hPutStrLn stderr
38 , _hackageDb = DB.empty
39 , _hackageDb = DB.empty
40+ , _force = False
39 }
41 }
40
42
41type Hackage4Nix a = RWST Configuration () PkgSet IO a
43type Hackage4Nix a = RWST Configuration () PkgSet IO a
@@ -79,7 +81,9 @@ parseNixFile path buf
79 | any (`isSuffixOf`path) badPackagePaths
81 | any (`isSuffixOf`path) badPackagePaths
80 = msgDebug ("ignore known bad package " ++ path) >> return Nothing
82 = msgDebug ("ignore known bad package " ++ path) >> return Nothing
81 | Just deriv <- parseDerivation buf
83 | Just deriv <- parseDerivation buf
84+ = do forceReGen <- asks _force
85+ let reGen = regenerateDerivation deriv buf
82− = return (Just (Pkg deriv path (regenerateDerivation deriv buf)))
86+ return (Just (Pkg deriv path (forceReGen || reGen)))
83 | otherwise = msgInfo ("failed to parse file " ++ path) >> return Nothing
87 | otherwise = msgInfo ("failed to parse file " ++ path) >> return Nothing
84
88
85selectLatestVersions :: PkgSet -> PkgSet
89selectLatestVersions :: PkgSet -> PkgSet
@@ -163,7 +167,7 @@ normalizeMaintainer x
163 | "self.stdenv.lib.maintainers." `isPrefixOf` x = drop 28 x
167 | "self.stdenv.lib.maintainers." `isPrefixOf` x = drop 28 x
164 | otherwise = x
168 | otherwise = x
165
169
166−data CliOption = PrintHelp | Verbose
170+data CliOption = PrintHelp | Verbose | ForceRegen
167 deriving (Eq)
171 deriving (Eq)
168
172
169main :: IO ()
173main :: IO ()
@@ -172,6 +176,7 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
172 options =
176 options =
173 [ Option "h" ["help"] (NoArg PrintHelp) "show this help text"
177 [ Option "h" ["help"] (NoArg PrintHelp) "show this help text"
174 , Option "v" ["verbose"] (NoArg Verbose) "enable noisy debug output"
178 , Option "v" ["verbose"] (NoArg Verbose) "enable noisy debug output"
179+ , Option "" ["force"] (NoArg ForceRegen) "re-generate all files in place"
175 ]
180 ]
176
181
177 usage :: String
182 usage :: String
@@ -198,6 +203,7 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
198 let cfg = defaultConfiguration
203 let cfg = defaultConfiguration
199 { _msgDebug = if Verbose `elem` opts then _msgDebug defaultConfiguration else const (return ())
204 { _msgDebug = if Verbose `elem` opts then _msgDebug defaultConfiguration else const (return ())
200 , _hackageDb = hackage
205 , _hackageDb = hackage
206+ , _force = ForceRegen `elem` opts
201 }
207 }
202 ((),_,()) <- runRWST (updateNixPkgs args) cfg Set.empty
208 ((),_,()) <- runRWST (updateNixPkgs args) cfg Set.empty
203 return ()
209 return ()