git.iko.soy/typeable/cabal2nix
on master help sign in
Drop the obsolete hackage4nix utility.
commitb5dd067f793d430ba0fa4331e08464a6b4b1d37d authorPeter Simons <simons@cryp.to> dateThu 8 Jan 2015, 22:42 (12 years ago) parent30d78b5
3 files changed−286
cabal2nix.cabal−25 src/hackage4nix.hs−260 test/doc-test.hs−1
cabal2nix.cabal−25
@@ -80,31 +80,6 @@ Executable cabal2nix
8080 Distribution.NixOS.PrettyPrinting
8181 Distribution.NixOS.Regex
8282
83−Executable hackage4nix
84− main-is: hackage4nix.hs
85− hs-source-dirs: src
86− Build-Depends: base >= 3 && < 5, regex-posix, pretty, Cabal >= 1.18,
87− mtl, containers, directory, filepath, hackage-db >= 1.11,
88− transformers, process, deepseq, bytestring, SHA
89− Extensions: PatternGuards, RecordWildCards, CPP
90− Ghc-Options: -Wall
91− other-modules: Cabal2Nix.CorePackages
92− Cabal2Nix.Flags
93− Cabal2Nix.Generate
94− Cabal2Nix.Package
95− Cabal2Nix.Hackage
96− Cabal2Nix.License
97− Cabal2Nix.Name
98− Cabal2Nix.Normalize
99− Cabal2Nix.PostProcess
100− Distribution.NixOS.Fetch
101− Distribution.NixOS.Derivation.Cabal
102− Distribution.NixOS.Derivation.License
103− Distribution.NixOS.Derivation.Meta
104− Distribution.NixOS.PrettyPrinting
105− Distribution.NixOS.PackageMap
106− Distribution.NixOS.Regex
107−
10883Executable hackage2nix
10984 main-is: hackage2nix.hs
11085 hs-source-dirs: src
src/hackage4nix.hsdeleted−260
@@ -1,260 +0,0 @@
1−module Main ( main ) where
2−
3−import Cabal2Nix.Generate
4−import Cabal2Nix.Normalize
5−import Control.Exception ( bracket )
6−import Control.Monad.RWS
7−import Data.List
8−import qualified Data.Set as Set
9−import Data.Version
10−import qualified Cabal2Nix.Hackage as DB
11−import Distribution.NixOS.Derivation.Cabal
12−import Distribution.Package
13−import Distribution.PackageDescription ( GenericPackageDescription() )
14−import Distribution.Text
15−import System.Console.GetOpt ( OptDescr(..), ArgDescr(..), ArgOrder(..), usageInfo, getOpt )
16−import System.Directory
17−import System.Environment
18−import System.Exit
19−import System.FilePath
20−import System.IO
21−import Text.Regex.Posix
22−
23−data Pkg = Pkg Derivation FilePath Bool
24− deriving (Show, Eq, Ord)
25−
26−type PkgSet = Set.Set Pkg
27−
28−data Configuration = Configuration
29− { _msgDebug :: String -> IO ()
30− , _msgInfo :: String -> IO ()
31− , _hackageDb :: DB.Hackage
32− , _force :: Bool
33− }
34−
35−defaultConfiguration :: Configuration
36−defaultConfiguration = Configuration
37− { _msgDebug = hPutStrLn stderr
38− , _msgInfo = hPutStrLn stderr
39− , _hackageDb = DB.empty
40− , _force = False
41− }
42−
43−type Hackage4Nix a = RWST Configuration () PkgSet IO a
44−
45−io :: (MonadIO m) => IO a -> m a
46−io = liftIO
47−
48−readDirectory :: FilePath -> IO [FilePath]
49−readDirectory dirpath = do
50− entries <- getDirectoryContents dirpath
51− return [ x | x <- entries, x /= ".", x /= ".." ]
52−
53−msgDebug, msgInfo :: String -> Hackage4Nix ()
54−msgDebug msg = ask >>= \s -> io (_msgDebug s msg)
55−msgInfo msg = ask >>= \s -> io (_msgInfo s msg)
56−
57−getCabalPackage :: String -> Version -> Hackage4Nix GenericPackageDescription
58−getCabalPackage name vers = do
59− db <- asks _hackageDb
60− case DB.lookup name db of
61− Just db' -> case DB.lookup vers db' of
62− Just pkg -> return pkg
63− Nothing -> fail ("hackage doesn't know about " ++ name ++ " version " ++ display vers)
64− Nothing -> fail ("hackage doesn't know about " ++ show name)
65−
66−discoverNixFiles :: (FilePath -> Hackage4Nix ()) -> FilePath -> Hackage4Nix ()
67−discoverNixFiles yield dirOrFile = do
68− isFile <- io (doesFileExist dirOrFile)
69− case (isFile, takeExtension dirOrFile) of
70− (True,".nix") -> yield dirOrFile
71− (True,_) -> return ()
72− (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>))
73−
74−regenerateDerivation :: Derivation -> String -> Bool
75−regenerateDerivation _ buf = not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches|broken")
76−
77−parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)
78−parseNixFile path buf
79− | not (buf =~ "cabal.mkDerivation")
80− = msgDebug ("ignore non-cabal package " ++ path) >> return Nothing
81− | any (`isSuffixOf`path) badPackagePaths
82− = msgDebug ("ignore known bad package " ++ path) >> return Nothing
83− | Just deriv <- parseDerivation buf
84− = do forceReGen <- asks _force
85− let reGen = regenerateDerivation deriv buf
86− return (Just (Pkg deriv path (forceReGen || reGen)))
87− | otherwise = msgInfo ("failed to parse file " ++ path) >> return Nothing
88−
89−selectLatestVersions :: PkgSet -> PkgSet
90−selectLatestVersions = Set.fromList . nubBy f2 . sortBy f1 . Set.toList
91− where
92− f1 (Pkg deriv1 _ _) (Pkg deriv2 _ _)
93− | pname deriv1 == pname deriv2 = compare (version deriv2) (version deriv1)
94− | otherwise = compare (pname deriv1) (pname deriv2)
95− f2 (Pkg deriv1 _ _) (Pkg deriv2 _ _) = pname deriv1 == pname deriv2
96−
97−discoverUpdates :: String -> Version -> Hackage4Nix [Version]
98−discoverUpdates name vers = do
99− db <- asks _hackageDb
100− case DB.lookup name db of
101− Just pkgs -> return (filter (>vers) (DB.keys pkgs))
102− Nothing -> fail ("discoverUpdates cannot find package " ++ show name ++ " on Hackage")
103−
104−updateNixPkgs :: [FilePath] -> Hackage4Nix ()
105−updateNixPkgs paths = do
106− -- Traverse the given directorcy structure and discover all available
107− -- Haskell packages.
108− forM_ paths $ \fileOrDir -> do
109− msgDebug $ "scanning " ++ show fileOrDir
110− flip discoverNixFiles fileOrDir $ \file -> do
111− nix' <- io (readFile file) >>= parseNixFile file
112− flip (maybe (return ())) nix' $ \nix ->
113− modify (Set.insert nix)
114−
115− -- Re-generate all Haskell packages in-place (unless
116− -- 'regenerateDerivation' decided that this particular package
117− -- shouldn't be touched.
118− latestVersions <- gets selectLatestVersions
119− let latestVersionMap :: [(String,Version)]
120− latestVersionMap = [ (pname deriv, version deriv) | Pkg deriv _ _ <- Set.toList latestVersions ]
121− let isLatest :: Derivation -> Bool
122− isLatest deriv = maybe False (version deriv ==) (lookup (pname deriv) latestVersionMap)
123− get >>= \pkgset -> forM_ (Set.toList pkgset) $ \nix -> do
124− let Pkg deriv path regenerate = nix
125− maints = maintainers (metaSection deriv)
126− plats = platforms (metaSection deriv)
127− hplats = if isLatest deriv then hydraPlatforms (metaSection deriv) else ["self.stdenv.lib.platforms.none"]
128−
129− when regenerate $ do
130− msgDebug ("re-generate " ++ path)
131− pkg <- getCabalPackage (pname deriv) (version deriv)
132− let deriv' = (cabal2nix pkg) { src = src deriv
133− , runHaddock = runHaddock deriv
134− , doCheck = doCheck deriv
135− , jailbreak = jailbreak deriv
136− , hyperlinkSource = hyperlinkSource deriv
137− , enableSplitObjs = enableSplitObjs deriv
138− }
139− meta = metaSection deriv'
140− plats' = if null plats then platforms meta else plats
141− deriv'' = deriv' { metaSection = meta
142− { maintainers = maints
143− , platforms = plats'
144− , hydraPlatforms = hplats
145− }
146− }
147− io $ writeFile path (show (disp (normalize deriv'')))
148−
149− -- Discover available updates and print the appropriate cabal2nix
150− -- command line to the console for the user to execute at his/her
151− -- discretion.
152− updates' <- forM (Set.elems latestVersions) $ \pkg -> do
153− let Pkg deriv _ _ = pkg
154− updates <- discoverUpdates (pname deriv) (version deriv)
155− return (pkg,updates)
156− let updates = [ u | u@(_,_:_) <- updates' ]
157− unless (null updates) $ do
158− msgInfo "The following updates are available:"
159− forM_ updates $ \(pkg,versions) -> do
160− let Pkg deriv path regenerate = pkg
161− msgInfo ""
162− msgInfo $ display (packageId deriv) ++ ":"
163− forM_ versions $ \newVersion -> do
164− let deriv' = deriv { version = newVersion }
165− msgInfo $ " " ++ genCabal2NixCmdline (Pkg deriv' path regenerate)
166− return ()
167−
168−genCabal2NixCmdline :: Pkg -> String
169−genCabal2NixCmdline (Pkg deriv path _) = unwords $ ["cabal2nix"] ++ opts ++ ['>':path']
170− where
171− meta = metaSection deriv
172− opts = [cabal] ++ maints' ++ plats' ++ hplats'
173− ++ (if jailbreak deriv then ["--jailbreak"] else [])
174− ++ (if runHaddock deriv then [] else ["--no-haddock"])
175− ++ (if doCheck deriv then [] else ["--no-check"])
176− cabal = "cabal://" ++ display (packageId deriv)
177− maints' = [ "--maintainer=" ++ normalizeMaintainer m | m <- maintainers meta ]
178− plats'
179− | ["self.ghc.meta.platforms"] == platforms meta = []
180− | otherwise = [ "--platform=" ++ p | p <- platforms meta ]
181− hplats'
182− | ["self.ghc.meta.platforms"] == platforms meta = []
183− | otherwise = [ "--hydra-platform=" ++ p | p <- hydraPlatforms meta ]
184− path'
185− | path =~ "/[0-9\\.]+\\.nix$" = replaceFileName path (display (version deriv) <.> "nix")
186− | otherwise = path
187−
188−normalizeMaintainer :: String -> String
189−normalizeMaintainer x
190− | "self.stdenv.lib.maintainers." `isPrefixOf` x = drop 28 x
191− | otherwise = x
192−
193−data CliOption = PrintHelp | Verbose | ForceRegen
194− deriving (Eq)
195−
196−main :: IO ()
197−main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
198− let options :: [OptDescr CliOption]
199− options =
200− [ Option "h" ["help"] (NoArg PrintHelp) "show this help text"
201− , Option "v" ["verbose"] (NoArg Verbose) "enable noisy debug output"
202− , Option "" ["force"] (NoArg ForceRegen) "re-generate all files in place"
203− ]
204−
205− usage :: String
206− usage = usageInfo "Usage: hackage4nix [options] [dir-or-file ...]" options ++ unlines
207− [ ""
208− , "The purpose of 'hackage4nix' is to keep all Haskell packages in our"
209− , "repository packages up-to-date. It scans a checked-out copy of"
210− , "Nixpkgs for expressions that use 'cabal.mkDerivation', and"
211− , "re-generates them in-place with cabal2nix."
212− ]
213−
214− cmdlineError :: String -> IO a
215− cmdlineError "" = hPutStrLn stderr usage >> exitFailure
216− cmdlineError errMsg = hPutStrLn stderr errMsg >> cmdlineError ""
217−
218− args' <- getArgs
219− (opts,args) <- case getOpt Permute options args' of
220− (o,n,[] ) -> return (o,n)
221− (_,_,errs) -> cmdlineError (concatMap (\e -> '*':'*':'*':' ':e) errs)
222−
223− when (PrintHelp `elem` opts) (cmdlineError "")
224−
225− hackage <- DB.readHashedHackage
226− let cfg = defaultConfiguration
227− { _msgDebug = if Verbose `elem` opts then _msgDebug defaultConfiguration else const (return ())
228− , _hackageDb = hackage
229− , _force = ForceRegen `elem` opts
230− }
231− ((),_,()) <- runRWST (updateNixPkgs args) cfg Set.empty
232− return ()
233−
234−
235−-- Packages that cabal2nix cannot generate build expressions for.
236−
237−badPackagePaths :: [FilePath]
238−badPackagePaths = [ -- These expression are not found on Hackage:
239− "haskell-platform/2009.2.0.2.nix", "haskell-platform/2010.1.0.0.nix"
240− , "haskell-platform/2010.2.0.0.nix", "haskell-platform/2011.2.0.0.nix"
241− , "haskell-platform/2011.2.0.1.nix", "haskell-platform/2011.4.0.0.nix"
242− , "haskell-platform/2012.2.0.0.nix", "haskell-platform/2012.4.0.0.nix"
243− , "haskell-platform/2013.2.0.0.nix", "compilers/flapjax/default.nix"
244− , "pkgs/games/uqm/3dovideo.nix", "haskell/ghcjs-prim/default.nix"
245− , "system/journal-mailer/default.nix", "development/compilers/ghcjs/default.nix"
246− -- Our primitive parser cannot handle these files.
247− , "top-level/all-packages.nix", "top-level/haskell-packages.nix"
248− -- This build is way too complicated to maintain it automatically.
249− , "pkgs/development/compilers/pakcs/default.nix"
250− , "pkgs/development/libraries/haskell/hoogle/local.nix"
251− -- Not registered on Hackage.
252− , "pkgs/development/compilers/agda/stdlib.nix"
253− , "pkgs/development/compilers/cryptol/1.8.x.nix"
254− , "pkgs/development/compilers/cryptol/2.0.x.nix"
255− , "pkgs/development/compilers/jhc/default.nix"
256− , "pkgs/development/tools/haskell/cabal-delete/default.nix"
257− , "pkgs/tools/networking/sproxy-web/default.nix"
258− , "pkgs/tools/networking/sproxy/default.nix"
259− , "pkgs/applications/editors/yi/yi-custom.nix"
260− ]
test/doc-test.hs−1
@@ -37,4 +37,3 @@ main = do
3737 ]
3838 doctest $ "src/cabal2nix.hs" : libs
3939 doctest $ "src/hackage2nix.hs" : libs
40− doctest $ "src/hackage4nix.hs" : libs