git.iko.soy/typeable/cabal2nix
on master help sign in
Distribution/NixOS/Derivation/Cabal.hs: support custom 'configureFlags'
commitf640a5a4dcfc1beee50c51fb3a78e267cf053b50 authorPeter Simons <simons@cryp.to> dateFri 26 Aug 2011, 12:17 (15 years ago) parent3662c18
2 files changed+33−24
nixos-types.cabal+1−1 src/Distribution/NixOS/Derivation/Cabal.hs+32−23
nixos-types.cabal+1−1
@@ -1,5 +1,5 @@
11Name: nixos-types
2−Version: 1.0
2+Version: 1.1
33Copyright: Peter Simons, Andres Loeh
44License: BSD3
55License-File: LICENSE
src/Distribution/NixOS/Derivation/Cabal.hs+32−23
@@ -26,10 +26,11 @@ import Distribution.Package
2626#ifdef __HADDOCK__
2727import Distribution.PackageDescription ( PackageDescription )
2828#endif
29+import Distribution.PackageDescription ( FlagAssignment, FlagName(..) )
2930import Data.Version
3031import Data.List
3132import Data.Char
32−import Text.Regex.Posix
33+import Text.Regex.Posix hiding ( empty )
3334
3435-- | A represtation of Nix expressions for building Haskell packages.
3536-- The data type correspond closely to the definition of
@@ -39,17 +40,18 @@ import Text.Regex.Posix
3940-- but no parsing as of now!
4041
4142data Derivation = MkDerivation
42− { pname :: String
43− , version :: Version
44− , sha256 :: String
45− , isLibrary :: Bool
46− , isExecutable :: Bool
47− , buildDepends :: [String]
48− , buildTools :: [String]
49− , extraLibs :: [String]
50− , pkgConfDeps :: [String]
51− , runHaddock :: Bool
52− , metaSection :: Meta
43+ { pname :: String
44+ , version :: Version
45+ , sha256 :: String
46+ , isLibrary :: Bool
47+ , isExecutable :: Bool
48+ , buildDepends :: [String]
49+ , buildTools :: [String]
50+ , extraLibs :: [String]
51+ , pkgConfDeps :: [String]
52+ , configureFlags :: (FlagAssignment,[String])
53+ , runHaddock :: Bool
54+ , metaSection :: Meta
5355 }
5456 deriving (Show, Eq, Ord)
5557
@@ -74,6 +76,7 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
7476 , listattr "buildTools" (buildTools deriv)
7577 , listattr "extraLibraries" (extraLibs deriv)
7678 , listattr "pkgconfigDepends" (pkgConfDeps deriv)
79+ , onlyIf renderedFlags $ attr "configureFlags" $ doubleQuotes (sep renderedFlags)
7780 , boolattr "noHaddock" (not (runHaddock deriv)) (not (runHaddock deriv))
7881 , disp (metaSection deriv)
7982 ]
@@ -85,6 +88,11 @@ renderDerivation deriv = funargs (map text ("cabal" : inputs)) $$ vcat
8588 filter (/="cabal") $ filter (/="Cabal") $
8689 buildDepends deriv ++ buildTools deriv ++ extraLibs deriv ++ pkgConfDeps deriv
8790
91+ (flags,extraFlags) = configureFlags deriv
92+ renderedFlags = renderedFlagAssignment ++ renderedExtraFlags
93+ renderedFlagAssignment = [ text "-f" <> (if enable then empty else char '-') <> text f | (FlagName f, enable) <- flags ]
94+ renderedExtraFlags = map text extraFlags
95+
8896-- | A very incomplete parser that extracts 'pname', 'version',
8997-- 'sha256', 'platforms', 'maintainers', and 'runHaddock' from the given
9098-- Nix expression.
@@ -100,17 +108,18 @@ parseDerivation buf
100108 , maint <- buf `regsubmatch` "maintainers *= *\\[([^\"]+)]"
101109 , noHaddock <- buf `regsubmatch` "noHaddock *= *(true|false) *;"
102110 = Just $ MkDerivation
103− { pname = name
104− , version = vers
105− , sha256 = sha
106− , isLibrary = False
107− , isExecutable = False
108− , buildDepends = []
109− , buildTools = []
110− , extraLibs = []
111− , pkgConfDeps = []
112− , runHaddock = case noHaddock of "true":[] -> False
113− _ -> True
111+ { pname = name
112+ , version = vers
113+ , sha256 = sha
114+ , isLibrary = False
115+ , isExecutable = False
116+ , buildDepends = []
117+ , buildTools = []
118+ , extraLibs = []
119+ , pkgConfDeps = []
120+ , configureFlags = ([],[])
121+ , runHaddock = case noHaddock of "true":[] -> False
122+ _ -> True
114123 , metaSection = Meta
115124 { homepage = ""
116125 , description = ""