Skip to content

Commit 66fce68

Browse files
committed
Fix stack integration, use version of stack2nix that supports Stack 2.
This uses @qrilka's work from nh2/stack2nix#1, now moved to nh2/stack2nix#2. Unfortunately, this introduces a backwards incompatibility for stack users: The `stack2nix-script` nix expression now needs to be passed `inherit compiler`, to satisfy stack complaining if there's no matching GHC on PATH (even though we don't use it). I haven't found a way around that yet. Example change that users need to make in their `default.nix` for building stack projects statically: stack2nix-script = import "${static-haskell-nix}/static-stack2nix-builder/stack2nix-script.nix" { inherit pkgs; + inherit compiler; stack-project-dir = toString ./.; # where stack.yaml is hackageSnapshot = "2021-07-11T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions };
1 parent fd0816f commit 66fce68

File tree

10 files changed

+35
-55
lines changed

10 files changed

+35
-55
lines changed

.buildkite/pipeline.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ steps:
5454
5555
cd static-stack/
5656
mkdir -p static-stack-test-dir
57-
curl -L https://github.com/commercialhaskell/stack/archive/v2.1.3.tar.gz | tar -xz -C static-stack-test-dir
58-
# Use lts-12 because ghc822 is no longer in nixpkgs
59-
cp static-stack-test-dir/stack-*/stack-lts-12.yaml static-stack-test-dir/stack-*/stack.yaml
60-
61-
echo "Overriding point release of unix-compat, see https://github.com/nh2/static-haskell-nix/issues/79"
62-
perl -pi -e 's/^packages:/packages:\n- unix-compat-0.5.2\@rev:0/g' static-stack-test-dir/stack-*/snapshot-lts-12.yaml
57+
curl -L https://github.com/commercialhaskell/stack/archive/v2.7.1.tar.gz | tar -xz -C static-stack-test-dir
6358
6459
$(nix-build --no-link -A fullBuildScript --argstr stackDir $PWD/static-stack-test-dir/stack-*)

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,7 @@ The [`static-stack`](./static-stack) directory shows how Stack itself can be bui
116116
then `/nix/store/dax3wjbjfrcwj6r3mafxj5fx6wcg5zbp-stack-2.3.0.1` is your final output _store path_ whose `/bin` directory contains your static executable.
117117
* I get `stack2nix: user error (No such package mypackage-1.2.3 in the cabal database. Did you run cabal update?)`.
118118
* You most likely have to bump the date like `hackageSnapshot = "2019-05-08T00:00:00Z";` to a newer date (past the time that package-version was added to Hackage).
119+
* Can I build Stack projects with resolvers that are too old to be supported by Stack >= 2?
120+
* No. For that you need need to use an old `static-haskell-nix` version: The one before [this PR](https://github.com/nh2/static-haskell-nix/pull/98) was merged.
119121
* I get some other error. Can I just file an issue and have you help me with it?
120122
* Yes. If possible (especially if your project is open source), please push some code so that your issue can be easily reproduced.

nixpkgs.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ if builtins.getEnv "STATIC_HASKELL_NIX_CI_NIXPKGS_UNSTABLE_BUILD" == "1"
2525
if builtins.pathExists ./nixpkgs/pkgs
2626
then import ./nixpkgs {}
2727
# Pinned nixpkgs version; should be kept up-to-date with our submodule.
28-
else import (fetchTarball https://github.com/NixOS/nixpkgs/archive/0c960262d159d3a884dadc3d4e4b131557dad116.tar.gz) {}
28+
else import (fetchTarball https://github.com/nh2/nixpkgs/archive/8d536f36256d30d8fa47b24caafb1af6405889f3.tar.gz) {}

static-stack/README.md

-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ If you get an error such as:
1818
1919
then update the `hackageSnapshot` date in `default.nix` to a date that includes the package and version.
2020

21-
### Temporarily: Use `stack-lts-12.yaml`
22-
23-
See #81: Stack's main `stack.yaml` uses GHC 8.2.2, which is no longer in recent `nixpkgs`.
24-
25-
If you get an error mentioning `error: attribute 'ghc822' in selection path 'haskell.compiler.ghc822' not found`, then build stack the same way [as our CI does it](https://github.com/nh2/static-haskell-nix/blob/38ef5a4e00b5f6fb421014829320d85899483874/.buildkite/pipeline.yml#L50-L64).
26-
27-
Alternatively you can use an older version of `static-haskell-nix` that pins an older version of `nixpkgs` that still has `ghc822`.
28-
29-
This issue will likely go away very soon given that [stack is as-of-writing upgrading `stack.yaml` to a newer LTS](https://github.com/commercialhaskell/stack/pull/5162).
30-
3121
## Binary caches for faster building (optional)
3222

3323
You can use the caches described in the [top-level README](../README.md#binary-caches-for-faster-building-optional) for faster building.

static-stack/default.nix

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
}:
1010
let
1111
cabalPackageName = "stack";
12-
compiler = "ghc844"; # matching stack-lts-12.yaml
12+
compiler = "ghc8104"; # matching stack-lts-12.yaml
1313

1414
pkgs = import ../nixpkgs {};
1515

1616
stack2nix-script = import ../static-stack2nix-builder/stack2nix-script.nix {
17-
pkgs = pkgs;
17+
inherit pkgs;
18+
inherit compiler;
1819
stack-project-dir = stackDir; # where stack.yaml is
19-
hackageSnapshot = "2020-02-08T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions
20+
hackageSnapshot = "2021-07-12T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions
2021
};
2122

2223
static-stack2nix-builder = import ../static-stack2nix-builder/default.nix {

static-stack2nix-builder-example/default.nix

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}:
77
let
88
cabalPackageName = "example-project";
9-
compiler = "ghc865"; # matching stack.yaml
9+
compiler = "ghc8104"; # matching stack.yaml
1010

1111
# Pin static-haskell-nix version.
1212
static-haskell-nix =
@@ -23,8 +23,9 @@ let
2323

2424
stack2nix-script = import "${static-haskell-nix}/static-stack2nix-builder/stack2nix-script.nix" {
2525
inherit pkgs;
26+
inherit compiler;
2627
stack-project-dir = toString ./.; # where stack.yaml is
27-
hackageSnapshot = "2019-10-08T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions
28+
hackageSnapshot = "2021-07-11T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions
2829
};
2930

3031
static-stack2nix-builder = import "${static-haskell-nix}/static-stack2nix-builder/default.nix" {
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
resolver: lts-14.7
1+
resolver: lts-18.2
22
packages:
33
- .

static-stack2nix-builder/default.nix

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
# The name of the cabal package to build, e.g. "pandoc".
66
cabalPackageName ? "myproject",
77

8-
# Compiler name in nixpkgs, e.g. "ghc864".
8+
# Compiler name in nixpkgs, e.g. "ghc8104".
99
# Must match the one in the `resolver` in `stack.yaml`.
1010
# If you get this wrong, you'll likely get an error like
1111
# <command line>: cannot satisfy -package-id Cabal-2.4.1.0-ALhzvdqe44A7vLWPOxSupv
1212
# TODO: Make `stack2nix` tell us that.
13-
compiler ? "ghc864",
13+
compiler ? "ghc8104",
1414

1515
# Path to `stack2nix` output that shall be used as Haskell packages.
1616
# You should usually give this the store path that `stack2nix-script` outputs.
1717
stack2nix-output-path,
1818

1919
# Pin nixpkgs version.
20-
normalPkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/88ae8f7d55efa457c95187011eb410d097108445.tar.gz) {},
20+
normalPkgs ? import (fetchTarball https://github.com/nh2/nixpkgs/archive/8d536f36256d30d8fa47b24caafb1af6405889f3.tar.gz) {},
2121

2222
# Use `integer-simple` instead of `integer-gmp` to avoid linking in
2323
# this LGPL dependency statically.

static-stack2nix-builder/stack2nix-script.nix

+19-28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
# nixpkgs to use.
88
pkgs,
99

10+
# ghc to use; only because without a GHC on path, stack complains:
11+
# stack2nix: No compiler found, expected minor version match with ghc-8.10.4 (x86_64) (based on resolver setting ...
12+
# This happens even when using the Stack API (as stack2nix does),
13+
# and stack2nix doen't currently accept or set the `--system-ghc`
14+
# flag to skip the check (maybe it should to eschew this option;
15+
# I suspect our operation here never uses GHC).
16+
# TODO: This shouldn't be necessary since `stack2nix` commit
17+
# Set `--system-ghc` via stack API.
18+
# But somehow stack2nix still complains about it;
19+
# perhaps we didn't use the Stack API correctly.
20+
compiler,
21+
1022
# Path to directory containing `stack.yaml`.
1123
stack-project-dir,
1224

@@ -47,37 +59,16 @@
4759
"${pkgs.cabal-install}/bin" # `cabal`
4860
"${pkgs.nix}/bin" # various `nix-*` commands
4961
"${pkgs.wget}/bin" # `wget`
62+
"${pkgs.haskell.compiler.${compiler}}/bin" # `ghc` version matching target stack.yaml
5063
];
5164

5265
fixed_stack2nix =
53-
let
54-
# stack2nix isn't compatible with Stack >= 2.0, see
55-
# https://github.com/input-output-hk/stack2nix/issues/168.
56-
# Current versions of nixpkgs master have Stack >= 2.0, see
57-
# https://github.com/NixOS/nixpkgs/issues/63691.
58-
# We thus fetch the `stack2nix` binary from an older nixpkgs version
59-
# that doesn't have Stack >= 2.0.
60-
# This means that `static-stack2nix-builder` may not work on `stack.yaml`
61-
# files that aren't compatible with Stack < 2.0.
62-
stack2nix_pkgs = import (fetchTarball https://github.com/NixOS/nixpkgs/archive/e36f91fa86109fa93cac2516a9365af57233a3a6.tar.gz) {};
63-
in
64-
# Some older stack2nix versions have fundamental problems that prevent
65-
# stack2nix from running correctly. Fix them here, until these old versions
66-
# are faded out of current nixpkgs. Especially:
67-
# * "Make sure output is written in UTF-8."
68-
# https://github.com/input-output-hk/stack2nix/commit/cb05818ef8b58899f15641f50cb04e5473b4f9b0
69-
# * "Make GHC base libraries dependent on GHC version."
70-
# https://github.com/input-output-hk/stack2nix/pull/172/commits
71-
#
72-
# Versions < 0.2.4 aren't supported, force-upgrade them to 0.2.4.
73-
if stack2nix_pkgs.lib.versionOlder stack2nix_pkgs.stack2nix.version "0.2.4"
74-
then stack2nix_pkgs.haskellPackages.callCabal2nix "stack2nix" (stack2nix_pkgs.fetchFromGitHub {
75-
owner = "nh2";
76-
repo = "stack2nix";
77-
rev = "c009e33af30c76b8fe94388382d816079fb5ac4e";
78-
sha256 = "0x0hjzjlx1a0pyjd8aalk3ajwcymsb2qd65n2sqdhpy9bdsz8vxl";
79-
}) {}
80-
else stack2nix_pkgs.stack2nix;
66+
pkgs.haskellPackages.callCabal2nix "stack2nix" (pkgs.fetchFromGitHub {
67+
owner = "nh2";
68+
repo = "stack2nix";
69+
rev = "c20097d4edf82256484a733544579d4b5e0f2808";
70+
sha256 = "1lpwc20q62z9a9fpksd9q10x1jz8l29psx4dqsff759srj4chy9p";
71+
}) {};
8172
in
8273
pkgs.writeShellScript "stack2nix-build-script.sh" ''
8374
set -eu -o pipefail

survey/default.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ let
10741074
# servant-server
10751075
# Some getting: *** abort because of serious configure-time warning from Cabal (multiple different package versions in project)
10761076
# stack2nix
1077-
Cabal =
1077+
Cabal = if !areCabalPatchesRequired then super.Cabal else # no patches needed -> don't even try to access any attributes
10781078
if approach == "pkgsMusl"
10791079
then ( # Example package where this matters: `focuslist`
10801080
# See note [When Cabal is `null` in a package set].

0 commit comments

Comments
 (0)