Skip to content

Commit

Permalink
Merge pull request #5494 from domenkozar/nix-compiler-version
Browse files Browse the repository at this point in the history
Nix: support passing ghcVersion to shell.nix
  • Loading branch information
qrilka authored Mar 2, 2021
2 parents 88b0ee9 + 3a9932c commit 3c3717d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Behavior changes:

Other enhancements:

* Nix integration now passes `ghcVersion` (in addition to existing `ghc`) to
`shell-file` as an identifier that can be looked up in a compiler attribute set.

* `stack list` is a new command to list package versions in a snapshot.
See [#5431](https://github.com/commercialhaskell/stack/pull/5431)

Expand Down
11 changes: 11 additions & 0 deletions src/Stack/Config/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Stack.Config.Nix
(nixOptsFromMonoid
,nixCompiler
,nixCompilerVersion
,StackNixException(..)
) where

Expand Down Expand Up @@ -77,6 +78,16 @@ nixCompiler compilerVersion =
WCGhcjs{} -> Left $ stringException "Only GHC is supported by stack --nix"
WCGhcGit{} -> Left $ stringException "Only GHC is supported by stack --nix"

nixCompilerVersion :: WantedCompiler -> Either StringException T.Text
nixCompilerVersion compilerVersion =
case compilerVersion of
WCGhc version ->
case T.split (== '.') (fromString $ versionString version) of
x : y : minor -> Right $ "ghc" <> T.concat (x : y : minor)
_ -> Left $ stringException "GHC major version not specified"
WCGhcjs{} -> Left $ stringException "Only GHC is supported by stack --nix"
WCGhcGit{} -> Left $ stringException "Only GHC is supported by stack --nix"

-- Exceptions thown specifically by Stack.Nix
data StackNixException
= NixCannotUseShellFileAndPackagesException
Expand Down
8 changes: 5 additions & 3 deletions src/Stack/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Data.Version (showVersion)
import Path.IO
import qualified Paths_stack as Meta
import Stack.Config (getInContainer, withBuildConfig)
import Stack.Config.Nix (nixCompiler)
import Stack.Config.Nix (nixCompiler, nixCompilerVersion)
import Stack.Constants (platformVariantEnvVar,inNixShellEnvVar,inContainerEnvVar)
import Stack.Types.Config
import Stack.Types.Docker
Expand Down Expand Up @@ -56,14 +56,16 @@ runShellAndExit = do
compilerVersion <- withBuildConfig $ view wantedCompilerVersionL

ghc <- either throwIO return $ nixCompiler compilerVersion
ghcVersion <- either throwIO return $ nixCompilerVersion compilerVersion
let pkgsInConfig = nixPackages (configNix config)
pkgs = pkgsInConfig ++ [ghc, "git", "gcc", "gmp"]
pkgsStr = "[" <> T.intercalate " " pkgs <> "]"
pureShell = nixPureShell (configNix config)
addGCRoots = nixAddGCRoots (configNix config)
nixopts = case mshellFile of
Just fp -> [toFilePath fp, "--arg", "ghc"
,"with (import <nixpkgs> {}); " ++ T.unpack ghc]
Just fp -> [toFilePath fp
,"--arg", "ghc", "with (import <nixpkgs> {}); " ++ T.unpack ghc
,"--argstr", "ghcVersion", T.unpack ghcVersion]
Nothing -> ["-E", T.unpack $ T.concat
["with (import <nixpkgs> {}); "
,"let inputs = ",pkgsStr,"; "
Expand Down

0 comments on commit 3c3717d

Please sign in to comment.