git.iko.soy/typeable/cabal2nix
on master help sign in
Improve type-safety of name mapping functions.
commitfc1140f35c93a2501b980175d985a1073dbc29df authorPeter Simons <simons@cryp.to> dateFri 21 Aug 2015, 00:28 (11 years ago) parentd67ab62
6 files changed+32−38
src/Distribution/Nixpkgs/Haskell.hs+2−2 src/Distribution/Nixpkgs/Haskell/FromCabal/Generate.hs+4−5 src/Distribution/Nixpkgs/Haskell/FromCabal/Name.hs+20−22 src/Distribution/Nixpkgs/Haskell/FromCabal/Normalize.hs+4−8 src/cabal2nix.hs+1 src/hackage2nix.hs+1−1
src/Distribution/Nixpkgs/Haskell.hs+2−2
@@ -55,7 +55,7 @@ data Derivation = MkDerivation
5555 , _src :: DerivationSource
5656 , _isLibrary :: Bool
5757 , _isExecutable :: Bool
58− , _extraFunctionArgs :: Set String
58+ , _extraFunctionArgs :: Set Identifier
5959 , _libraryDepends :: BuildInfo
6060 , _executableDepends :: BuildInfo
6161 , _testDepends :: BuildInfo
@@ -136,7 +136,7 @@ instance Pretty Derivation where
136136 ]
137137 where
138138 inputs :: Set String
139− inputs = Set.unions [ _extraFunctionArgs
139+ inputs = Set.unions [ Set.map (view ident) _extraFunctionArgs
140140 , setOf (dependencies . each . folded . ident) drv
141141 , Set.fromList ["fetch" ++ derivKind _src | derivKind _src /= "" && not isHackagePackage]
142142 ]
src/Distribution/Nixpkgs/Haskell/FromCabal/Generate.hs+4−5
@@ -22,7 +22,6 @@ import qualified Distribution.PackageDescription as Cabal
2222import Distribution.PackageDescription.Configuration
2323import Distribution.System
2424import Distribution.Text ( display )
25−import Language.Nix.Identifier
2625
2726cabal2nix :: FlagAssignment -> GenericPackageDescription -> Derivation
2827cabal2nix flags' cabal = normalize $ drv & cabalFlags .~ flags
@@ -80,7 +79,7 @@ cabal2nix' PackageDescription {..} = normalize $ postProcess $
8079
8180convertBuildInfo :: Cabal.BuildInfo -> Nix.BuildInfo
8281convertBuildInfo Cabal.BuildInfo {..} = mempty
83− & haskell .~ Set.fromList [ create ident y | (Dependency (PackageName y) _) <- targetBuildDepends ]
84− & system .~ Set.fromList [ create ident y | x <- extraLibs, y <- libNixName x, not (null y) ]
85− & pkgconfig .~ Set.fromList [ create ident y | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x, not (null y) ]
86− & tool .~ Set.fromList [ create ident y | Dependency (PackageName x) _ <- buildTools, y <- buildToolNixName x, not (null y) ]
82+ & haskell .~ Set.fromList [ toNixName x | (Dependency x _) <- targetBuildDepends ]
83+ & system .~ Set.fromList [ y | x <- extraLibs, y <- libNixName x ]
84+ & pkgconfig .~ Set.fromList [ y | Dependency (PackageName x) _ <- pkgconfigDepends, y <- libNixName x ]
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 #-}
22
3−import Data.Char
3+module Distribution.Nixpkgs.Haskell.FromCabal.Name ( toNixName, libNixName, buildToolNixName ) where
44
5−-- | Map Cabal names to Nix attribute names.
6−toNixName :: String -> String
7−toNixName = id
5+import Language.Nix.Identifier
6+import Distribution.Package
7+import Internal.Lens
88
9−-- | The old mapping function. This may be useful to generate a compatibility layer.
10−toNixName' :: String -> String
11−toNixName' [] = error "toNixName: empty string is not a valid argument"
12−toNixName' name = f name
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
9+-- | Map Cabal names to Nix attribute names.
10+toNixName :: PackageName -> Identifier
11+toNixName (PackageName "") = error "toNixName: invalid empty package name"
12+toNixName (PackageName n) = create ident n
1813
1914-- | Map libraries to Nix packages.
20−-- TODO: This should probably be configurable. We also need to consider the
21−-- possibility of name clashes with Haskell libraries. I have included
22−-- identity mappings to incicate that I have verified their correctness.
23−libNixName :: String -> [String]
15+--
16+-- TODO: This list should not be hard-coded here; it belongs into the Nixpkgs
17+-- repository.
18+
19+libNixName :: String -> [Identifier]
20+libNixName "" = []
2421libNixName "adns" = return "adns"
2522libNixName "alsa" = return "alsaLib"
2623libNixName "alut" = return "freealut"
@@ -121,7 +118,7 @@ libNixName "Qt5Qml" = return "qt5"
121118libNixName "Qt5Quick" = return "qt5"
122119libNixName "Qt5Widgets" = return "qt5"
123120libNixName "rtlsdr" = return "rtl-sdr"
124−libNixName "rt" = return [] -- in glibc
121+libNixName "rt" = [] -- in glibc
125122libNixName "ruby1.8" = return "ruby"
126123libNixName "sass" = return "libsass"
127124libNixName "sane-backends" = return "saneBackends"
@@ -163,12 +160,13 @@ libNixName "Xtst" = return "libXtst"
163160libNixName "Xxf86vm" = return "libXxf86vm"
164161libNixName "zmq" = return "zeromq"
165162libNixName "z" = return "zlib"
166−libNixName x = return x
163+libNixName x = return (create ident x)
167164
168165-- | 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")
170168buildToolNixName "cabal" = return "cabal-install"
171169buildToolNixName "gtk2hsC2hs" = return "gtk2hs-buildtools"
172170buildToolNixName "gtk2hsHookGenerator" = return "gtk2hs-buildtools"
173171buildToolNixName "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 @@
11module Distribution.Nixpkgs.Haskell.FromCabal.Normalize ( normalize, normalizeCabalFlags ) where
22
33import Distribution.Nixpkgs.Haskell.FromCabal.CorePackages
4−import Distribution.Nixpkgs.Haskell.FromCabal.Name
54import Data.Function
65import Data.List
76import Data.Set ( Set )
@@ -13,7 +12,7 @@ import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
1312import Distribution.Simple.Utils ( lowercase )
1413import Internal.Lens
1514import Internal.Regex ( regsubmatch )
16−import Language.Nix.Identifier ( Identifier, ident )
15+import Language.Nix.Identifier ( ident )
1716
1817normalize :: Derivation -> Derivation
1918normalize drv = drv
@@ -27,7 +26,7 @@ normalizeBuildInfo :: PackageName -> BuildInfo -> BuildInfo
2726normalizeBuildInfo (PackageName pname) bi = bi
2827 & haskell . contains (create ident pname) .~ False
2928 & 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)
3130
3231 {-
3332 {
@@ -64,11 +63,8 @@ normalizeSet = Set.filter (not . null)
6463-- normalizeNixLibs :: Set String -> Set String
6564-- normalizeNixLibs = normalizeSet . Set.fromList . concatMap libNixName . Set.toList
6665
67−normalizeNixBuildTools :: Set Identifier -> Set Identifier
68−normalizeNixBuildTools = Set.fromList . concatMap buildToolNixName' . Set.toList
69− where
70− buildToolNixName' :: Identifier -> [Identifier]
71− buildToolNixName' n = [ create ident n' | n' <- buildToolNixName (n^.ident) ]
66+-- normalizeNixBuildTools :: Set Identifier -> Set Identifier
67+-- normalizeNixBuildTools = Set.fromList . concatMap buildToolNixName . Set.toList
7268
7369-- |Strip any kind of path prefix from maintainer names, filter duplicates, and
7470-- sort the resulting list alphabetically.
src/cabal2nix.hs+1
@@ -1,4 +1,5 @@
11{-# LANGUAGE RecordWildCards #-}
2+{-# LANGUAGE OverloadedStrings #-}
23
34module Main ( main ) where
45
src/hackage2nix.hs+1−1
@@ -251,7 +251,7 @@ resolveNixpkgsIdentifier nixpkgs name
251251 | otherwise = Nothing
252252
253253goodScopes :: 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"]])
255255
256256getShortestPath :: [Path] -> Maybe Path
257257getShortestPath [] = Nothing