Skip to content

Commit

Permalink
Stack/Nix used with a shell file now expects a function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
YPares committed Jun 6, 2016
1 parent 3103ebe commit 4edd985
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 11 additions & 7 deletions doc/nix_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,24 @@ equivalent of the configuration used in
2015-03-05):

```nix
{ghc}:
with (import <nixpkgs> {});
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:

Expand Down
6 changes: 4 additions & 2 deletions src/Stack/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nixpkgs> {}); " ++ T.unpack ghc]
Nothing -> ["-E", T.unpack $ T.intercalate " " $ concat
[["with (import <nixpkgs> {});"
,"runCommand \"myEnv\" {"
Expand Down

0 comments on commit 4edd985

Please sign in to comment.