git.iko.soy/typeable/cabal2nix
on master help sign in
Various style improvements.
d75a8d6Peter Simons
src/Cabal2Nix.hs+1−1
@@ -86,4 +86,4 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
86 }
86 }
87 }
87 }
88
88
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
14import Distribution.NixOS.Derivation.Cabal
14import Distribution.NixOS.Derivation.Cabal
15
15
16cabal2nix :: Cabal.GenericPackageDescription -> Derivation
16cabal2nix :: Cabal.GenericPackageDescription -> Derivation
17−cabal2nix cabal = normalize $ postProcess $ MkDerivation
17+cabal2nix cabal = normalize $ postProcess MkDerivation
18 { pname = let Cabal.PackageName x = Cabal.pkgName pkg in x
18 { pname = let Cabal.PackageName x = Cabal.pkgName pkg in x
19 , version = Cabal.pkgVersion pkg
19 , version = Cabal.pkgVersion pkg
20 , sha256 = "cabal2nix left the she256 field undefined"
20 , sha256 = "cabal2nix left the she256 field undefined"
src/Cabal2Nix/Hackage.hs+6−6
@@ -1,6 +1,6 @@
1module Cabal2Nix.Hackage ( hashPackage, readCabalFile ) where
1module Cabal2Nix.Hackage ( hashPackage, readCabalFile ) where
2
2
3−import Control.Monad ( when )
3+import Control.Monad ( unless )
4import Data.List ( isPrefixOf )
4import Data.List ( isPrefixOf )
5import Data.Version ( showVersion )
5import Data.Version ( showVersion )
6import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
6import Distribution.Package ( PackageIdentifier(..), PackageName(..) )
@@ -21,7 +21,7 @@ hackagePath :: PackageIdentifier -> Ext -> String
21hackagePath (PackageIdentifier (PackageName name) version') ext =
21hackagePath (PackageIdentifier (PackageName name) version') ext =
22 "http://hackage.haskell.org/packages/archive/" ++
22 "http://hackage.haskell.org/packages/archive/" ++
23 name ++ "/" ++ version ++ "/" ++ name ++
23 name ++ "/" ++ version ++ "/" ++ name ++
24− (if ext == TarGz then "-" ++ version else "") ++
24+ (if ext == TarGz then '-' : version else "") ++
25 showExt ext
25 showExt ext
26 where
26 where
27 version = showVersion version'
27 version = showVersion version'
@@ -30,11 +30,11 @@ hashPackage :: PackageIdentifier -> IO String
30hashPackage pkg = do
30hashPackage pkg = do
31 cachePath <- hashCachePath pkg
31 cachePath <- hashCachePath pkg
32 exists <- doesFileExist cachePath
32 exists <- doesFileExist cachePath
33− hash' <- case exists of
33+ hash' <- if exists
34− True -> readFile cachePath
34+ then readFile cachePath
35− False -> readProcess "bash" ["-c", "exec nix-prefetch-url 2>/dev/tty " ++ hackagePath pkg TarGz] ""
35+ else readProcess "bash" ["-c", "exec nix-prefetch-url 2>/dev/tty " ++ hackagePath pkg TarGz] ""
36 let hash = reverse (dropWhile (=='\n') (reverse hash'))
36 let hash = reverse (dropWhile (=='\n') (reverse hash'))
37− when (not exists) $ do
37+ unless exists $ do
38 createDirectoryIfMissing True (dropFileName cachePath)
38 createDirectoryIfMissing True (dropFileName cachePath)
39 writeFile cachePath hash
39 writeFile cachePath hash
40 return hash
40 return hash
src/Cabal2Nix/Normalize.hs+5−4
@@ -7,11 +7,12 @@ import Cabal2Nix.Name
7import Cabal2Nix.CorePackages
7import Cabal2Nix.CorePackages
8import Data.List
8import Data.List
9import Data.Char
9import Data.Char
10+import Data.Function
10
11
11normalize :: Derivation -> Derivation
12normalize :: Derivation -> Derivation
12normalize deriv@(MkDerivation {..}) = deriv
13normalize deriv@(MkDerivation {..}) = deriv
13− { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) $ buildDepends)
14+ { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) buildDepends)
14− , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) $ buildTools)
15+ , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) buildTools)
15 , extraLibs = normalizeNixLibs extraLibs
16 , extraLibs = normalizeNixLibs extraLibs
16 , pkgConfDeps = normalizeNixLibs pkgConfDeps
17 , pkgConfDeps = normalizeNixLibs pkgConfDeps
17 , metaSection = normalizeMeta metaSection
18 , metaSection = normalizeMeta metaSection
@@ -27,7 +28,7 @@ normalizeMeta meta@(Meta {..}) = meta
27normalizeDescription :: String -> String
28normalizeDescription :: String -> String
28normalizeDescription desc
29normalizeDescription desc
29 | null desc = []
30 | null desc = []
30− | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (reverse (tail (reverse desc)))
31+ | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (init desc)
31 | otherwise = quote (unwords (words desc))
32 | otherwise = quote (unwords (words desc))
32
33
33quote :: String -> String
34quote :: String -> String
@@ -37,7 +38,7 @@ quote (c:cs) = c : quote cs
37quote [] = []
38quote [] = []
38
39
39normalizeList :: [String] -> [String]
40normalizeList :: [String] -> [String]
40−normalizeList = nub . sortBy (\x y -> compare (map toLower x) (map toLower y))
41+normalizeList = nub . sortBy (compare `on` map toLower)
41
42
42normalizeNixNames :: [String] -> [String]
43normalizeNixNames :: [String] -> [String]
43normalizeNixNames = normalizeList . map toNixName
44normalizeNixNames = normalizeList . map toNixName
src/Cabal2Nix/PostProcess.hs+1−1
@@ -11,7 +11,7 @@ postProcess deriv@(MkDerivation {..})
11 | pname == "cairo" = deriv { extraLibs = "pkgconfig":"libc":"cairo":"zlib":extraLibs }
11 | pname == "cairo" = deriv { extraLibs = "pkgconfig":"libc":"cairo":"zlib":extraLibs }
12 | pname == "editline" = deriv { extraLibs = "libedit":extraLibs }
12 | pname == "editline" = deriv { extraLibs = "libedit":extraLibs }
13 | pname == "epic" = deriv { extraLibs = "gmp":"boehmgc":extraLibs, buildTools = "happy":buildTools }
13 | 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 }
15 | pname == "glib" = deriv { extraLibs = "pkgconfig":"libc":extraLibs }
15 | pname == "glib" = deriv { extraLibs = "pkgconfig":"libc":extraLibs }
16 | pname == "GLUT" = deriv { extraLibs = "glut":"libSM":"libICE":"libXmu":"libXi":"mesa":extraLibs }
16 | pname == "GLUT" = deriv { extraLibs = "glut":"libSM":"libICE":"libXmu":"libXi":"mesa":extraLibs }
17 | pname == "gtk" = deriv { extraLibs = "pkgconfig":"libc":extraLibs, buildDepends = delete "gio" buildDepends }
17 | 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(..) )
30import Data.Version
30import Data.Version
31import Data.List
31import Data.List
32import Data.Char
32import Data.Char
33+import Data.Function
33import Text.Regex.Posix hiding ( empty )
34import Text.Regex.Posix hiding ( empty )
34
35
35-- | A represtation of Nix expressions for building Haskell packages.
36-- | A represtation of Nix expressions for building Haskell packages.
@@ -72,8 +73,8 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
72 [ attr "pname" $ string (pname deriv)
73 [ attr "pname" $ string (pname deriv)
73 , attr "version" $ doubleQuotes (disp (version deriv))
74 , attr "version" $ doubleQuotes (disp (version deriv))
74 , attr "sha256" $ string (sha256 deriv)
75 , attr "sha256" $ string (sha256 deriv)
75− , boolattr "isLibrary" (not (isLibrary deriv) || (isExecutable deriv)) (isLibrary deriv)
76+ , boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
76− , boolattr "isExecutable" (not (isLibrary deriv) || (isExecutable deriv)) (isExecutable deriv)
77+ , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
77 , listattr "buildDepends" (buildDepends deriv)
78 , listattr "buildDepends" (buildDepends deriv)
78 , listattr "buildTools" (buildTools deriv)
79 , listattr "buildTools" (buildTools deriv)
79 , listattr "extraLibraries" (extraLibs deriv)
80 , listattr "extraLibraries" (extraLibs deriv)
@@ -87,7 +88,7 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
87 , text ""
88 , text ""
88 ]
89 ]
89 where
90 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") $
91 buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
92 buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
92 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
93 renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
93 ++ map text (configureFlags deriv)
94 ++ map text (configureFlags deriv)
@@ -106,7 +107,7 @@ parseDerivation buf
106 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
107 , plats <- buf `regsubmatch` "platforms *= *([^;]+);"
107 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
108 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
108 , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
109 , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
109− = Just $ MkDerivation
110+ = Just MkDerivation
110 { pname = name
111 { pname = name
111 , version = vers
112 , version = vers
112 , sha256 = sha
113 , sha256 = sha
src/Distribution/NixOS/Derivation/Meta.hs+1−1
@@ -60,7 +60,7 @@ renderMeta meta = vcat
60 , attr "license" $ disp (license meta)
60 , attr "license" $ disp (license meta)
61 , onlyIf (platforms meta) $ sep
61 , onlyIf (platforms meta) $ sep
62 [ text "platforms" <+> equals
62 [ 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
64 ]
64 ]
65 , listattr "maintainers" (maintainers meta)
65 , listattr "maintainers" (maintainers meta)
66 ]
66 ]
src/Distribution/NixOS/PrettyPrinting.hs+1−2
@@ -51,7 +51,6 @@ prepunctuate p (d:ds) = d : map (p <>) ds
51
51
52funargs :: [Doc] -> Doc
52funargs :: [Doc] -> Doc
53funargs xs = sep [
53funargs xs = sep [
54− lbrace <+> (fcat $ prepunctuate (comma <> text " ") $
54+ lbrace <+> fcat (prepunctuate (comma <> text " ") $ map (nest 2) xs),
55− map (nest 2) xs),
56 rbrace <> colon
55 rbrace <> colon
57 ]
56 ]
src/Hackage4Nix.hs+10−10
@@ -71,7 +71,7 @@ discoverNixFiles yield dirOrFile = do
71 (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>))
71 (False,_) -> io (readDirectory dirOrFile) >>= mapM_ (discoverNixFiles yield . (dirOrFile </>))
72
72
73regenerateDerivation :: Derivation -> String -> Bool
73regenerateDerivation :: Derivation -> String -> Bool
74−regenerateDerivation deriv buf = not (pname deriv `elem` patchedPackages) &&
74+regenerateDerivation deriv buf = (pname deriv `notElem` patchedPackages) &&
75 not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches")
75 not (buf =~ "(pre|post)Configure|(pre|post)Install|patchPhase|patches")
76
76
77parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)
77parseNixFile :: FilePath -> String -> Hackage4Nix (Maybe Pkg)
@@ -103,7 +103,7 @@ discoverUpdates name vers = do
103updateNixPkgs :: [FilePath] -> Hackage4Nix ()
103updateNixPkgs :: [FilePath] -> Hackage4Nix ()
104updateNixPkgs paths = do
104updateNixPkgs paths = do
105 msgDebug $ "updating = " ++ show paths
105 msgDebug $ "updating = " ++ show paths
106− flip mapM_ paths $ \fileOrDir ->
106+ forM_ paths $ \fileOrDir ->
107 flip discoverNixFiles fileOrDir $ \file -> do
107 flip discoverNixFiles fileOrDir $ \file -> do
108 nix' <- io (readFile file) >>= parseNixFile file
108 nix' <- io (readFile file) >>= parseNixFile file
109 flip (maybe (return ())) nix' $ \nix -> do
109 flip (maybe (return ())) nix' $ \nix -> do
@@ -122,26 +122,26 @@ updateNixPkgs paths = do
122 , platforms = plats'
122 , platforms = plats'
123 }
123 }
124 }
124 }
125− io $ writeFile path (show (disp (normalize (deriv''))))
125+ io $ writeFile path (show (disp (normalize deriv'')))
126 pkgset <- gets selectLatestVersions
126 pkgset <- gets selectLatestVersions
127− updates' <- flip mapM (Set.elems pkgset) $ \pkg -> do
127+ updates' <- forM (Set.elems pkgset) $ \pkg -> do
128 let Pkg deriv _ _ = pkg
128 let Pkg deriv _ _ = pkg
129 updates <- discoverUpdates (pname deriv) (version deriv)
129 updates <- discoverUpdates (pname deriv) (version deriv)
130 return (pkg,updates)
130 return (pkg,updates)
131− let updates = [ u | u@(_,(_:_)) <- updates' ]
131+ let updates = [ u | u@(_,_:_) <- updates' ]
132− when (not (null updates)) $ do
132+ unless (null updates) $ do
133 msgInfo "The following updates are available:"
133 msgInfo "The following updates are available:"
134− flip mapM_ updates $ \(pkg,versions) -> do
134+ forM_ updates $ \(pkg,versions) -> do
135 let Pkg deriv path regenerate = pkg
135 let Pkg deriv path regenerate = pkg
136 msgInfo ""
136 msgInfo ""
137− msgInfo $ (display (packageId deriv)) ++ ":"
137+ msgInfo $ display (packageId deriv) ++ ":"
138− flip mapM_ versions $ \newVersion -> do
138+ forM_ versions $ \newVersion -> do
139 let deriv' = deriv { version = newVersion }
139 let deriv' = deriv { version = newVersion }
140 msgInfo $ " " ++ genCabal2NixCmdline (Pkg deriv' path regenerate)
140 msgInfo $ " " ++ genCabal2NixCmdline (Pkg deriv' path regenerate)
141 return ()
141 return ()
142
142
143genCabal2NixCmdline :: Pkg -> String
143genCabal2NixCmdline :: Pkg -> String
144−genCabal2NixCmdline (Pkg deriv path _) = unwords $ ["cabal2nix"] ++ opts ++ [">"++path']
144+genCabal2NixCmdline (Pkg deriv path _) = unwords $ ["cabal2nix"] ++ opts ++ ['>':path']
145 where
145 where
146 meta = metaSection deriv
146 meta = metaSection deriv
147 opts = [cabal] ++ maints' ++ plats' ++ if runHaddock deriv then [] else ["--no-haddock"]
147 opts = [cabal] ++ maints' ++ plats' ++ if runHaddock deriv then [] else ["--no-haddock"]