git.iko.soy/typeable/cabal2nix
on master help sign in
re-factoring: switch [String] to Set String in Derivation type
commit2ebe4dca18613f18647b82262b57032fbdf9c181 authorPeter Simons <simons@cryp.to> dateFri 23 Jan 2015, 20:52 (12 years ago) parent5ae868e
6 files changed+150−127
src/Cabal2Nix/Generate.hs+8−7 src/Cabal2Nix/Normalize.hs+16−11 src/Cabal2Nix/PostProcess.hs+82−71 src/Distribution/NixOS/Derivation/Cabal.hs+39−34 src/cabal2nix.hs+2−1 src/hackage2nix.hs+3−3
src/Cabal2Nix/Generate.hs+8−7
@@ -11,6 +11,7 @@ import qualified Distribution.Package as Cabal
1111import qualified Distribution.PackageDescription as Cabal
1212import Distribution.PackageDescription.Configuration
1313import Distribution.System
14+import qualified Data.Set as Set
1415
1516cabal2nix :: Cabal.FlagAssignment -> Cabal.GenericPackageDescription -> Derivation
1617cabal2nix flags' cabal = drv { cabalFlags = flags }
@@ -32,13 +33,13 @@ cabal2nix' tpkg = normalize $ postProcess $ normalize $ MkDerivation
3233 , src = error "cabal2nix left the src field undefined"
3334 , isLibrary = isJust (Cabal.library tpkg)
3435 , isExecutable = not (null (Cabal.executables tpkg))
35− , extraFunctionArgs = []
36− , buildDepends = map unDep deps
37− , testDepends = map unDep tstDeps ++ concatMap Cabal.extraLibs tests
38− , buildTools = map unDep tools
39− , extraLibs = libs
40− , pkgConfDeps = pcs
41− , configureFlags = []
36+ , extraFunctionArgs = Set.empty
37+ , buildDepends = Set.fromList $ map unDep deps
38+ , testDepends = Set.fromList $ map unDep tstDeps ++ concatMap Cabal.extraLibs tests
39+ , buildTools = Set.fromList $ map unDep tools
40+ , extraLibs = Set.fromList libs
41+ , pkgConfDeps = Set.fromList pcs
42+ , configureFlags = Set.empty
4243 , cabalFlags = configureCabalFlags pkg
4344 , runHaddock = True
4445 , jailbreak = False
src/Cabal2Nix/Normalize.hs+16−11
@@ -1,10 +1,12 @@
11{-# LANGUAGE RecordWildCards #-}
22
3−module Cabal2Nix.Normalize ( normalize, normalizeList, normalizeCabalFlags ) where
3+module Cabal2Nix.Normalize ( normalize, normalizeList, normalizeSet, normalizeCabalFlags ) where
44
55import Cabal2Nix.CorePackages
66import Cabal2Nix.Name
77import Data.Char
8+import Data.Set ( Set )
9+import qualified Data.Set as Set
810import Data.Function
911import Data.List
1012import Distribution.NixOS.Derivation.Cabal
@@ -14,12 +16,12 @@ import Distribution.Simple.Utils ( lowercase )
1416
1517normalize :: Derivation -> Derivation
1618normalize deriv@(MkDerivation {..}) = deriv
17− { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) buildDepends)
18− , testDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) testDepends)
19− , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) buildTools)
19+ { buildDepends = normalizeNixNames (Set.delete pname buildDepends)
20+ , testDepends = normalizeNixNames (Set.delete pname testDepends)
21+ , buildTools = normalizeNixBuildTools (Set.filter (`notElem` coreBuildTools) buildTools)
2022 , extraLibs = normalizeNixLibs extraLibs
2123 , pkgConfDeps = normalizeNixLibs pkgConfDeps
22− , configureFlags = normalizeList configureFlags
24+ , configureFlags = normalizeSet configureFlags
2325 , cabalFlags = normalizeCabalFlags cabalFlags
2426 , metaSection = normalizeMeta metaSection
2527 }
@@ -46,14 +48,17 @@ quote [] = []
4648normalizeList :: [String] -> [String]
4749normalizeList = nub . sortBy (compare `on` map toLower) . filter (not . null)
4850
49−normalizeNixNames :: [String] -> [String]
50−normalizeNixNames = normalizeList . map toNixName
51+normalizeSet :: Set String -> Set String
52+normalizeSet = Set.filter (not . null)
5153
52−normalizeNixLibs :: [String] -> [String]
53−normalizeNixLibs = normalizeList . concatMap libNixName
54+normalizeNixNames :: Set String -> Set String
55+normalizeNixNames = normalizeSet . Set.map toNixName
5456
55−normalizeNixBuildTools :: [String] -> [String]
56−normalizeNixBuildTools = normalizeList . concatMap buildToolNixName
57+normalizeNixLibs :: Set String -> Set String
58+normalizeNixLibs = normalizeSet . Set.fromList . concatMap libNixName . Set.toList
59+
60+normalizeNixBuildTools :: Set String -> Set String
61+normalizeNixBuildTools = normalizeSet . Set.fromList . concatMap buildToolNixName . Set.toList
5762
5863-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
5964-- sort the resulting list alphabetically.
src/Cabal2Nix/PostProcess.hs+82−71
@@ -2,7 +2,7 @@
22
33module Cabal2Nix.PostProcess ( postProcess ) where
44
5−import Data.List
5+import qualified Data.Set as Set
66import Distribution.NixOS.Derivation.Cabal
77import Distribution.Text ( display )
88
@@ -10,105 +10,116 @@ postProcess :: Derivation -> Derivation
1010postProcess = postProcess' . fixGtkBuilds
1111
1212fixGtkBuilds :: Derivation -> Derivation
13−fixGtkBuilds deriv@(MkDerivation {..}) = deriv { pkgConfDeps = pkgConfDeps \\ buildDepends }
13+fixGtkBuilds deriv@(MkDerivation {..}) = deriv { pkgConfDeps = pkgConfDeps `Set.difference` buildDepends }
1414
1515postProcess' :: Derivation -> Derivation
1616postProcess' deriv@(MkDerivation {..})
1717 | pname == "aeson" && version > Version [0,7] []
18− = deriv { buildDepends = "blaze-builder":buildDepends }
19− | pname == "Agda" = deriv { buildTools = "emacs":buildTools, phaseOverrides = agdaPostInstall }
18+ = deriv { buildDepends = Set.insert "blaze-builder" buildDepends }
19+ | pname == "Agda" = deriv { buildTools = Set.insert "emacs" buildTools, phaseOverrides = agdaPostInstall }
2020 | pname == "alex" && version < Version [3,1] []
21− = deriv { buildTools = "perl":buildTools }
21+ = deriv { buildTools = Set.insert "perl" buildTools }
2222 | pname == "alex" && version >= Version [3,1] []
23− = deriv { buildTools = "perl":"happy":buildTools }
24− | pname == "apache-md5" = deriv { testDepends = delete "crypto" testDepends }
25− | pname == "bindings-GLFW" = deriv { extraLibs = "libXext":"libXfixes":extraLibs }
26− | pname == "bits-extras" = deriv { configureFlags = "--ghc-option=-lgcc_s":configureFlags, extraLibs = filter (/= "gcc_s") extraLibs }
23+ = deriv { buildTools = Set.insert "perl" (Set.insert "happy" buildTools) }
24+ | pname == "apache-md5" = deriv { testDepends = Set.delete "crypto" testDepends }
25+ | pname == "bindings-GLFW" = deriv { extraLibs = Set.insert "libXext" (Set.insert "libXfixes" extraLibs) }
26+ | pname == "bits-extras" = deriv { configureFlags = Set.insert "--ghc-option=-lgcc_s" configureFlags
27+ , extraLibs = Set.filter (/= "gcc_s") extraLibs
28+ }
2729 | pname == "Cabal" = deriv { phaseOverrides = "preCheck = \"unset GHC_PACKAGE_PATH; export HOME=$NIX_BUILD_TOP\";" }
28− | pname == "cabal-bounds" = deriv { buildTools = "cabal-install":buildTools }
30+ | pname == "cabal-bounds" = deriv { buildTools = Set.insert "cabal-install" buildTools }
2931 | pname == "cabal-install" && version >= Version [0,14] []
3032 = deriv { phaseOverrides = cabalInstallPostInstall }
3133 | pname == "darcs" = deriv { phaseOverrides = darcsInstallPostInstall }
3234 | pname == "dns" = deriv { testTarget = "spec" }
33− | pname == "editline" = deriv { extraLibs = "libedit":extraLibs }
34− | pname == "epic" = deriv { extraLibs = "gmp":"boehmgc":extraLibs, buildTools = "happy":buildTools }
35+ | pname == "editline" = deriv { extraLibs = Set.insert "libedit" extraLibs }
36+ | pname == "epic" = deriv { extraLibs = Set.insert "gmp" (Set.insert "boehmgc" extraLibs)
37+ , buildTools = Set.insert "happy" buildTools
38+ }
3539 | pname == "ghc-heap-view" = deriv { phaseOverrides = ghciPostInstall }
36− | pname == "ghc-mod" = deriv { phaseOverrides = ghcModPostInstall pname version, buildTools = "emacs":"makeWrapper":buildTools }
37− | pname == "ghc-parser" = deriv { buildTools = "cpphs":"happy":buildTools, phaseOverrides = ghcParserPatchPhase }
40+ | pname == "ghc-mod" = deriv { phaseOverrides = ghcModPostInstall pname version
41+ , buildTools = Set.insert "emacs" (Set.insert "makeWrapper" buildTools) }
42+ | pname == "ghc-parser" = deriv { buildTools = Set.insert "cpphs" (Set.insert "happy" buildTools)
43+ , phaseOverrides = ghcParserPatchPhase }
3844 | pname == "ghc-paths" = deriv { phaseOverrides = ghcPathsPatches }
3945 | pname == "ghc-vis" = deriv { phaseOverrides = ghciPostInstall }
40− | pname == "git-annex" = deriv { phaseOverrides = gitAnnexOverrides, buildTools = "git":"rsync":"gnupg1":"curl":"wget":"lsof":"openssh":"which":"bup":"perl":buildTools }
41− | pname == "github-backup" = deriv { buildTools = "git":buildTools }
42− | pname == "gloss-raster" = deriv { extraLibs = "llvm":extraLibs }
43− | pname == "GLUT" = deriv { extraLibs = "glut":"libSM":"libICE":"libXmu":"libXi":"mesa":extraLibs }
44− | pname == "gtkglext" = deriv { pkgConfDeps = "pangox_compat":pkgConfDeps }
45− | pname == "gtk2hs-buildtools"= deriv { buildDepends = "hashtables":buildDepends }
46+ | pname == "git-annex" = deriv { phaseOverrides = gitAnnexOverrides
47+ , buildTools = Set.fromList ["git","rsync","gnupg1","curl","wget","lsof","openssh","which","bup","perl"] `Set.union` buildTools }
48+ | pname == "github-backup" = deriv { buildTools = Set.insert "git" buildTools }
49+ | pname == "gloss-raster" = deriv { extraLibs = Set.insert "llvm" extraLibs }
50+ | pname == "GLUT" = deriv { extraLibs = Set.fromList ["glut","libSM","libICE","libXmu","libXi","mesa"] `Set.union` extraLibs }
51+ | pname == "gtkglext" = deriv { pkgConfDeps = Set.insert "pangox_compat" pkgConfDeps }
52+ | pname == "gtk2hs-buildtools"= deriv { buildDepends = Set.insert "hashtables" buildDepends }
4653 | pname == "haddock" && version < Version [2,14] []
47− = deriv { buildTools = "alex":"happy":buildTools }
54+ = deriv { buildTools = Set.insert "alex" (Set.insert "happy" buildTools) }
4855 | pname == "haddock" = deriv { phaseOverrides = haddockPreCheck }
49− | pname == "happy" = deriv { buildTools = "perl":buildTools }
50− | pname == "haskeline" = deriv { buildDepends = "utf8-string":buildDepends }
51− | pname == "haskell-src" = deriv { buildTools = "happy":buildTools }
52− | pname == "haskell-src-meta" = deriv { buildDepends = "uniplate":buildDepends }
56+ | pname == "happy" = deriv { buildTools = Set.insert "perl" buildTools }
57+ | pname == "haskeline" = deriv { buildDepends = Set.insert "utf8-string" buildDepends }
58+ | pname == "haskell-src" = deriv { buildTools = Set.insert "happy" buildTools }
59+ | pname == "haskell-src-meta" = deriv { buildDepends = Set.insert "uniplate" buildDepends }
5360 | pname == "HFuse" = deriv { phaseOverrides = hfusePreConfigure }
5461 | pname == "highlighting-kate"= highlightingKatePostProcessing deriv
55− | pname == "hlibgit2" = deriv { buildTools = "git":buildTools }
56− | pname == "HList" = deriv { buildTools = "diffutils":buildTools }
57− | pname == "hmatrix" = deriv { extraLibs = "liblapack":"blas": filter (/= "lapack") extraLibs }
58− | pname == "hmatrix-special" = deriv { extraLibs = "gsl":extraLibs }
62+ | pname == "hlibgit2" = deriv { buildTools = Set.insert "git" buildTools }
63+ | pname == "HList" = deriv { buildTools = Set.insert "diffutils" buildTools }
64+ | pname == "hmatrix" = deriv { extraLibs = Set.insert "liblapack" (Set.insert "blas" (Set.filter (/= "lapack") extraLibs)) }
65+ | pname == "hmatrix-special" = deriv { extraLibs = Set.insert "gsl" extraLibs }
5966 | pname == "hoogle" = deriv { testTarget = "--test-option=--no-net" }
6067 | pname == "hspec" = deriv { doCheck = False }
61− | pname == "GlomeVec" = deriv { buildTools = "llvm":buildTools }
62− | pname == "idris" = deriv { buildTools = "happy":buildTools, extraLibs = "gmp":"boehmgc":extraLibs }
63− | pname == "language-c-quote" = deriv { buildTools = "alex":"happy":buildTools }
64− | pname == "language-java" = deriv { buildDepends = "syb":buildDepends }
65− | pname == "leksah-server" = deriv { buildDepends = "process-leksah":buildDepends }
66− | pname == "lhs2tex" = deriv { extraLibs = "texLive":extraLibs, phaseOverrides = lhs2texPostInstall }
67− | pname == "libffi" = deriv { extraLibs = delete "ffi" extraLibs }
68− | pname == "liquid-fixpoint" = deriv { buildTools = "ocaml":buildTools }
69− | pname == "llvm-base" = deriv { extraLibs = "llvm":extraLibs }
68+ | pname == "GlomeVec" = deriv { buildTools = Set.insert "llvm" buildTools }
69+ | pname == "idris" = deriv { buildTools = Set.insert "happy" buildTools, extraLibs = Set.insert "gmp" (Set.insert "boehmgc" extraLibs) }
70+ | pname == "language-c-quote" = deriv { buildTools = Set.insert "alex" (Set.insert "happy" buildTools) }
71+ | pname == "language-java" = deriv { buildDepends = Set.insert "syb" buildDepends }
72+ | pname == "leksah-server" = deriv { buildDepends = Set.insert "process-leksah" buildDepends }
73+ | pname == "lhs2tex" = deriv { extraLibs = Set.insert "texLive" extraLibs, phaseOverrides = lhs2texPostInstall }
74+ | pname == "libffi" = deriv { extraLibs = Set.delete "ffi" extraLibs }
75+ | pname == "liquid-fixpoint" = deriv { buildTools = Set.insert "ocaml" buildTools }
76+ | pname == "llvm-base" = deriv { extraLibs = Set.insert "llvm" extraLibs }
7077 | pname == "llvm-general" = deriv { doCheck = False }
7178 | pname == "llvm-general-pure"= deriv { doCheck = False }
72− | pname == "MFlow" = deriv { buildTools = "cpphs":buildTools }
73− | pname == "multiarg" = deriv { buildDepends = "utf8-string":buildDepends }
74− | pname == "mysql" = deriv { buildTools = "mysqlConfig":buildTools, extraLibs = "zlib":extraLibs }
79+ | pname == "MFlow" = deriv { buildTools = Set.insert "cpphs" buildTools }
80+ | pname == "multiarg" = deriv { buildDepends = Set.insert "utf8-string" buildDepends }
81+ | pname == "mysql" = deriv { buildTools = Set.insert "mysqlConfig" buildTools, extraLibs = Set.insert "zlib" extraLibs }
7582 | pname == "ncurses" = deriv { phaseOverrides = ncursesPatchPhase }
76− | pname == "Omega" = deriv { testDepends = delete "stdc++" testDepends }
77− | pname == "OpenAL" = deriv { extraLibs = "openal":extraLibs }
78− | pname == "OpenGL" = deriv { extraLibs = "mesa":"libX11":extraLibs }
79− | pname == "pandoc" = deriv { buildDepends = "alex":"happy":buildDepends }
80− | pname == "pcap" = deriv { extraLibs = "libpcap":extraLibs }
81− | pname == "persistent" = deriv { extraLibs = "sqlite3":extraLibs }
82− | pname == "purescript" = deriv { buildTools = "nodejs":buildTools }
83− | pname == "repa-algorithms" = deriv { extraLibs = "llvm":extraLibs }
84− | pname == "repa-examples" = deriv { extraLibs = "llvm":extraLibs }
85− | pname == "saltine" = deriv { extraLibs = map (\x -> if x == "sodium" then "libsodium" else x) extraLibs }
86− | pname == "SDL-image" = deriv { extraLibs = "SDL_image":extraLibs }
87− | pname == "SDL-mixer" = deriv { extraLibs = "SDL_mixer":extraLibs }
88− | pname == "SDL-ttf" = deriv { extraLibs = "SDL_ttf":extraLibs }
83+ | pname == "Omega" = deriv { testDepends = Set.delete "stdc++" testDepends }
84+ | pname == "OpenAL" = deriv { extraLibs = Set.insert "openal" extraLibs }
85+ | pname == "OpenGL" = deriv { extraLibs = Set.insert "mesa" (Set.insert "libX11" extraLibs) }
86+ | pname == "pandoc" = deriv { buildDepends = Set.insert "alex" (Set.insert "happy" buildDepends) }
87+ | pname == "pcap" = deriv { extraLibs = Set.insert "libpcap" extraLibs }
88+ | pname == "persistent" = deriv { extraLibs = Set.insert "sqlite3" extraLibs }
89+ | pname == "purescript" = deriv { buildTools = Set.insert "nodejs" buildTools }
90+ | pname == "repa-algorithms" = deriv { extraLibs = Set.insert "llvm" extraLibs }
91+ | pname == "repa-examples" = deriv { extraLibs = Set.insert "llvm" extraLibs }
92+ | pname == "saltine" = deriv { extraLibs = Set.map (\x -> if x == "sodium" then "libsodium" else x) extraLibs }
93+ | pname == "SDL-image" = deriv { extraLibs = Set.insert "SDL_image" extraLibs }
94+ | pname == "SDL-mixer" = deriv { extraLibs = Set.insert "SDL_mixer" extraLibs }
95+ | pname == "SDL-ttf" = deriv { extraLibs = Set.insert "SDL_ttf" extraLibs }
8996 | pname == "sloane" = deriv { phaseOverrides = sloanePostInstall }
90− | pname == "structured-haskell-mode" = deriv { buildTools = "emacs":buildTools, phaseOverrides = structuredHaskellModePostInstall }
91− | pname == "terminfo" = deriv { extraLibs = "ncurses":extraLibs }
92− | pname == "threadscope" = deriv { configureFlags = "--ghc-options=-rtsopts":configureFlags }
93− | pname == "thyme" = deriv { buildTools = "cpphs":buildTools }
94− | pname == "vacuum" = deriv { extraLibs = "ghc-paths":extraLibs }
95− | pname == "wxc" = deriv { extraLibs = "wxGTK":"mesa":"libX11":extraLibs, phaseOverrides = wxcPostInstall version }
96− | pname == "wxcore" = deriv { extraLibs = "wxGTK":"mesa":"libX11":extraLibs }
97+ | pname == "structured-haskell-mode" = deriv { buildTools = Set.insert "emacs" buildTools
98+ , phaseOverrides = structuredHaskellModePostInstall
99+ }
100+ | pname == "terminfo" = deriv { extraLibs = Set.insert "ncurses" extraLibs }
101+ | pname == "threadscope" = deriv { configureFlags = Set.insert "--ghc-options=-rtsopts" configureFlags }
102+ | pname == "thyme" = deriv { buildTools = Set.insert "cpphs" buildTools }
103+ | pname == "vacuum" = deriv { extraLibs = Set.insert "ghc-paths" extraLibs }
104+ | pname == "wxc" = deriv { extraLibs = Set.fromList ["wxGTK","mesa","libX11"] `Set.union` extraLibs
105+ , phaseOverrides = wxcPostInstall version
106+ }
107+ | pname == "wxcore" = deriv { extraLibs = Set.fromList ["wxGTK","mesa","libX11"] `Set.union` extraLibs }
97108 | pname == "X11" && version >= Version [1,6] []
98− = deriv { extraLibs = "libXinerama":"libXext":"libXrender":extraLibs }
99− | pname == "X11" = deriv { extraLibs = "libXinerama":"libXext":extraLibs }
100− | pname == "X11-xft" = deriv { extraLibs = "pkgconfig":"freetype":"fontconfig":extraLibs
101− , configureFlags = "--extra-include-dirs=${freetype}/include/freetype2":configureFlags
109+ = deriv { extraLibs = Set.fromList ["libXinerama","libXext","libXrender"] `Set.union` extraLibs }
110+ | pname == "X11" = deriv { extraLibs = Set.insert "libXinerama" (Set.insert "libXext" extraLibs) }
111+ | pname == "X11-xft" = deriv { extraLibs = Set.fromList ["pkgconfig","freetype","fontconfig"] `Set.union` extraLibs
112+ , configureFlags = Set.insert "--extra-include-dirs=${freetype}/include/freetype2" configureFlags
102113 }
103114 | pname == "xmonad" = deriv { phaseOverrides = xmonadPostInstall }
104115
105116-- Unbreak packages during hackage2nix generation:
106117
107− | pname == "hnetcdf" = deriv { testDepends = delete "netcdf" testDepends }
108− | pname == "SDL2-ttf" = deriv { buildDepends = delete "SDL2" buildDepends }
109− | pname == "jsaddle" = deriv { buildDepends = delete "ghcjs-base" buildDepends, testDepends = delete "ghcjs-base" testDepends }
110− | pname == "hzk" = deriv { testDepends = delete "zookeeper_mt" testDepends, buildTools = "zookeeper_mt":buildTools }
111− | pname == "zip-archive" = deriv { testDepends = delete "zip" testDepends, buildTools = "zip":buildTools }
118+ | pname == "hnetcdf" = deriv { testDepends = Set.delete "netcdf" testDepends }
119+ | pname == "SDL2-ttf" = deriv { buildDepends = Set.delete "SDL2" buildDepends }
120+ | pname == "jsaddle" = deriv { buildDepends = Set.delete "ghcjs-base" buildDepends, testDepends = Set.delete "ghcjs-base" testDepends }
121+ | pname == "hzk" = deriv { testDepends = Set.delete "zookeeper_mt" testDepends, buildTools = Set.insert "zookeeper_mt" buildTools }
122+ | pname == "zip-archive" = deriv { testDepends = Set.delete "zip" testDepends, buildTools = Set.insert "zip" buildTools }
112123 | otherwise = deriv
113124
114125ghcModPostInstall :: String -> Version -> String
@@ -150,7 +161,7 @@ darcsInstallPostInstall = unlines
150161highlightingKatePostProcessing :: Derivation -> Derivation
151162highlightingKatePostProcessing deriv@(MkDerivation {..}) = deriv
152163 { phaseOverrides = "prePatch = \"sed -i -e 's|regex-pcre-builtin >= .*|regex-pcre|' highlighting-kate.cabal\";"
153− , buildDepends = "regex-pcre" : filter (/="regex-pcre-builtin") buildDepends
164+ , buildDepends = Set.insert "regex-pcre" (Set.delete "regex-pcre-builtin" buildDepends)
154165 }
155166
156167xmonadPostInstall :: String
src/Distribution/NixOS/Derivation/Cabal.hs+39−34
@@ -23,6 +23,8 @@ module Distribution.NixOS.Derivation.Cabal
2323
2424import Control.DeepSeq.Generics
2525import Data.Char
26+import Data.Set ( Set )
27+import qualified Data.Set as Set
2628import Data.Function
2729import Data.List
2830import Data.Version
@@ -33,6 +35,9 @@ import Distribution.Package
3335import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
3436import GHC.Generics ( Generic )
3537
38+toAscList :: Set String -> [String]
39+toAscList = sortBy (compare `on` map toLower) . Set.toList
40+
3641-- | A represtation of Nix expressions for building Haskell packages.
3742-- The data type correspond closely to the definition of
3843-- 'PackageDescription' from Cabal.
@@ -46,13 +51,13 @@ data Derivation = MkDerivation
4651 , src :: DerivationSource
4752 , isLibrary :: Bool
4853 , isExecutable :: Bool
49− , extraFunctionArgs :: [String]
50− , buildDepends :: [String]
51− , testDepends :: [String]
52− , buildTools :: [String]
53− , extraLibs :: [String]
54− , pkgConfDeps :: [String]
55− , configureFlags :: [String]
54+ , extraFunctionArgs :: Set String
55+ , buildDepends :: Set String
56+ , testDepends :: Set String
57+ , buildTools :: Set String
58+ , extraLibs :: Set String
59+ , pkgConfDeps :: Set String
60+ , configureFlags :: Set String
5661 , cabalFlags :: FlagAssignment
5762 , runHaddock :: Bool
5863 , jailbreak :: Bool
@@ -78,40 +83,40 @@ deriving instance Generic FlagName
7883instance NFData FlagName where rnf = genericRnf
7984
8085renderDerivation :: Derivation -> Doc
81−renderDerivation deriv =
82− funargs (map text ("mkDerivation":inputs)) $$ vcat
86+renderDerivation (MkDerivation {..}) =
87+ funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
8388 [ text "mkDerivation" <+> lbrace
8489 , nest 2 $ vcat
85− [ attr "pname" $ string (pname deriv)
86− , attr "version" $ doubleQuotes (disp (version deriv))
87− , sourceAttr (src deriv)
88− , onlyIf (not (null (editedCabalFile deriv))) $ attr "editedCabalFile" $ string (editedCabalFile deriv)
89− , boolattr "isLibrary" (not (isLibrary deriv) || isExecutable deriv) (isLibrary deriv)
90− , boolattr "isExecutable" (not (isLibrary deriv) || isExecutable deriv) (isExecutable deriv)
91− , listattr "buildDepends" empty (buildDepends deriv)
92− , listattr "testDepends" empty (testDepends deriv)
93− , listattr "buildTools" empty (buildTools deriv)
94− , listattr "extraLibraries" empty (extraLibs deriv)
95− , listattr "pkgconfigDepends" empty (pkgConfDeps deriv)
90+ [ attr "pname" $ string pname
91+ , attr "version" $ doubleQuotes (disp version)
92+ , sourceAttr src
93+ , onlyIf (not (null editedCabalFile)) $ attr "editedCabalFile" $ string editedCabalFile
94+ , boolattr "isLibrary" ((not isLibrary) || isExecutable) isLibrary
95+ , boolattr "isExecutable" ((not isLibrary) || isExecutable) isExecutable
96+ , listattr "buildDepends" empty (toAscList buildDepends)
97+ , listattr "testDepends" empty (toAscList testDepends)
98+ , listattr "buildTools" empty (toAscList buildTools)
99+ , listattr "extraLibraries" empty (toAscList extraLibs)
100+ , listattr "pkgconfigDepends" empty (toAscList pkgConfDeps)
96101 , listattr "configureFlags" empty (map (show . show) renderedFlags)
97− , boolattr "enableSplitObjs" (not (enableSplitObjs deriv)) (enableSplitObjs deriv)
98− , boolattr "doHaddock" (not (runHaddock deriv)) (runHaddock deriv)
99− , boolattr "jailbreak" (jailbreak deriv) (jailbreak deriv)
100− , boolattr "doCheck" (not (doCheck deriv)) (doCheck deriv)
101− , onlyIf (not (null (testTarget deriv))) $ attr "testTarget" $ string (testTarget deriv)
102− , boolattr "hyperlinkSource" (not (hyperlinkSource deriv)) (hyperlinkSource deriv)
103− , onlyIf (not (null (phaseOverrides deriv))) $ vcat ((map text . lines) (phaseOverrides deriv))
104− , pPrint (metaSection deriv)
102+ , boolattr "enableSplitObjs" (not enableSplitObjs) enableSplitObjs
103+ , boolattr "doHaddock" (not runHaddock) runHaddock
104+ , boolattr "jailbreak" jailbreak jailbreak
105+ , boolattr "doCheck" (not doCheck) doCheck
106+ , onlyIf (not (null testTarget)) $ attr "testTarget" $ string testTarget
107+ , boolattr "hyperlinkSource" (not hyperlinkSource) hyperlinkSource
108+ , onlyIf (not (null phaseOverrides)) $ vcat ((map text . lines) phaseOverrides)
109+ , pPrint metaSection
105110 ]
106111 , rbrace
107112 ]
108113 where
109− inputs = nub $ sortBy (compare `on` map toLower) $
110− buildDepends deriv ++ testDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
111− ++ ["fetch" ++ derivKind (src deriv) | derivKind (src deriv) /= "" && not isHackagePackage]
112− renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags deriv ]
113− ++ map text (configureFlags deriv)
114− isHackagePackage = "mirror://hackage/" `isPrefixOf` derivUrl (src deriv)
114+ inputs = Set.unions [ buildDepends, testDepends, buildTools, extraLibs, pkgConfDeps
115+ , Set.fromList ["fetch" ++ derivKind src | derivKind src /= "" && not isHackagePackage]
116+ ]
117+ renderedFlags = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- cabalFlags ]
118+ ++ map text (toAscList configureFlags)
119+ isHackagePackage = "mirror://hackage/" `isPrefixOf` derivUrl src
115120 sourceAttr (DerivationSource{..})
116121 | isHackagePackage = attr "sha256" $ string derivHash
117122 | derivKind /= "" = vcat
src/cabal2nix.hs+2−1
@@ -15,6 +15,7 @@ import System.Environment ( getArgs )
1515import System.Exit ( exitFailure, exitSuccess )
1616import System.IO ( hPutStrLn, hFlush, stdout, stderr )
1717import Distribution.Simple.Utils ( lowercase )
18+import qualified Data.Set as Set
1819
1920data Configuration = Configuration
2021 { optPrintHelp :: Bool
@@ -113,7 +114,7 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
113114 , platforms = optPlatform cfg
114115 }
115116 , doCheck = doCheck deriv && optDoCheck cfg
116− , extraFunctionArgs = "stdenv" : extraFunctionArgs deriv
117+ , extraFunctionArgs = Set.insert "stdenv" (extraFunctionArgs deriv)
117118 }
118119
119120 deriv'' :: Doc
src/hackage2nix.hs+3−3
@@ -146,13 +146,13 @@ generatePackageSet config hackage nixpkgs = do
146146 }
147147
148148 missing :: Set String
149− missing = Set.fromList $ filter (`Set.notMember` knownAttributesSet) (buildDepends drv ++ testDepends drv)
149+ missing = Set.filter (`Set.notMember` knownAttributesSet) (buildDepends drv `Set.union` testDepends drv)
150150
151151 buildInputs :: Map Attribute (Maybe Path)
152152 buildInputs = Map.unions
153153 [ Map.fromList [ (n, Nothing) | n <- Set.toList missing ]
154− , Map.fromList [ (n, resolveNixpkgsAttribute nixpkgs n) | n <- Set.toAscList (Set.fromList (extraLibs drv ++ pkgConfDeps drv)) ]
155− , Map.fromList [ (n, resolveNixpkgsOrHackageAttribute nixpkgs hackage n) | n <- Set.toAscList (Set.fromList (buildTools drv)) ]
154+ , Map.fromList [ (n, resolveNixpkgsAttribute nixpkgs n) | n <- Set.toAscList (extraLibs drv `Set.union` pkgConfDeps drv) ]
155+ , Map.fromList [ (n, resolveNixpkgsOrHackageAttribute nixpkgs hackage n) | n <- Set.toAscList (buildTools drv) ]
156156 ]
157157
158158 systemOverrides :: Doc