|
1 |
| -{ |
2 |
| - release ? false, |
3 |
| -}: |
4 | 1 | # Builds a static `stack` executable from a stack source dir.
|
5 | 2 | #
|
6 | 3 | # Usage:
|
7 | 4 | #
|
8 |
| -# $(nix-build --no-out-link -A stack2nix-script) /path/to/stack/source --stack-yaml stack-nightly.yaml && nix-build --no-out-link -A static_stack |
9 |
| -# |
10 |
| -# We do it this way instead of writing a derivation that |
11 |
| -# does that for you because as of writing, `stack2nix` doesn't support |
12 |
| -# being run from within a nix build, because it calls `cabal update`. |
| 5 | +# $(nix-build --no-link -A run-stack2nix-and-static-build-script --argstr stackDir /absolute/path/to/stack/source) |
| 6 | +{ |
| 7 | + stackDir ? "/absolute/path/to/stack/source", |
| 8 | +}: |
13 | 9 | let
|
14 |
| - pyopenssl-fix-test-buffer-size-overlay = final: previous: { |
15 |
| - python36 = previous.python36.override { |
16 |
| - packageOverrides = self: super: { |
17 |
| - cython = super.cython.overridePythonAttrs (old: rec { |
18 |
| - # TODO Cython tests for unknown reason hang with musl. Remove when that's fixed. |
19 |
| - # See https://github.com/nh2/static-haskell-nix/issues/6#issuecomment-421852854 |
20 |
| - doCheck = false; |
21 |
| - }); |
22 |
| - pyopenssl = super.pyopenssl.overridePythonAttrs (old: rec { |
23 |
| - patches = [ |
24 |
| - # TODO Remove when https://github.com/pyca/pyopenssl/commit/b2777a465b669fb647dbac0a92919cb05458707b is available in nixpkgs |
25 |
| - (final.fetchpatch { |
26 |
| - name = "wantWriteError-test-buffer-size.patch"; |
27 |
| - url = "https://github.com/pyca/pyopenssl/commit/b2777a465b669fb647dbac0a92919cb05458707b.patch"; |
28 |
| - sha256 = "0igksnl0cd5cx8f38bfjdriwdrzbw6ciy0hs805s84mprfwhck8d"; |
29 |
| - }) |
30 |
| - ]; |
31 |
| - }); |
32 |
| - }; |
33 |
| - }; |
34 |
| - }; |
35 |
| - |
36 |
| - normalPkgs = import (fetchTarball https://github.com/nh2/nixpkgs/archive/442912b4f19644311700b43b3b5247c6291d785a.tar.gz) {}; |
37 | 10 |
|
38 |
| - # In `survey` we provide a nixpkgs set with some fixes; import it here. |
39 |
| - pkgs = (import ../survey/default.nix { |
40 |
| - inherit normalPkgs; |
41 |
| - overlays = [ pyopenssl-fix-test-buffer-size-overlay ]; |
42 |
| - }).pkgs; |
| 11 | + upstreamNixpkgs = import ../nixpkgs {}; |
43 | 12 |
|
44 |
| - # TODO Use `pkgs.stack2nix` instead of this once `stack2nix` 0.2 is in `pkgs` |
45 |
| - stack2nix_src = pkgs.fetchFromGitHub { |
46 |
| - owner = "input-output-hk"; |
47 |
| - repo = "stack2nix"; |
48 |
| - rev = "v0.2.1"; |
49 |
| - sha256 = "1ihcp3mr0s89xmc81f9hxq07jw6pm3lixr5bdamqiin1skpk8q3b"; |
| 13 | + static-stack2nix-builder = import ../static-stack2nix-builder/default.nix { |
| 14 | + cabalPackageName = "stack"; |
| 15 | + normalPkgs = upstreamNixpkgs; |
| 16 | + compiler = "ghc822"; # matching stack.yaml |
| 17 | + hackageSnapshot = "2019-05-08T00:00:00Z"; # pins e.g. extra-deps without hashes or revisions |
| 18 | + stack2nix-stack-project-dir = stackDir; # where stack.yaml is |
| 19 | + # disableOptimization = true; # for compile speed |
50 | 20 | };
|
51 |
| - stack2nix = import (stack2nix_src + "/default.nix") {}; |
52 |
| - |
53 |
| - # Script that runs `stack2nix` on a given stack source dir. |
54 |
| - # Arguments given to the script are given to `stack2nix`. |
55 |
| - # Running the script creates file `stack.nix`. |
56 |
| - stack2nix-script = |
57 |
| - # `stack2nix` requires `cabal` on $PATH. |
58 |
| - # We put our nixpkgs's version of `nix` on $PATH for reproducibility. |
59 |
| - pkgs.writeScript "stack2nix-build-script.sh" '' |
60 |
| - #!/usr/bin/env bash |
61 |
| - set -eu -o pipefail |
62 |
| - PATH=${pkgs.cabal-install}/bin:${normalPkgs.nix}/bin:$PATH ${stack2nix}/bin/stack2nix -o stack.nix $@ |
63 |
| - ''; |
64 |
| - |
65 |
| - # Apply patch to generated stack2nix output to work around |
66 |
| - # 'libyaml' dependency to be named 'yaml'; see |
67 |
| - # https://github.com/NixOS/cabal2nix/issues/378 |
68 |
| - # Note this patch depends on |
69 |
| - # https://github.com/commercialhaskell/stack/blob/a2489de02/stack.yaml#L27 |
70 |
| - # which includes |
71 |
| - # https://github.com/snoyberg/yaml/pull/151/commits/ba216731cd5bf4264e9ad95d55616ff1a9edfac5 |
72 |
| - # This patch doesn't apply and can be removed if either |
73 |
| - # * the `stack` version to be compiled has `yaml` older than in the line mentioned above, or |
74 |
| - # * the `cabal2nix` version in use has https://github.com/NixOS/cabal2nix/commit/67e3189f fixed |
75 |
| - stack2nix-output = pkgs.runCommand "stack.nix-patched" {} '' |
76 |
| - cp ${./stack.nix} $out |
77 |
| - patch -p1 $out ${./stack-libyaml-dependency-name-cabal2nix-issue-378.patch} |
78 |
| - ''; |
79 | 21 |
|
80 |
| - enableCabalFlags = flags: drv: builtins.foldl' (d: flag: pkgs.haskell.lib.enableCabalFlag d flag) drv flags; |
81 |
| - setStackFlags = drv: |
82 |
| - if release |
83 |
| - then enableCabalFlags [ "hide-dependency-versions" "supported-build" ] drv |
84 |
| - else drv; |
85 |
| - # Builds a static stack executable from a `stack.nix` file generated |
86 |
| - # with `stack2nix`. |
87 |
| - static_stack = setStackFlags (import ../survey/default.nix { |
88 |
| - normalPkgs = pkgs; |
89 |
| - normalHaskellPackages = import stack2nix-output { |
90 |
| - inherit pkgs; |
91 |
| - }; |
92 |
| - }).haskellPackages.stack; |
93 |
| - # TODO check if `overrideCabal super.stack (old: { executableToolDepends = [ pkgs.git ]; })` |
94 |
| - # is necessary here now that it's removed from `survey` |
95 |
| - |
96 |
| - # Script that runs `nix-build` to build the final executable. |
97 |
| - # We do this to fix the version of `nix` to the one in our nixpkgs |
98 |
| - # for reproducibility, as changing nix versions can change the build env. |
99 |
| - # Arguments given to the script are given to `nix-build`. |
100 |
| - build-script = |
101 |
| - pkgs.writeScript "stack-build-script.sh" '' |
102 |
| - #!/usr/bin/env bash |
103 |
| - set -eu -o pipefail |
104 |
| - set -x |
105 |
| - ${normalPkgs.nix}/bin/nix-build --no-out-link -A static_stack $@ |
106 |
| - ''; |
107 |
| - |
108 |
| -in { |
109 |
| - inherit pkgs; |
110 |
| - inherit stack2nix-script; |
111 |
| - inherit static_stack; |
112 |
| - inherit build-script; |
113 |
| -} |
| 22 | +in |
| 23 | + static-stack2nix-builder // { |
| 24 | + static_package = |
| 25 | + with upstreamNixpkgs.haskell.lib; |
| 26 | + overrideCabal |
| 27 | + (appendConfigureFlags |
| 28 | + static-stack2nix-builder.static_package |
| 29 | + [ |
| 30 | + # Official release flags: |
| 31 | + "-fsupported-build" |
| 32 | + "-fhide-dependency-versions" |
| 33 | + "-f-disable-git-info" # stack2nix turns that on, we turn it off again |
| 34 | + ] |
| 35 | + ) |
| 36 | + (old: { |
| 37 | + # Enabling git info needs these extra deps. |
| 38 | + # TODO Make `stack2nix` accept per-package Cabal flags, |
| 39 | + # so that `cabal2nix` would automatically add |
| 40 | + # the right dependencies for us. |
| 41 | + executableHaskellDepends = (old.executableHaskellDepends or []) ++ |
| 42 | + (with static-stack2nix-builder.haskell-static-nix_output.haskellPackages; [ |
| 43 | + githash |
| 44 | + optparse-simple |
| 45 | + ]); |
| 46 | + # Put `git` on PATH, because `githash` calls it. |
| 47 | + preConfigure = '' |
| 48 | + export PATH=${upstreamNixpkgs.git}/bin:$PATH |
| 49 | + git --version |
| 50 | + ''; |
| 51 | + }); |
| 52 | + } |
0 commit comments