diff --git a/doc/nix_integration.md b/doc/nix_integration.md index af1575d3cd..365de35adb 100644 --- a/doc/nix_integration.md +++ b/doc/nix_integration.md @@ -200,20 +200,24 @@ equivalent of the configuration used in 2015-03-05): ```nix +{ghc}: with (import {}); haskell.lib.buildStackProject { name = "myEnv"; - buildInputs = [ glpk pcre ]; + buildInputs = [ ghc glpk pcre ]; } ``` -Defining manually a `shell.nix` file gives you the possibility to -override some Nix derivations ("packages"), for instance to change -some build options of the libraries you use, or to set additional -environment variables. See the [Nix manual][nix-manual-exprs] for -more. The `buildStackProject` utility function is documented in the -[Nixpkgs manual][nixpkgs-manual-haskell]. +Defining manually a `shell.nix` file gives you the possibility to override some +Nix derivations ("packages"), for instance to change some build options of the +libraries you use, or to set additional environment variables. See the +[Nix manual][nix-manual-exprs] for more. The `buildStackProject` utility +function is documented in the [Nixpkgs manual][nixpkgs-manual-haskell]. In such +case, stack expect this file to define a function of exactly one argument that +should be called `ghc` (as arguments within a set are non-positional), which you +should give to `buildInputs`. This is the ghc from the resolver you set in the +`stack.yaml`. And now for the `stack.yaml` file: diff --git a/src/Stack/Nix.hs b/src/Stack/Nix.hs index 213d2ead85..840f05c7af 100644 --- a/src/Stack/Nix.hs +++ b/src/Stack/Nix.hs @@ -84,10 +84,12 @@ runShellAndExit mprojectRoot maresolver mcompiler getCmdArgs = do traverse (resolveFile (fromMaybeProjectRoot mprojectRoot)) $ nixInitFile (configNix config) let pkgsInConfig = nixPackages (configNix config) - pkgs = pkgsInConfig ++ [nixCompiler config mresolver mcompiler] + ghc = nixCompiler config mresolver mcompiler + pkgs = pkgsInConfig ++ [ghc] pureShell = nixPureShell (configNix config) nixopts = case mshellFile of - Just fp -> [toFilePath fp] + Just fp -> [toFilePath fp, "--arg", "ghc" + ,"with (import {}); " ++ T.unpack ghc] Nothing -> ["-E", T.unpack $ T.intercalate " " $ concat [["with (import {});" ,"runCommand \"myEnv\" {"