diff --git a/ChangeLog.md b/ChangeLog.md index c9f0e5876f..adff519513 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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) diff --git a/src/Stack/Config/Nix.hs b/src/Stack/Config/Nix.hs index 896836f785..97d847ede5 100644 --- a/src/Stack/Config/Nix.hs +++ b/src/Stack/Config/Nix.hs @@ -5,6 +5,7 @@ module Stack.Config.Nix (nixOptsFromMonoid ,nixCompiler + ,nixCompilerVersion ,StackNixException(..) ) where @@ -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 diff --git a/src/Stack/Nix.hs b/src/Stack/Nix.hs index ed167403e0..81e383d7c1 100644 --- a/src/Stack/Nix.hs +++ b/src/Stack/Nix.hs @@ -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 @@ -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 {}); " ++ T.unpack ghc] + Just fp -> [toFilePath fp + ,"--arg", "ghc", "with (import {}); " ++ T.unpack ghc + ,"--argstr", "ghcVersion", T.unpack ghcVersion] Nothing -> ["-E", T.unpack $ T.concat ["with (import {}); " ,"let inputs = ",pkgsStr,"; "