Skip to content

Commit 4edd985

Browse files
committed
Stack/Nix used with a shell file now expects a function
Addresses commercialhaskell#2243 The shell file should expect a `{ghc}` argument which should be passed to the `buildInputs`, so the stack environment contains the right GHC If the shell file doesn't define a function, then the ghc passed by stack is just ignored, but the doc doesn't mention it in order to encourage this new good practise.
1 parent 3103ebe commit 4edd985

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

doc/nix_integration.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,24 @@ equivalent of the configuration used in
200200
2015-03-05):
201201

202202
```nix
203+
{ghc}:
203204
with (import <nixpkgs> {});
204205
205206
haskell.lib.buildStackProject {
206207
name = "myEnv";
207-
buildInputs = [ glpk pcre ];
208+
buildInputs = [ ghc glpk pcre ];
208209
}
209210
```
210211

211-
Defining manually a `shell.nix` file gives you the possibility to
212-
override some Nix derivations ("packages"), for instance to change
213-
some build options of the libraries you use, or to set additional
214-
environment variables. See the [Nix manual][nix-manual-exprs] for
215-
more. The `buildStackProject` utility function is documented in the
216-
[Nixpkgs manual][nixpkgs-manual-haskell].
212+
Defining manually a `shell.nix` file gives you the possibility to override some
213+
Nix derivations ("packages"), for instance to change some build options of the
214+
libraries you use, or to set additional environment variables. See the
215+
[Nix manual][nix-manual-exprs] for more. The `buildStackProject` utility
216+
function is documented in the [Nixpkgs manual][nixpkgs-manual-haskell]. In such
217+
case, stack expect this file to define a function of exactly one argument that
218+
should be called `ghc` (as arguments within a set are non-positional), which you
219+
should give to `buildInputs`. This is the ghc from the resolver you set in the
220+
`stack.yaml`.
217221

218222
And now for the `stack.yaml` file:
219223

src/Stack/Nix.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ runShellAndExit mprojectRoot maresolver mcompiler getCmdArgs = do
8484
traverse (resolveFile (fromMaybeProjectRoot mprojectRoot)) $
8585
nixInitFile (configNix config)
8686
let pkgsInConfig = nixPackages (configNix config)
87-
pkgs = pkgsInConfig ++ [nixCompiler config mresolver mcompiler]
87+
ghc = nixCompiler config mresolver mcompiler
88+
pkgs = pkgsInConfig ++ [ghc]
8889
pureShell = nixPureShell (configNix config)
8990
nixopts = case mshellFile of
90-
Just fp -> [toFilePath fp]
91+
Just fp -> [toFilePath fp, "--arg", "ghc"
92+
,"with (import <nixpkgs> {}); " ++ T.unpack ghc]
9193
Nothing -> ["-E", T.unpack $ T.intercalate " " $ concat
9294
[["with (import <nixpkgs> {});"
9395
,"runCommand \"myEnv\" {"

0 commit comments

Comments
 (0)