@@ -1,26 +1,23 @@
1−module Distribution.Nixpkgs.Haskell.FromCabal.Name ( toNixName, toNixName', libNixName, buildToolNixName ) where
1+{-# LANGUAGE OverloadedStrings #-}
3−import Data.Char
3+module Distribution.Nixpkgs.Haskell.FromCabal.Name ( toNixName, libNixName, buildToolNixName ) where
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
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
15− f ('-':c:cs) | c `notElem` "-" = toUpper c : f cs
16− f ('-':_) = error ("unexpected package name " ++ show name)
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.
23−libNixName :: String -> [String]
19+libNixName :: String -> [Identifier]
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)
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)