Skip to content

Commit 09d75be

Browse files
Merge pull request #4189 from ttuegel/bugfix/no-hardcode-nix-compiler
Do not hardcode GHC versions for Nixpkgs
2 parents a111f67 + c5d8a65 commit 09d75be

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ Other enhancements:
8888
* It is possible to specify the Hackage base URL to upload packages to, instead
8989
of the default of `https://hackage.haskell.org/`, by using `hackage-base-url`
9090
configuration option.
91+
* When using Nix, if a specific minor version of GHC is not requested, the
92+
latest minor version in the given major branch will be used automatically.
9193

9294
Bug fixes:
9395

src/Stack/Config/Nix.hs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,28 @@ nixOptsFromMonoid NixOptsMonoid{..} os = do
5555

5656
nixCompiler :: CompilerVersion a -> Either StringException T.Text
5757
nixCompiler compilerVersion =
58-
let -- These are the latest minor versions for each respective major version available in nixpkgs
59-
fixMinor "8.2" = "8.2.1"
60-
fixMinor "8.0" = "8.0.2"
61-
fixMinor "7.10" = "7.10.3"
62-
fixMinor "7.8" = "7.8.4"
63-
fixMinor "7.6" = "7.6.3"
64-
fixMinor "7.4" = "7.4.2"
65-
fixMinor "7.2" = "7.2.2"
66-
fixMinor "6.12" = "6.12.3"
67-
fixMinor "6.10" = "6.10.4"
68-
fixMinor v = v
69-
nixCompilerFromVersion v = T.append (T.pack "haskell.compiler.ghc")
70-
(T.filter (/= '.')
71-
(fixMinor (versionText v)))
72-
in case compilerVersion of
73-
GhcVersion v -> Right $ nixCompilerFromVersion v
74-
_ -> Left $ stringException "Only GHC is supported by stack --nix"
58+
case compilerVersion of
59+
GhcVersion version ->
60+
case T.split (== '.') (versionText version) of
61+
x : y : minor ->
62+
Right $
63+
case minor of
64+
[] ->
65+
-- The minor version is not specified. Select the latest minor
66+
-- version in Nixpkgs corresponding to the requested major
67+
-- version.
68+
let major = T.concat [x, y] in
69+
"(let compilers = builtins.filter \
70+
\(name: builtins.match \
71+
\\"ghc" <> major <> "[[:digit:]]*\" name != null) \
72+
\(lib.attrNames haskell.compiler); in \
73+
\if compilers == [] \
74+
\then abort \"No compiler found for GHC "
75+
<> versionText version <> "\"\
76+
\else haskell.compiler.${builtins.head compilers})"
77+
_ -> "haskell.compiler.ghc" <> T.concat (x : y : minor)
78+
_ -> Left $ stringException "GHC major version not specified"
79+
_ -> Left $ stringException "Only GHC is supported by stack --nix"
7580

7681
-- Exceptions thown specifically by Stack.Nix
7782
data StackNixException

0 commit comments

Comments
 (0)