@@ -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)