git.iko.soy/typeable/cabal2nix
on master help sign in
Add --compiler-id for specifying compiler id.

This is useful for specifying the branch in "if impl(...)" expressions. Useful for generating nix expression for projects that support both GHC and GHCJS, but have different dependencies depending on the compiler.

commitfa93bd025b78ec9e11cd1c83b283893b9ec175d9 authorJussi Maki <jussi.maki@digitalasset.com> dateFri 3 Jun 2016, 11:30 (10 years ago) parent35f7635
1 file changed+9−3
cabal2nix/src/Main.hs+9−3
cabal2nix/src/Main.hs+9−3
@@ -15,7 +15,7 @@ import Distribution.Nixpkgs.Meta
1515import Distribution.PackageDescription ( FlagName(..), FlagAssignment )
1616import Distribution.Simple.Utils ( lowercase )
1717import Distribution.System
18−import Distribution.Text ( display )
18+import Distribution.Text ( display, simpleParse )
1919import Language.Nix
2020import Options.Applicative
2121import Paths_cabal2nix
@@ -41,6 +41,7 @@ data Options = Options
4141 , optHackageDb :: Maybe FilePath
4242 , optNixShellOutput :: Bool
4343 , optFlags :: [String]
44+ , optCompilerId :: Maybe String
4445 , optUrl :: String
4546 }
4647 deriving (Show)
@@ -62,6 +63,7 @@ options = Options
6263 <*> optional (strOption $ long "hackage-db" <> metavar "PATH" <> help "path to the local hackage db in tar format")
6364 <*> switch (long "shell" <> help "generate output suitable for nix-shell")
6465 <*> many (strOption $ short 'f' <> long "flag" <> help "Cabal flag (may be specified multiple times)")
66+ <*> optional (strOption $ long "compiler-id" <> help "Compiler identifier to use when evaluating cabal file")
6567 <*> strArgument (metavar "URI")
6668
6769pinfo :: ParserInfo Options
@@ -97,11 +99,15 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
9799
98100 pkg <- getPackage optHackageDb $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256)
99101
100− let deriv :: Derivation
102+ let
103+ compilerId :: CompilerId
104+ compilerId = fromMaybe buildCompilerId (optCompilerId >>= simpleParse)
105+
106+ deriv :: Derivation
101107 deriv = fromGenericPackageDescription (const True)
102108 (\i -> Just (binding # (i, path # [i])))
103109 buildPlatform
104− (unknownCompilerInfo buildCompilerId NoAbiTag)
110+ (unknownCompilerInfo compilerId NoAbiTag)
105111 (readFlagList optFlags)
106112 []
107113 (pkgCabal pkg)