git.iko.soy/typeable/cabal2nix
on master help sign in
Improve type-safety of name mapping functions.
fc1140fPeter Simons
src/Distribution/Nixpkgs/Haskell.hs+2−2
@@ -55,7 +55,7 @@ data Derivation = MkDerivation
55 , _src :: DerivationSource
55 , _src :: DerivationSource
56 , _isLibrary :: Bool
56 , _isLibrary :: Bool
57 , _isExecutable :: Bool
57 , _isExecutable :: Bool
58− , _extraFunctionArgs :: Set String
58+ , _extraFunctionArgs :: Set Identifier
59 , _libraryDepends :: BuildInfo
59 , _libraryDepends :: BuildInfo
60 , _executableDepends :: BuildInfo
60 , _executableDepends :: BuildInfo
61 , _testDepends :: BuildInfo
61 , _testDepends :: BuildInfo
@@ -136,7 +136,7 @@ instance Pretty Derivation where
136 ]
136 ]
137 where
137 where
138 inputs :: Set String
138 inputs :: Set String
139− inputs = Set.unions [ _extraFunctionArgs
139+ inputs = Set.unions [ Set.map (view ident) _extraFunctionArgs
140 , setOf (dependencies . each . folded . ident) drv
140 , setOf (dependencies . each . folded . ident) drv
141 , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
141 , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
142 ]
142 ]
src/Distribution/Nixpkgs/Haskell/FromCabal/Generate.hs+4−5
@@ -22,7 +22,6 @@ import qualified Distribution.PackageDescription as Cabal
22import Distribution.PackageDescription.Configuration
22import Distribution.PackageDescription.Configuration
23import Distribution.System
23import Distribution.System
24import Distribution.Text ( display )
24import Distribution.Text ( display )
25−import Language.Nix.Identifier
26
25
27cabal2nix :: FlagAssignment -> GenericPackageDescription -> Derivation
26cabal2nix :: FlagAssignment -> GenericPackageDescription -> Derivation
28cabal2nix flags' cabal = normalize $ drv & cabalFlags .~ flags
27cabal2nix flags' cabal = normalize $ drv & cabalFlags .~ flags
@@ -80,7 +79,7 @@ cabal2nix' PackageDescription {..} = normalize $ postProcess $
80
79
81convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
80convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
82convertBuildInfo Cabal.BuildInfo {..} = mempty
81convertBuildInfo Cabal.BuildInfo {..} = mempty
83− & haskell .~ Set.fromList [ create ident y | (Dependency (PackageName y) _) <- targetBuildDepends ]
82+ & haskell .~ Set.fromList [ toNixName x | (Dependency x _) <- targetBuildDepends ]
84− & system .~ Set.fromList [ create ident y | x <- extraLibs, y <- libNixName x, not (null y) ]
83+ & system .~ Set.fromList [ y | x <- extraLibs, y <- libNixName x ]
85− & pkgconfig .~ Set.fromList [ create ident y | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x, not (null y) ]
84+ & pkgconfig .~ Set.fromList [ y | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x ]
86− & tool .~ Set.fromList [ create ident y | Dependency (PackageName x) _ <- buildTools, y <- buildToolNixName x, not (null y) ]
85+ & tool .~ Set.fromList [ y | Dependency (PackageName x) _ <- buildTools, y <- buildToolNixName x ]
src/Distribution/Nixpkgs/Haskell/FromCabal/Name.hs+20−22
@@ -1,26 +1,23 @@
1−module Distribution.Nixpkgs.Haskell.FromCabal.Name ( toNixName, toNixName', libNixName, buildToolNixName ) where
1+{-# LANGUAGE OverloadedStrings #-}
2
2
3−import Data.Char
3+module Distribution.Nixpkgs.Haskell.FromCabal.Name ( toNixName, libNixName, buildToolNixName ) where
4
4
5−-- | Map Cabal names to Nix attribute names.
5+import Language.Nix.Identifier
6−toNixName :: String -> String
6+import Distribution.Package
7−toNixName = id
7+import Internal.Lens
8
8
9−-- | The old mapping function. This may be useful to generate a compatibility layer.
9+-- | Map Cabal names to Nix attribute names.
10−toNixName' :: String -> String
10+toNixName :: PackageName -> Identifier
11−toNixName' [] = error "toNixName: empty string is not a valid argument"
11+toNixName (PackageName "") = error "toNixName: invalid empty package name"
12−toNixName' name = f name
12+toNixName (PackageName n) = create ident n
13− where
14− f [] = []
15− f ('-':c:cs) | c `notElem` "-" = toUpper c : f cs
16− f ('-':_) = error ("unexpected package name " ++ show name)
17− f (c:cs) = c : f cs
18
13
19-- | Map libraries to Nix packages.
14-- | Map libraries to Nix packages.
20−-- TODO: This should probably be configurable. We also need to consider the
15+--
21−-- possibility of name clashes with Haskell libraries. I have included
16+-- TODO: This list should not be hard-coded here; it belongs into the Nixpkgs
22−-- identity mappings to incicate that I have verified their correctness.
17+-- repository.
18+
23−libNixName :: String -> [String]
19+libNixName :: String -> [Identifier]
20+libNixName "" = []
24libNixName "adns" = return "adns"
21libNixName "adns" = return "adns"
25libNixName "alsa" = return "alsaLib"
22libNixName "alsa" = return "alsaLib"
26libNixName "alut" = return "freealut"
23libNixName "alut" = return "freealut"
@@ -121,7 +118,7 @@ libNixName "Qt5Qml" = return "qt5"
121libNixName "Qt5Quick" = return "qt5"
118libNixName "Qt5Quick" = return "qt5"
122libNixName "Qt5Widgets" = return "qt5"
119libNixName "Qt5Widgets" = return "qt5"
123libNixName "rtlsdr" = return "rtl-sdr"
120libNixName "rtlsdr" = return "rtl-sdr"
124−libNixName "rt" = return [] -- in glibc
121+libNixName "rt" = [] -- in glibc
125libNixName "ruby1.8" = return "ruby"
122libNixName "ruby1.8" = return "ruby"
126libNixName "sass" = return "libsass"
123libNixName "sass" = return "libsass"
127libNixName "sane-backends" = return "saneBackends"
124libNixName "sane-backends" = return "saneBackends"
@@ -163,12 +160,13 @@ libNixName "Xtst" = return "libXtst"
163libNixName "Xxf86vm" = return "libXxf86vm"
160libNixName "Xxf86vm" = return "libXxf86vm"
164libNixName "zmq" = return "zeromq"
161libNixName "zmq" = return "zeromq"
165libNixName "z" = return "zlib"
162libNixName "z" = return "zlib"
166−libNixName x = return x
163+libNixName x = return (create ident x)
167
164
168-- | Map build tool names to Nix attribute names.
165-- | Map build tool names to Nix attribute names.
169−buildToolNixName :: String -> [String]
166+buildToolNixName :: String -> [Identifier]
167+buildToolNixName "" = return (error "buildToolNixName: invalid empty dependency name")
170buildToolNixName "cabal" = return "cabal-install"
168buildToolNixName "cabal" = return "cabal-install"
171buildToolNixName "gtk2hsC2hs" = return "gtk2hs-buildtools"
169buildToolNixName "gtk2hsC2hs" = return "gtk2hs-buildtools"
172buildToolNixName "gtk2hsHookGenerator" = return "gtk2hs-buildtools"
170buildToolNixName "gtk2hsHookGenerator" = return "gtk2hs-buildtools"
173buildToolNixName "gtk2hsTypeGen" = return "gtk2hs-buildtools"
171buildToolNixName "gtk2hsTypeGen" = return "gtk2hs-buildtools"
174−buildToolNixName x = return (toNixName x)
172+buildToolNixName x = return (create ident x)
src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs+4−8
@@ -1,7 +1,6 @@
1module Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalize, normalizeCabalFlags ) where
1module Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalize, normalizeCabalFlags ) where
2
2
3import Distribution.Nixpkgs.Haskell.FromCabal.CorePackages
3import Distribution.Nixpkgs.Haskell.FromCabal.CorePackages
4−import Distribution.Nixpkgs.Haskell.FromCabal.Name
5import Data.Function
4import Data.Function
6import Data.List
5import Data.List
7import Data.Set ( Set )
6import Data.Set ( Set )
@@ -13,7 +12,7 @@ import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
13import Distribution.Simple.Utils ( lowercase )
12import Distribution.Simple.Utils ( lowercase )
14import Internal.Lens
13import Internal.Lens
15import Internal.Regex ( regsubmatch )
14import Internal.Regex ( regsubmatch )
16−import Language.Nix.Identifier ( Identifier, ident )
15+import Language.Nix.Identifier ( ident )
17
16
18normalize :: Derivation -> Derivation
17normalize :: Derivation -> Derivation
19normalize drv = drv
18normalize drv = drv
@@ -27,7 +26,7 @@ normalizeBuildInfo :: PackageName -> BuildInfo -> BuildInfo
27normalizeBuildInfo (PackageName pname) bi = bi
26normalizeBuildInfo (PackageName pname) bi = bi
28 & haskell . contains (create ident pname) .~ False
27 & haskell . contains (create ident pname) .~ False
29 & tool . contains (create ident pname) .~ False
28 & tool . contains (create ident pname) .~ False
30− & tool %~ normalizeNixBuildTools . Set.filter (\n -> n^.ident `notElem` coreBuildTools)
29+ & tool %~ Set.filter (\n -> n^.ident `notElem` coreBuildTools)
31
30
32 {-
31 {-
33 {
32 {
@@ -64,11 +63,8 @@ normalizeSet = Set.filter (not . null)
64-- normalizeNixLibs :: Set String -> Set String
63-- normalizeNixLibs :: Set String -> Set String
65-- normalizeNixLibs = normalizeSet . Set.fromList . concatMap libNixName . Set.toList
64-- normalizeNixLibs = normalizeSet . Set.fromList . concatMap libNixName . Set.toList
66
65
67−normalizeNixBuildTools :: Set Identifier -> Set Identifier
66+-- normalizeNixBuildTools :: Set Identifier -> Set Identifier
68−normalizeNixBuildTools = Set.fromList . concatMap buildToolNixName' . Set.toList
67+-- normalizeNixBuildTools = Set.fromList . concatMap buildToolNixName . Set.toList
69− where
70− buildToolNixName' :: Identifier -> [Identifier]
71− buildToolNixName' n = [ create ident n' | n' <- buildToolNixName (n^.ident) ]
72
68
73-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
69-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
74-- sort the resulting list alphabetically.
70-- sort the resulting list alphabetically.
src/cabal2nix.hs+1
@@ -1,4 +1,5 @@
1{-# LANGUAGE RecordWildCards #-}
1{-# LANGUAGE RecordWildCards #-}
2+{-# LANGUAGE OverloadedStrings #-}
2
3
3module Main ( main ) where
4module Main ( main ) where
4
5
src/hackage2nix.hs+1−1
@@ -251,7 +251,7 @@ resolveNixpkgsIdentifier nixpkgs name
251 | otherwise = Nothing
251 | otherwise = Nothing
252
252
253goodScopes :: Set Path
253goodScopes :: Set Path
254−goodScopes = Set.fromList ((map (create path . ("pkgs":))) [[], ["xlibs"], ["gnome"], ["gnome3"], ["kde4"]])
254+goodScopes = Set.fromList (map (create path . ("pkgs":)) [[], ["xlibs"], ["gnome"], ["gnome3"], ["kde4"]])
255
255
256getShortestPath :: [Path] -> Maybe Path
256getShortestPath :: [Path] -> Maybe Path
257getShortestPath [] = Nothing
257getShortestPath [] = Nothing