From 4edd98544b05f3e77dcd70feed13693513b7c322 Mon Sep 17 00:00:00 2001 From: YPares Date: Mon, 6 Jun 2016 11:42:09 +0200 Subject: [PATCH] Stack/Nix used with a shell file now expects a function Addresses https://github.com/commercialhaskell/stack/issues/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. --- doc/nix_integration.md | 18 +++++++++++------- src/Stack/Nix.hs | 6 ++++-- 2 files changed, 15 insertions(+), 9 deletions(-) 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\" {"