git.iko.soy/typeable/cabal2nix
on master help sign in
BuildInfo: Switch "Set Dependency" to "Set Identifier"
commite2a125b4cc2a3b256101812ab9a1b20d5320a125 authorPeter Simons <simons@cryp.to> dateSat 8 Aug 2015, 20:35 (11 years ago) parent7632425
6 files changed+53−61
src/Cabal2Nix/Generate.hs+5−7 src/Cabal2Nix/Normalize.hs+7−7 src/Cabal2Nix/PostProcess.hs+18−16 src/Distribution/Nixpkgs/Haskell.hs+11−25 src/Language/Nix/Identifier.hs+8−3 src/hackage2nix.hs+4−3
src/Cabal2Nix/Generate.hs+5−7
@@ -7,8 +7,6 @@ import Cabal2Nix.Name
77import Cabal2Nix.Normalize
88import Cabal2Nix.PostProcess
99import Control.Lens
10−-- import Data.Set.Lens
11−-- import Control.Applicative
1210import Data.Maybe
1311import qualified Data.Set as Set
1412import Data.Version
@@ -16,10 +14,10 @@ import Distribution.Compiler
1614import Distribution.Nixpkgs.Haskell
1715import qualified Distribution.Nixpkgs.Haskell as Nix
1816import Cabal2Nix.License
17+import Language.Nix.Identifier
1918import Distribution.Nixpkgs.Fetch
2019import qualified Distribution.Nixpkgs.Meta as Nix
2120import Distribution.Package
22−import Distribution.Version
2321import Distribution.PackageDescription
2422import qualified Distribution.PackageDescription as Cabal
2523import Distribution.PackageDescription.Configuration
@@ -79,7 +77,7 @@ cabal2nix' PackageDescription {..} = normalize $ postProcess $
7977
8078convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
8179convertBuildInfo Cabal.BuildInfo {..} = mempty
82− & haskell .~ Set.fromList targetBuildDepends
83− & system .~ Set.fromList [ Dependency (PackageName y) anyVersion | x <- extraLibs, y <- libNixName x, not (null y) ]
84− & pkgconfig .~ Set.fromList [ Dependency (PackageName y) anyVersion | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x, not (null y) ]
85− & tool .~ Set.fromList [ Dependency (PackageName y) anyVersion | Dependency (PackageName x) _ <- buildTools, y <- buildToolNixName x, not (null y) ]
80+ & haskell .~ Set.fromList [ Identifier y | (Dependency (PackageName y) _) <- targetBuildDepends ]
81+ & system .~ Set.fromList [ Identifier y | x <- extraLibs, y <- libNixName x, not (null y) ]
82+ & pkgconfig .~ Set.fromList [ Identifier y | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x, not (null y) ]
83+ & tool .~ Set.fromList [ Identifier y | Dependency (PackageName x) _ <- buildTools, y <- buildToolNixName x, not (null y) ]
src/Cabal2Nix/Normalize.hs+7−7
@@ -7,13 +7,13 @@ import Data.Function
77import Data.List
88import Data.Set ( Set )
99import qualified Data.Set as Set
10+import Language.Nix.Identifier ( Identifier(..) )
1011import Distribution.Nixpkgs.Haskell
1112import Distribution.Nixpkgs.Meta
1213import Distribution.Nixpkgs.Util.Regex ( regsubmatch )
1314import Distribution.Package
1415import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
1516import Distribution.Simple.Utils ( lowercase )
16−import Distribution.Version
1717
1818normalize :: Derivation -> Derivation
1919normalize drv = drv
@@ -24,9 +24,9 @@ normalize drv = drv
2424 & over cabalFlags normalizeCabalFlags
2525
2626normalizeBuildInfo :: PackageName -> BuildInfo -> BuildInfo
27−normalizeBuildInfo pname bi = bi
28− & haskell . contains (Dependency pname anyVersion) .~ False
29− & tool %~ normalizeNixBuildTools . Set.filter (\(Dependency (PackageName n) _) -> n `notElem` coreBuildTools)
27+normalizeBuildInfo (PackageName pname) bi = bi
28+ & haskell . contains (Identifier pname) .~ False
29+ & tool %~ normalizeNixBuildTools . Set.filter (\(Identifier n) -> n `notElem` coreBuildTools)
3030
3131 {-
3232 {
@@ -63,11 +63,11 @@ normalizeSet = Set.filter (not . null)
6363-- normalizeNixLibs :: Set String -> Set String
6464-- normalizeNixLibs = normalizeSet . Set.fromList . concatMap libNixName . Set.toList
6565
66−normalizeNixBuildTools :: Set Dependency -> Set Dependency
66+normalizeNixBuildTools :: Set Identifier -> Set Identifier
6767normalizeNixBuildTools = Set.fromList . concatMap buildToolNixName' . Set.toList
6868 where
69− buildToolNixName' :: Dependency -> [Dependency]
70− buildToolNixName' (Dependency (PackageName n) vr) = [ Dependency (PackageName n') vr | n' <- buildToolNixName n ]
69+ buildToolNixName' :: Identifier -> [Identifier]
70+ buildToolNixName' (Identifier n) = [ Identifier n' | n' <- buildToolNixName n ]
7171
7272-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
7373-- sort the resulting list alphabetically.
src/Cabal2Nix/PostProcess.hs+18−16
@@ -1,3 +1,5 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
13module Cabal2Nix.PostProcess ( postProcess ) where
24
35import Control.Lens
@@ -18,28 +20,28 @@ fixGtkBuilds drv = drv & dependencies . pkgconfig %~ (`Set.difference` buildDeps
1820
1921hooks :: [(Dependency, Derivation -> Derivation)]
2022hooks = over (mapped._1) (\str -> fromMaybe (error ("invalid constraint: " ++ show str)) (simpleParse str))
21− [ ("Agda", set (executableDepends . tool . contains (dep "emacs")) True . set phaseOverrides agdaPostInstall)
23+ [ ("Agda", set (executableDepends . tool . contains "emacs") True . set phaseOverrides agdaPostInstall)
2224 , ("dns", set testTarget "spec") -- don't execute tests that try to access the network
23− , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList [dep "libXext", dep "libXfixes"])))
25+ , ("bindings-GLFW", over (libraryDepends . system) (Set.union (Set.fromList ["libXext", "libXfixes"])))
2426 , ("cabal-install", set phaseOverrides cabalInstallPostInstall)
2527 , ("darcs", set phaseOverrides darcsInstallPostInstall)
2628 , ("git-annex", gitAnnexHook)
2729 , ("haddock", set phaseOverrides "preCheck = \"unset GHC_PACKAGE_PATH\";")
2830 , ("HFuse", set phaseOverrides hfusePreConfigure)
2931 , ("gf", set phaseOverrides gfPhaseOverrides . set doCheck False)
30− , ("github-backup", set (executableDepends . tool . contains (dep "git")) True)
31− , ("GlomeVec", set (libraryDepends . pkgconfig . contains (dep "llvm")) True)
32− , ("gtk3", set (libraryDepends . pkgconfig . contains (dep "gtk3")) True) -- https://github.com/NixOS/cabal2nix/issues/145
33− , ("imagemagick", set (libraryDepends . pkgconfig . contains (dep "imagemagick")) True) -- https://github.com/NixOS/cabal2nix/issues/136
34− , ("jsaddle", set (dependencies . haskell . contains (dep "ghcjs-base")) False)
35− , ("mysql", set (libraryDepends . system . contains (dep "mysql")) True)
36− , ("pango", set (libraryDepends . haskell . contains (dep "cairo")) True)
37− , ("readline", over (libraryDepends . system) (Set.union (Set.fromList [dep "readline", dep "ncurses"])))
38− , ("terminfo", set (libraryDepends . system . contains (dep "ncurses")) True)
39− , ("thyme", set (libraryDepends . tool . contains (dep "cpphs")) True) -- required on Darwin
32+ , ("github-backup", set (executableDepends . tool . contains "git") True)
33+ , ("GlomeVec", set (libraryDepends . pkgconfig . contains "llvm") True)
34+ , ("gtk3", set (libraryDepends . pkgconfig . contains "gtk3") True) -- https://github.com/NixOS/cabal2nix/issues/145
35+ , ("imagemagick", set (libraryDepends . pkgconfig . contains "imagemagick") True) -- https://github.com/NixOS/cabal2nix/issues/136
36+ , ("jsaddle", set (dependencies . haskell . contains "ghcjs-base") False)
37+ , ("mysql", set (libraryDepends . system . contains "mysql") True)
38+ , ("pango", set (libraryDepends . haskell . contains "cairo") True)
39+ , ("readline", over (libraryDepends . system) (Set.union (Set.fromList ["readline", "ncurses"])))
40+ , ("terminfo", set (libraryDepends . system . contains "ncurses") True)
41+ , ("thyme", set (libraryDepends . tool . contains "cpphs") True) -- required on Darwin
4042 , ("monad", set phaseOverrides xmonadPostInstall)
4143 , ("wxc", wxcHook)
42− , ("wxcore", set (libraryDepends . pkgconfig . contains (dep "wxGTK")) True)
44+ , ("wxcore", set (libraryDepends . pkgconfig . contains "wxGTK") True)
4345 ]
4446
4547gitAnnexHook :: Derivation -> Derivation
@@ -52,7 +54,7 @@ gitAnnexHook = set phaseOverrides gitAnnexOverrides . over (executableDepends .
5254 , " ./git-annex test"
5355 , "'';"
5456 ]
55− buildInputs = Set.map dep $ Set.fromList ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
57+ buildInputs = Set.fromList ["git","rsync","gnupg","curl","wget","lsof","openssh","which","bup","perl"]
5658
5759hfusePreConfigure :: String
5860hfusePreConfigure = unlines
@@ -76,8 +78,8 @@ gfPhaseOverrides = unlines
7678 ]
7779
7880wxcHook :: Derivation -> Derivation
79−wxcHook drv = drv & libraryDepends . system %~ Set.union (Set.fromList [dep "mesa", dep "libX11"])
80− & libraryDepends . pkgconfig . contains (dep "wxGTK") .~ True
81+wxcHook drv = drv & libraryDepends . system %~ Set.union (Set.fromList ["mesa", "libX11"])
82+ & libraryDepends . pkgconfig . contains "wxGTK" .~ True
8183 & phaseOverrides .~ wxcPostInstall (packageVersion drv)
8284 & runHaddock .~ False
8385 where
src/Distribution/Nixpkgs/Haskell.hs+11−25
@@ -9,7 +9,6 @@ module Distribution.Nixpkgs.Haskell
99 , phaseOverrides, editedCabalFile, metaSection
1010 , BuildInfo, haskell, pkgconfig, system, tool
1111 , dependencies, anyDep
12− , dep, unDep
1312 )
1413 where
1514
@@ -17,9 +16,9 @@ import Control.DeepSeq.Generics
1716import Control.Lens
1817import Data.Set ( Set )
1918import qualified Data.Set as Set
20−import Data.Function
19+import Data.Set.Lens
2120import Data.List
22−import Distribution.Version
21+import Language.Nix.Identifier
2322import Distribution.Nixpkgs.Meta
2423import Distribution.Nixpkgs.Fetch
2524import Distribution.Nixpkgs.Util.PrettyPrinting
@@ -28,10 +27,10 @@ import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
2827import GHC.Generics ( Generic )
2928
3029data BuildInfo = BuildInfo
31− { _haskell :: Set Dependency
32− , _pkgconfig :: Set Dependency
33− , _system :: Set Dependency
34− , _tool :: Set Dependency
30+ { _haskell :: Set Identifier
31+ , _pkgconfig :: Set Identifier
32+ , _system :: Set Identifier
33+ , _tool :: Set Identifier
3534 }
3635 deriving (Show, Eq, Generic)
3736
@@ -110,10 +109,6 @@ instance NFData Derivation where rnf = genericRnf
110109
111110instance NFData FlagName where rnf = genericRnf
112111
113−instance NFData VersionRange where rnf = genericRnf
114−
115−instance NFData Dependency where rnf = genericRnf
116−
117112instance Pretty Derivation where
118113 pPrint drv@(MkDerivation {..}) = funargs (map text ("mkDerivation" : toAscList inputs)) $$ vcat
119114 [ text "mkDerivation" <+> lbrace
@@ -143,7 +138,7 @@ instance Pretty Derivation where
143138 where
144139 inputs :: Set String
145140 inputs = Set.unions [ _extraFunctionArgs
146− , view (dependencies . anyDep . to (Set.map unDep)) drv
141+ , setOf (dependencies . anyDep . folded . ident) drv
147142 , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
148143 ]
149144
@@ -165,17 +160,8 @@ instance Pretty Derivation where
165160
166161pPrintBuildInfo :: String -> BuildInfo -> Doc
167162pPrintBuildInfo prefix bi = vcat
168− [ setattr (prefix++"HaskellDepends") (Set.map unDep (bi^.haskell))
169− , setattr (prefix++"SystemDepends") (Set.map unDep (bi^.system))
170− , setattr (prefix++"PkgconfigDepends") (Set.map unDep (bi^.pkgconfig))
171− , setattr (prefix++"ToolDepends") (Set.map unDep (bi^.tool))
163+ [ setattr (prefix++"HaskellDepends") (setOf (haskell.folded.ident) bi)
164+ , setattr (prefix++"SystemDepends") (setOf (system.folded.ident) bi)
165+ , setattr (prefix++"PkgconfigDepends") (setOf (pkgconfig.folded.ident) bi)
166+ , setattr (prefix++"ToolDepends") (setOf (tool.folded.ident) bi)
172167 ]
173−
174−dep :: String -> Dependency
175−dep s = Dependency (PackageName s) anyVersion
176−
177−unDep :: Dependency -> String
178−unDep (Dependency (PackageName x) _) = x
179−
180−instance Ord Dependency where
181− compare = compare `on` unDep
src/Language/Nix/Identifier.hs+8−3
@@ -1,13 +1,16 @@
1+{-# LANGUAGE DeriveGeneric #-}
12{-# LANGUAGE GeneralizedNewtypeDeriving #-}
23
34module Language.Nix.Identifier ( Identifier(..), ident, quote, needsQuoting ) where
45
6+import Control.DeepSeq.Generics
57import Control.Lens
68import Data.Char
79import Data.Function ( on )
810import Data.String
911import Distribution.Nixpkgs.Util.PrettyPrinting ( Pretty(..), text )
1012import Text.Regex.Posix
13+import GHC.Generics ( Generic )
1114
1215-- | Identifiers in Nix are essentially strings. Reasonable people restrict
1316-- themselves to identifiers of the form @[a-zA-Z\_][a-zA-Z0-9\_\'\-]*@,
@@ -26,9 +29,9 @@ import Text.Regex.Posix
2629-- >>> Identifier "abc" == Identifier "ABC"
2730-- False
2831-- >>> Identifier "abc" < Identifier "ABC"
29−-- True
30−-- >>> Identifier "abc" > Identifier "ABC"
3132-- False
33+-- >>> Identifier "abc" > Identifier "ABC"
34+-- True
3235-- >>> Identifier "X" > Identifier "a"
3336-- True
3437-- >>> Identifier "x" > Identifier "A"
@@ -38,7 +41,7 @@ import Text.Regex.Posix
3841-- prop> \str -> any (`elem` ['a'..'z']) str ==> Identifier (map toLower str) /= Identifier (map toUpper str)
3942
4043newtype Identifier = Identifier String
41− deriving (Show, Eq, IsString)
44+ deriving (Show, Eq, IsString, Generic)
4245
4346instance Pretty Identifier where
4447 pPrint i = text (i ^. ident . to quote)
@@ -49,6 +52,8 @@ instance Ord Identifier where
4952 EQ -> compare a b
5053 r -> r
5154
55+instance NFData Identifier where rnf = genericRnf
56+
5257-- | Checks whether a given string would need quoting when interpreted as an
5358-- intentifier.
5459
src/hackage2nix.hs+4−3
@@ -19,6 +19,7 @@ import Data.Maybe
1919import Data.Monoid
2020import Data.Set ( Set )
2121import qualified Data.Set as Set
22+import Language.Nix.Identifier
2223import Distribution.Compiler
2324import Distribution.Nixpkgs.Fetch
2425import Distribution.Nixpkgs.Haskell
@@ -143,13 +144,13 @@ generatePackageSet config hackage nixpkgs = do
143144 (missingDeps, _, drv') = cabal2nix resolver descr
144145
145146 haskellDependencies :: Set String
146− haskellDependencies = Set.map unDep $ mconcat [ drv'^.x.haskell | x <- [libraryDepends,executableDepends,testDepends] ]
147+ haskellDependencies = Set.map (view ident) $ mconcat [ drv'^.x.haskell | x <- [libraryDepends,executableDepends,testDepends] ]
147148
148149 systemDependencies :: Set String
149− systemDependencies = Set.map unDep $ mconcat [ drv'^.x.y | x <- [libraryDepends,executableDepends,testDepends], y <- [system,pkgconfig] ]
150+ systemDependencies = Set.map (view ident) $ mconcat [ drv'^.x.y | x <- [libraryDepends,executableDepends,testDepends], y <- [system,pkgconfig] ]
150151
151152 haskellOrSystemDependencies :: Set String
152− haskellOrSystemDependencies = Set.map unDep $ mconcat [ drv'^.x.tool | x <- [libraryDepends,executableDepends,testDepends] ]
153+ haskellOrSystemDependencies = Set.map (view ident) $ mconcat [ drv'^.x.tool | x <- [libraryDepends,executableDepends,testDepends] ]
153154
154155 missing :: Set String
155156 missing = Set.filter (`Set.notMember` knownAttributesSet) haskellDependencies