Skip to content

Commit 77d8200

Browse files
authored
Add support for static nix-tools (#2157)
* Add support for static build of nix-tools * Add default-setup and default-setup-ghcjs to nix-tools * Update cabal to 3.10.3 * Use nix-tools.exes.cabal when possible
1 parent f986076 commit 77d8200

File tree

1,180 files changed

+887
-98986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,180 files changed

+887
-98986
lines changed
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Wait for Hydra Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "nix-tools-*"
9+
pull_request:
10+
11+
env:
12+
FLAKE_REF: github:${{ github.repository }}?ref=${{ github.head_ref || github.ref }}
13+
GH_TOKEN: ${{ github.token }}
14+
15+
jobs:
16+
wait-for-hydra:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Install Nix with good defaults
24+
uses: input-output-hk/install-nix-action@v20
25+
with:
26+
extra_nix_config: |
27+
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= loony-tools:pr9m4BkM/5/eSTZlkQyRt57Jz7OMBxNSUiMC4FkcNfk=
28+
substituters = https://cache.nixos.org/ https://cache.iog.io/ https://cache.zw3rk.com
29+
nix_path: nixpkgs=channel:nixos-unstable
30+
31+
- name: Display flake metadata
32+
id: flake-metadata
33+
run: |
34+
echo $PWD
35+
ls -lah .
36+
nix flake metadata ${{ env.FLAKE_REF }}
37+
nix flake metadata ${{ env.FLAKE_REF }} --json | jq -r '"LOCKED_URL=\(.url)"' >> "$GITHUB_OUTPUT"
38+
39+
- name: Wait for nix-tools meta job
40+
uses: input-output-hk/actions/wait-for-hydra@angerman/support-prs
41+
with:
42+
status: 'ci/hydra-build:nix-tools'
43+
44+
- name: "Pull nix-tools"
45+
run: |
46+
ls -lah .
47+
cp $(nix build --builders "" --max-jobs 0 ${{ steps.flake-metadata.outputs.LOCKED_URL }}#hydraJobs.aarch64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd --no-link --print-out-paths)/*.zip .
48+
cp $(nix build --builders "" --max-jobs 0 ${{ steps.flake-metadata.outputs.LOCKED_URL }}#hydraJobs.x86_64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd --no-link --print-out-paths)/*.zip .
49+
cp $(nix build --builders "" --max-jobs 0 ${{ steps.flake-metadata.outputs.LOCKED_URL }}#hydraJobs.x86_64-linux.nix-tools.static.zipped.nix-tools-static-no-ifd --no-link --print-out-paths)/*.zip .
50+
cp $(nix build --builders "" --max-jobs 0 ${{ steps.flake-metadata.outputs.LOCKED_URL }}#hydraJobs.x86_64-linux.nix-tools.static.zipped.nix-tools-static-arm64-no-ifd --no-link --print-out-paths)/*.zip .
51+
52+
- name: Configure Git
53+
if: startsWith(github.ref, 'refs/tags/')
54+
run: |
55+
git config --global user.name 'Auto Update Bot'
56+
git config --global user.email '[email protected]'
57+
58+
- name: "Compute nix-tools-static.nix"
59+
if: startsWith(github.ref, 'refs/tags/')
60+
run: |
61+
git fetch --all
62+
git switch --force static-nix-tools
63+
(
64+
echo "pkgs: let baseurl = \"https://github.com/input-output-hk/haskell.nix/releases/download/${GITHUB_REF_NAME}/\"; in {"
65+
for arch in aarch64-darwin x86_64-darwin aarch64-linux x86_64-linux; do
66+
echo " ${arch} = pkgs.fetchurl { "
67+
echo " name = \"${arch}-nix-tools-static\";"
68+
echo " url = \"\${baseurl}${arch}-nix-tools-static.zip\";"
69+
echo " sha256 = \"$(nix-hash --sri --type sha256 --flat ${arch}-nix-tools-static.zip)\";"
70+
echo " };"
71+
done
72+
echo "}"
73+
) > nix-tools-static.nix
74+
cat nix-tools-static.nix
75+
76+
77+
- name: Push to nix branch
78+
if: startsWith(github.ref, 'refs/tags/')
79+
run: |
80+
git add nix-tools-static.nix
81+
git commit -m "update nix-tools-static.nix"
82+
git push origin static-nix-tools
83+
84+
- name: Release
85+
uses: input-output-hk/action-gh-release@v1
86+
if: startsWith(github.ref, 'refs/tags/')
87+
with:
88+
files: |
89+
*-nix-tools-static.zip

build.nix

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ in rec {
2626

2727
tools = pkgs.lib.optionalAttrs (ifdLevel >= 3) (
2828
pkgs.recurseIntoAttrs ({
29-
cabal-latest = tool compiler-nix-name "cabal" { inherit evalPackages; cabalProjectLocal = builtins.readFile ./test/cabal.project.local; };
29+
cabal-latest = tool compiler-nix-name "cabal" { inherit evalPackages; };
3030
} // pkgs.lib.optionalAttrs (__compareVersions haskell.compiler.${compiler-nix-name}.version "9.8" < 0) {
3131
hlint-latest = tool compiler-nix-name "hlint" {
3232
inherit evalPackages;
@@ -91,11 +91,7 @@ in rec {
9191
};
9292
check-hydra = pkgs.buildPackages.callPackage ./scripts/check-hydra.nix {};
9393
check-closure-size = pkgs.buildPackages.callPackage ./scripts/check-closure-size.nix {
94-
# Includes cabal-install since this is commonly used.
95-
nix-tools = pkgs.linkFarm "common-tools" [
96-
{ name = "nix-tools"; path = haskell.nix-tools; }
97-
{ name = "cabal-install"; path = haskell.cabal-install.${compiler-nix-name}; }
98-
];
94+
nix-tools = haskell.nix-tools-unchecked; # includes cabal-install and default-setup
9995
};
10096
check-materialization-concurrency = pkgs.buildPackages.callPackage ./scripts/check-materialization-concurrency/check.nix {};
10197
check-path-support = pkgsForGitHubAction.buildPackages.callPackage ./scripts/check-path-support.nix {
@@ -114,7 +110,7 @@ in rec {
114110
# Some of the dependencies of the impure scripts so that they will
115111
# will be in the cache too for buildkite.
116112
inherit (pkgs.buildPackages) glibc coreutils git openssh cabal-install nix-prefetch-git;
117-
inherit (haskell) nix-tools;
113+
nix-tools = pkgs.haskell-nix.nix-tools-unchecked;
118114
})
119115
);
120116
}

builder/comp-builder.nix

+8-4
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ let
110110

111111
ghc = (if enableDWARF then (x: x.dwarf) else (x: x)) (
112112
(if smallAddressSpace then (x: x.smallAddressSpace) else (x: x)) defaults.ghc);
113-
setup = (if enableDWARF then (x: x.dwarf) else (x: x)) (
114-
(if smallAddressSpace then (x: x.smallAddressSpace) else (x: x)) drvArgs.setup);
113+
setup = (if enableDWARF then (x: x.dwarf or x) else (x: x)) (
114+
(if smallAddressSpace then (x: x.smallAddressSpace or x) else (x: x)) drvArgs.setup);
115115

116116
# TODO fix cabal wildcard support so hpack wildcards can be mapped to cabal wildcards
117117
canCleanSource = !(cabal-generator == "hpack" && !(package.cleanHpack or false));
@@ -285,7 +285,7 @@ let
285285

286286
enableParallelBuilding = true;
287287

288-
SETUP_HS = setup + /bin/Setup;
288+
SETUP_HS = setup + "/bin/${setup.exeName}";
289289

290290
inherit cabalFile;
291291
passAsFile = [ "cabalFile" ];
@@ -635,7 +635,11 @@ let
635635
''))
636636
+ (lib.optionalString doCoverage ''
637637
mkdir -p $out/share
638-
cp -r dist/${lib.optionalString (builtins.compareVersions defaults.ghc.version "9.9" >= 0) "build/extra-compilation-artifacts/"}hpc $out/share
638+
if [ -d dist/build/extra-compilation-artifacts ]; then
639+
cp -r dist/build/extra-compilation-artifacts/hpc $out/share
640+
else
641+
cp -r dist/hpc $out/share
642+
fi
639643
cp dist/setup-config $out/
640644
'')
641645
}

builder/hspkg-builder.nix

+5-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ let
3535

3636
setup = if package.buildType == "Simple"
3737
then
38-
# Don't try to build default setup with DWARF enabled
39-
let defaultSetup = ghc.defaultSetupFor package.identifier.name // {
40-
dwarf = defaultSetup;
41-
}; in defaultSetup
38+
if stdenv.targetPlatform.isGhcjs # TODO probably should be hostPlatform, but only HsColour used to build ghc will change (updating will require rebuilding all the ghcjs versions)
39+
then
40+
buildPackages.haskell-nix.nix-tools-unchecked.exes.default-setup-ghcjs // { exeName = "default-setup-ghcjs"; }
41+
else
42+
buildPackages.haskell-nix.nix-tools-unchecked.exes.default-setup // { exeName = "default-setup"; }
4243
else setup-builder ({
4344
component = components.setup // {
4445
depends = config.setup-depends ++ components.setup.depends ++ package.setup-depends;

builder/setup-builder.nix

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ let
7777
cleanSrc = cleanSrc';
7878
dwarf = self (drvArgs // { enableDWARF = true; });
7979
smallAddressSpace = self (drvArgs // { smallAddressSpace = true; });
80+
exeName = "Setup";
8081
};
8182

8283
meta = {

flake.lock

+8-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+18-10
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
url = "github:input-output-hk/stackage.nix";
4040
flake = false;
4141
};
42-
nix-tools-static = {
43-
url = "github:input-output-hk/haskell-nix-example/nix";
44-
flake = false;
45-
};
4642
cabal-32 = {
4743
url = "github:haskell/cabal/3.2";
4844
flake = false;
@@ -135,7 +131,7 @@
135131
stripAttrsForHydra
136132
filterDerivations;
137133

138-
in traceHydraJobs ({
134+
flake = {
139135
inherit config;
140136
overlay = self.overlays.combined;
141137
overlays = import ./overlays { sources = inputs; };
@@ -250,10 +246,6 @@
250246
inherit system;
251247
pkgs = self.legacyPackages.${system};
252248
src = ./nix-tools;
253-
override-inputs = {
254-
# Avoid downloading another `hackage.nix`.
255-
inherit (inputs) hackage;
256-
};
257249
};
258250
in cf.defaultNix.hydraJobs;
259251
in
@@ -290,7 +282,23 @@
290282
"ghc901"
291283
"ghc921" "ghc922" "ghc923"])
292284
);
293-
});
285+
}; in with (import nixpkgs { system = "x86_64-linux"; });
286+
traceHydraJobs (lib.recursiveUpdate flake {
287+
hydraJobs.nix-tools = pkgs.releaseTools.aggregate {
288+
name = "nix-tools";
289+
constituents = [
290+
"aarch64-darwin.nix-tools.static.zipped.nix-tools-static"
291+
"x86_64-darwin.nix-tools.static.zipped.nix-tools-static"
292+
"x86_64-linux.nix-tools.static.zipped.nix-tools-static"
293+
"x86_64-linux.nix-tools.static.zipped.nix-tools-static-arm64"
294+
"aarch64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd"
295+
"x86_64-darwin.nix-tools.static.zipped.nix-tools-static-no-ifd"
296+
"x86_64-linux.nix-tools.static.zipped.nix-tools-static-no-ifd"
297+
"x86_64-linux.nix-tools.static.zipped.nix-tools-static-arm64-no-ifd"
298+
(writeText "gitrev" (self.rev or "0000000000000000000000000000000000000000"))
299+
];
300+
};
301+
});
294302

295303
# --- Flake Local Nix Configuration ----------------------------
296304
nixConfig = {

lib/cabal-project-parser.nix

+6-6
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ let
128128
# This works because `cabal configure` does not include any of the `/nix/sore/`
129129
# paths in the `plan.json` (so materialized plan-nix will still work as expeced).
130130
# See tests/unit.nix for examples of input and output.
131-
parseRepositoryBlock = evalPackages: _cabalProjectFileName: sha256map: inputMap: cabal-install: nix-tools: block:
131+
parseRepositoryBlock = evalPackages: _cabalProjectFileName: sha256map: inputMap: nix-tools: block:
132132
let
133133
lines = pkgs.lib.splitString "\n" block;
134134
# The first line will contain the repository name.
@@ -151,7 +151,7 @@ let
151151
repoContents = if inputMap ? ${attrs.url}
152152
# If there is an input use it to make `file:` url and create a suitable `.cabal/packages/${name}` directory
153153
then evalPackages.runCommand name ({
154-
nativeBuildInputs = [ cabal-install ] ++ evalPackages.haskell-nix.cabal-issue-8352-workaround;
154+
nativeBuildInputs = [ nix-tools.exes.cabal ] ++ evalPackages.haskell-nix.cabal-issue-8352-workaround;
155155
preferLocalBuild = true;
156156
}) ''
157157
HOME=$(mktemp -d)
@@ -167,7 +167,7 @@ let
167167
cp -r $HOME/.cabal/packages/${name} $out
168168
''
169169
else evalPackages.runCommand name ({
170-
nativeBuildInputs = [ cabal-install evalPackages.curl nix-tools ] ++ evalPackages.haskell-nix.cabal-issue-8352-workaround;
170+
nativeBuildInputs = [ nix-tools.exes.cabal evalPackages.curl ] ++ evalPackages.haskell-nix.cabal-issue-8352-workaround;
171171
LOCALE_ARCHIVE = pkgs.lib.optionalString (evalPackages.stdenv.buildPlatform.libc == "glibc") "${evalPackages.glibcLocales}/lib/locale/locale-archive";
172172
LANG = "en_US.UTF-8";
173173
preferLocalBuild = true;
@@ -192,7 +192,7 @@ let
192192
# Output of hackage-to-nix
193193
hackage = import (
194194
evalPackages.runCommand ("hackage-to-nix-" + name) {
195-
nativeBuildInputs = [ cabal-install evalPackages.curl nix-tools ];
195+
nativeBuildInputs = [ nix-tools.exes.hackage-to-nix ];
196196
LOCALE_ARCHIVE = pkgs.lib.optionalString (evalPackages.stdenv.buildPlatform.libc == "glibc") "${evalPackages.glibcLocales}/lib/locale/locale-archive";
197197
LANG = "en_US.UTF-8";
198198
preferLocalBuild = true;
@@ -204,11 +204,11 @@ let
204204
repo.${name} = repoContents;
205205
};
206206

207-
parseRepositories = evalPackages: cabalProjectFileName: sha256map: inputMap: cabal-install: nix-tools: projectFile:
207+
parseRepositories = evalPackages: cabalProjectFileName: sha256map: inputMap: nix-tools: projectFile:
208208
let
209209
# This will leave the name of repository in the first line of each block
210210
blocks = pkgs.lib.splitString "\nrepository " ("\n" + projectFile);
211-
repoBlocks = builtins.map (parseRepositoryBlock evalPackages cabalProjectFileName sha256map inputMap cabal-install nix-tools) (pkgs.lib.lists.drop 1 blocks);
211+
repoBlocks = builtins.map (parseRepositoryBlock evalPackages cabalProjectFileName sha256map inputMap nix-tools) (pkgs.lib.lists.drop 1 blocks);
212212
in {
213213
extra-hackages = pkgs.lib.lists.map (block: block.hackage) repoBlocks;
214214
repos = pkgs.lib.lists.foldl' (x: block: x // block.repo) {} repoBlocks;

lib/call-cabal-project-to-nix.nix

+3-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ let
7070
# These defaults are here rather than in modules/cabal-project.nix to make them
7171
# lazy enough to avoid infinite recursion issues.
7272
# Using null as the default also improves performance as they are not forced by the
73-
# nix module system for `nix-tools-unchecked` and `cabal-install-unchecked`.
73+
# nix module system for `nix-tools-unchecked`.
7474
nix-tools = if args.nix-tools or null != null
7575
then args.nix-tools
7676
else evalPackages.haskell-nix.nix-tools-unchecked;
77-
cabal-install = nix-tools.exes.cabal;
7877
forName = pkgs.lib.optionalString (name != null) (" for " + name);
7978
nameAndSuffix = suffix: if name == null then suffix else name + "-" + suffix;
8079

@@ -262,7 +261,7 @@ let
262261

263262
# Parse the `repository` blocks
264263
repoResult = pkgs.haskell-nix.haskellLib.parseRepositories
265-
evalPackages cabalProjectFileName sha256map inputMap cabal-install nix-tools sourceRepoFixedProjectFile;
264+
evalPackages cabalProjectFileName sha256map inputMap nix-tools sourceRepoFixedProjectFile;
266265
in {
267266
sourceRepos = sourceReposBuild;
268267
inherit (repoResult) repos extra-hackages;
@@ -451,7 +450,7 @@ let
451450
# some packages that will be excluded by `index-state-max`
452451
# which is used by cabal (cached-index-state >= index-state-max).
453452
dotCabal {
454-
inherit cabal-install nix-tools extra-hackage-tarballs;
453+
inherit nix-tools extra-hackage-tarballs;
455454
extra-hackage-repos = fixedProject.repos;
456455
index-state = cached-index-state;
457456
sha256 = index-sha256-found;

0 commit comments

Comments
 (0)