git.iko.soy/typeable/cabal2nix
on master help sign in
cabal2nix: improve flexibility of the generated shell.nix file

The output produced by "cabal2nix --shell" is now more versatile: - Running "nix-shell" will enter an interactive environment that's suitable for compiling the generated Haskell package. - Running "nix-build shell.nix" will compile the package with Nix. (Note that you may have to clean the "dist/" directory for these builds to succeed.) - Either command can be passed an argument "--argstr compiler ghcXYZ" to determine the Haskell package set to use for the build. For example, "--argstr compiler ghc784" instantiates the expression to use GHC 7.8.4. The default choice is "ghc7101".

commita7998916868af0d09882468b3e43f5854082860f authorPeter Simons <simons@cryp.to> dateMon 25 May 2015, 14:40 (11 years ago) parent6b77548
1 file changed+14−5
src/cabal2nix.hs+14−5
src/cabal2nix.hs+14−5
@@ -122,11 +122,20 @@ main = bracket (return ()) (\() -> hFlush stdout >> hFlush stderr) $ \() -> do
122122
123123 shell :: Doc -> Doc
124124 shell expr = vcat
125− [ text "with (import <nixpkgs> {}).pkgs;"
126− , text "let pkg = " <> hang (text "haskellngPackages.callPackage") 2 (parens expr) <+> braces empty <> semi
127− , text "in"
128− , text " pkg.env"
129− ]
125+ [ text "{ nixpkgs ? import <nixpkgs> {}, compiler ? \"ghc7101\" }:"
126+ , text ""
127+ , text "let"
128+ , text ""
129+ , text " inherit (nixpkgs) pkgs;"
130+ , text ""
131+ , text " f = " <> expr <> semi
132+ , text ""
133+ , text " drv = pkgs.haskell.packages.${compiler}.callPackage f {};"
134+ , text ""
135+ , text "in"
136+ , text ""
137+ , text " if pkgs.lib.inNixShell then drv.env else drv"
138+ ]
130139
131140 deriv''' | optNixShellOutput cfg = shell deriv''
132141 | otherwise = deriv''