git.iko.soy/typeable/cabal2nix
on master help sign in
Various style improvements.
commitd75a8d69205246a81365ce2f9580cfd7a59554e7 authorPeter Simons <simons@cryp.to> dateSun 25 Mar 2012, 20:42 (15 years ago) parentd204f0a
9 files changed+31−30
src/Cabal2Nix.hs+1−1 src/Cabal2Nix/Generate.hs+1−1 src/Cabal2Nix/Hackage.hs+6−6 src/Cabal2Nix/Normalize.hs+5−4 src/Cabal2Nix/PostProcess.hs+1−1 src/Distribution/NixOS/Derivation/Cabal.hs+5−4 src/Distribution/NixOS/Derivation/Meta.hs+1−1 src/Distribution/NixOS/PrettyPrinting.hs+1−2 src/Hackage4Nix.hs+10−10
src/Cabal2Nix.hs+1−1
@@ -86,4 +86,4 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
8686 }
8787 }
8888
89− putStr (show (disp (normalize (deriv'))))
89+ putStr (show (disp (normalize deriv')))
src/Cabal2Nix/Generate.hs+1−1
@@ -14,7 +14,7 @@ import Distribution.Version
1414import Distribution.NixOS.Derivation.Cabal
1515
1616cabal2nix :: Cabal.GenericPackageDescription -> Derivation
17−cabal2nix cabal = normalize $ postProcess $ MkDerivation
17+cabal2nix cabal = normalize $ postProcess MkDerivation
1818 { pname = let Cabal.PackageName x = Cabal.pkgName pkg in x
1919 , version = Cabal.pkgVersion pkg
2020 , sha256 = "cabal2nix left the she256 field undefined"
src/Cabal2Nix/Hackage.hs+6−6
@@ -1,6 +1,6 @@
11module Cabal2Nix.Hackage ( hashPackage, readCabalFile ) where
22
3−import Control.Monad ( when )
3+import Control.Monad ( unless )
44import Data.List ( isPrefixOf )
55import Data.Version ( showVersion )
66import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
@@ -21,7 +21,7 @@ hackagePath :: PackageIdentifier -> Ext -> String
2121hackagePath (PackageIdentifier (PackageName name) version') ext =
2222 "http://hackage.haskell.org/packages/archive/" ++
2323 name ++ "/" ++ version ++ "/" ++ name ++
24− (if ext == TarGz then "-" ++ version else "") ++
24+ (if ext == TarGz then '-' : version else "") ++
2525 showExt ext
2626 where
2727 version = showVersion version'
@@ -30,11 +30,11 @@ hashPackage :: PackageIdentifier -> IO String
3030hashPackage pkg = do
3131 cachePath <- hashCachePath pkg
3232 exists <- doesFileExist cachePath
33− hash' <- case exists of
34− True -> readFile cachePath
35− False -> readProcess "bash" ["-c", "exec nix-prefetch-url 2>/dev/tty " ++ hackagePath pkg TarGz] ""
33+ hash' <- if exists
34+ then readFile cachePath
35+ else readProcess "bash" ["-c", "exec nix-prefetch-url 2>/dev/tty " ++ hackagePath pkg TarGz] ""
3636 let hash = reverse (dropWhile (=='\n') (reverse hash'))
37− when (not exists) $ do
37+ unless exists $ do
3838 createDirectoryIfMissing True (dropFileName cachePath)
3939 writeFile cachePath hash
4040 return hash
src/Cabal2Nix/Normalize.hs+5−4
@@ -7,11 +7,12 @@ import Cabal2Nix.Name
77import Cabal2Nix.CorePackages
88import Data.List
99import Data.Char
10+import Data.Function
1011
1112normalize :: Derivation -> Derivation
1213normalize deriv@(MkDerivation {..}) = deriv
13− { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) $ buildDepends)
14− , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) $ buildTools)
14+ { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) buildDepends)
15+ , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) buildTools)
1516 , extraLibs = normalizeNixLibs extraLibs
1617 , pkgConfDeps = normalizeNixLibs pkgConfDeps
1718 , metaSection = normalizeMeta metaSection
@@ -27,7 +28,7 @@ normalizeMeta meta@(Meta {..}) = meta
2728normalizeDescription :: String -> String
2829normalizeDescription desc
2930 | null desc = []
30− | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (reverse (tail (reverse desc)))
31+ | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (init desc)
3132 | otherwise = quote (unwords (words desc))
3233
3334quote :: String -> String
@@ -37,7 +38,7 @@ quote (c:cs) = c : quote cs
3738quote [] = []
3839
3940normalizeList :: [String] -> [String]
40−normalizeList = nub . sortBy (\x y -> compare (map toLower x) (map toLower y))
41+normalizeList = nub . sortBy (compare `on` map toLower)
4142
4243normalizeNixNames :: [String] -> [String]
4344normalizeNixNames = normalizeList . map toNixName
src/Cabal2Nix/PostProcess.hs+1−1
@@ -11,7 +11,7 @@ postProcess deriv@(MkDerivation {..})
1111 | pname == "cairo" = deriv { extraLibs = "pkgconfig":"libc":"cairo":"zlib":extraLibs }
1212 | pname == "editline" = deriv { extraLibs = "libedit":extraLibs }
1313 | pname == "epic" = deriv { extraLibs = "gmp":"boehmgc":extraLibs, buildTools = "happy":buildTools }
14− | pname == "glade" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, pkgConfDeps = "gtkC":(delete "gtk" pkgConfDeps) }
14+ | pname == "glade" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, pkgConfDeps = "gtkC":delete "gtk" pkgConfDeps }
1515 | pname == "glib" = deriv { extraLibs = "pkgconfig":"libc":extraLibs }
1616 | pname == "GLUT" = deriv { extraLibs = "glut":"libSM":"libICE":"libXmu":"libXi":"mesa":extraLibs }
1717 | pname == "gtk" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, buildDepends = delete "gio" buildDepends }
src/Distribution/NixOS/Derivation/Cabal.hs+5−4
@@ -30,6 +30,7 @@ import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
3030import Data.Version
3131import Data.List
3232import Data.Char
33+import Data.Function
3334import Text.Regex.Posix hiding ( empty )
3435
3536-- | A represtation of Nix expressions for building Haskell packages.
@@ -72,8 +73,8 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
7273 [ attr "pname" $ string (pname deriv)
7374 , attr "version" $ doubleQuotes (disp (version deriv))
7475 , attr "sha256" $ string (sha256 deriv)
75− , boolattr "isLibrary" (not (isLibrary deriv) || (isExecutable deriv)) (isLibrary deriv)
76− , boolattr "isExecutable" (not (isLibrary deriv) || (isExecutable deriv)) (isExecutable deriv)
76+ , boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
77+ , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
7778 , listattr "buildDepends" (buildDepends deriv)
7879 , listattr "buildTools" (buildTools deriv)
7980 , listattr "extraLibraries" (extraLibs deriv)
@@ -87,7 +88,7 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
8788 , text ""
8889 ]
8990 where
90− inputs = nub $ sortBy (\x y -> compare (map toLower x) (map toLower y)) $ filter (/="cabal") $
91+ inputs = nub $ sortBy (compare `on` map toLower) $ filter (/="cabal") $
9192 buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
9293 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
9394 ++ map text (configureFlags deriv)
@@ -106,7 +107,7 @@ parseDerivation buf
106107 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
107108 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
108109 , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
109− = Just $ MkDerivation
110+ = Just MkDerivation
110111 { pname = name
111112 , version = vers
112113 , sha256 = sha
src/Distribution/NixOS/Derivation/Meta.hs+1−1
@@ -60,7 +60,7 @@ renderMeta meta = vcat
6060 , attr "license" $ disp (license meta)
6161 , onlyIf (platforms meta) $ sep
6262 [ text "platforms" <+> equals
63− , nest 2 ((fsep $ punctuate (text " ++") $ map text (platforms meta))) <> semi
63+ , nest 2 (fsep $ punctuate (text " ++") $ map text (platforms meta)) <> semi
6464 ]
6565 , listattr "maintainers" (maintainers meta)
6666 ]
src/Distribution/NixOS/PrettyPrinting.hs+1−2
@@ -51,7 +51,6 @@ prepunctuate p (d:ds) = d : map (p <>) ds
5151
5252funargs :: [Doc] -> Doc
5353funargs xs = sep [
54− lbrace <+> (fcat $ prepunctuate (comma <> text " ") $
55− map (nest 2) xs),
54+ lbrace <+> fcat (prepunctuate (comma <> text " ") $ map (nest 2) xs),
5655 rbrace <> colon
5756 ]
src/Hackage4Nix.hs+10−10
@@ -71,7 +71,7 @@ discoverNixFiles yield dirOrFile = do
7171 (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>))
7272
7373regenerateDerivation :: Derivation -> String -> Bool
74−regenerateDerivation deriv buf = not (pname deriv `elem` patchedPackages) &&
74+regenerateDerivation deriv buf = (pname deriv `notElem` patchedPackages) &&
7575 not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches")
7676
7777parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)
@@ -103,7 +103,7 @@ discoverUpdates name vers = do
103103updateNixPkgs :: [FilePath] -> Hackage4Nix ()
104104updateNixPkgs paths = do
105105 msgDebug $ "updating = " ++ show paths
106− flip mapM_ paths $ \fileOrDir ->
106+ forM_ paths $ \fileOrDir ->
107107 flip discoverNixFiles fileOrDir $ \file -> do
108108 nix' <- io (readFile file) >>= parseNixFile file
109109 flip (maybe (return ())) nix' $ \nix -> do
@@ -122,26 +122,26 @@ updateNixPkgs paths = do
122122 , platforms = plats'
123123 }
124124 }
125− io $ writeFile path (show (disp (normalize (deriv''))))
125+ io $ writeFile path (show (disp (normalize deriv'')))
126126 pkgset <- gets selectLatestVersions
127− updates' <- flip mapM (Set.elems pkgset) $ \pkg -> do
127+ updates' <- forM (Set.elems pkgset) $ \pkg -> do
128128 let Pkg deriv _ _ = pkg
129129 updates <- discoverUpdates (pname deriv) (version deriv)
130130 return (pkg,updates)
131− let updates = [ u | u@(_,(_:_)) <- updates' ]
132− when (not (null updates)) $ do
131+ let updates = [ u | u@(_,_:_) <- updates' ]
132+ unless (null updates) $ do
133133 msgInfo "The following updates are available:"
134− flip mapM_ updates $ \(pkg,versions) -> do
134+ forM_ updates $ \(pkg,versions) -> do
135135 let Pkg deriv path regenerate = pkg
136136 msgInfo ""
137− msgInfo $ (display (packageId deriv)) ++ ":"
138− flip mapM_ versions $ \newVersion -> do
137+ msgInfo $ display (packageId deriv) ++ ":"
138+ forM_ versions $ \newVersion -> do
139139 let deriv' = deriv { version = newVersion }
140140 msgInfo $ " " ++ genCabal2NixCmdline (Pkg deriv' path regenerate)
141141 return ()
142142
143143genCabal2NixCmdline :: Pkg -> String
144−genCabal2NixCmdline (Pkg deriv path _) = unwords $ ["cabal2nix"] ++ opts ++ [">"++path']
144+genCabal2NixCmdline (Pkg deriv path _) = unwords $ ["cabal2nix"] ++ opts ++ ['>':path']
145145 where
146146 meta = metaSection deriv
147147 opts = [cabal] ++ maints' ++ plats' ++ if runHaddock deriv then [] else ["--no-haddock"]