Skip to content

Commit 1b4bccb

Browse files
Remove flake utils (#2027)
* Remove flake-utils * WIP * Try to depend on pkgs rather than system * Use builtins * Try putting back internal as it was * Remove/update some comments * Better name for forEachSystem' * Minor changes * Remove extra nixpkgs in default.nix * Use flake-compat override-inputs to implement sourcesOverride This makes the overlays in compat internal the same as the ones in the flake. * Deprecate using overlaysOverrideable * Move internal.compat to default.nix * Adapt ci.nix * ghc945 -> ghc947 * Minor changes * Slightly more readable * Fix * Bump haskell.nix in nix-tools flake. This removes the transitive dependency on https://github.com/hamishmack/flake-utils which is not needed anymore. * Pre-fetch nixpkgs before calling flake-compat * Fix evalSystem in ci.nix * Avoid issues with restricted evaluation * Trivial change --------- Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@gmail.com>
1 parent e166d75 commit 1b4bccb

File tree

10 files changed

+326
-207
lines changed

10 files changed

+326
-207
lines changed

ci-lib.nix

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
{
2-
# Generic nixpkgs, use *only* for lib functions that are stable across versions
3-
pkgs,
4-
lib ? pkgs.lib
5-
}: rec {
1+
{ lib }:
2+
rec {
63
inherit (import ./dimension.nix) dimension;
74

85
# A filter for removing packages that aren't supported on the current platform

ci.nix

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
11
# 'supportedSystems' restricts the set of systems that we will evaluate for. Useful when you're evaluating
22
# on a machine with e.g. no way to build the Darwin IFDs you need!
33
{ ifdLevel ? 3
4-
# Whether or not we are evaluating in restricted mode. This is true in Hydra, but not in Hercules.
5-
, restrictEval ? false
64
, checkMaterialization ? false
7-
, compat
8-
, system
5+
, system ? builtins.currentSystem
96
, evalSystem ? builtins.currentSystem or "x86_64-linux"
10-
, pkgs ? (compat { inherit system; }).pkgs }:
7+
# NOTE: we apply checkMaterialization when defining nixpkgsArgs
8+
, haskellNix ? import ./default.nix { inherit system ; }
9+
}:
1110
let
12-
inherit (import ./ci-lib.nix { inherit pkgs; }) dimension platformFilterGeneric filterAttrsOnlyRecursive;
13-
inherit (pkgs.haskell-nix) sources;
11+
inherit (haskellNix) inputs;
12+
inherit (inputs.nixpkgs) lib;
13+
inherit
14+
(import ./ci-lib.nix { inherit lib; })
15+
dimension
16+
platformFilterGeneric
17+
filterAttrsOnlyRecursive;
18+
19+
# short names for nixpkgs versions
1420
nixpkgsVersions = {
15-
"R2205" = "nixpkgs-2205";
16-
"R2211" = "nixpkgs-2211";
17-
"R2305" = "nixpkgs-2305";
18-
"unstable" = "nixpkgs-unstable";
21+
"R2205" = inputs.nixpkgs-2205;
22+
"R2211" = inputs.nixpkgs-2211;
23+
"R2305" = inputs.nixpkgs-2305;
24+
"unstable" = inputs.nixpkgs-unstable;
1925
};
20-
haskellNix = compat { inherit checkMaterialization system; };
21-
nixpkgsArgs = haskellNix.nixpkgsArgs // {
26+
27+
nixpkgsArgs = {
28+
# set checkMaterialization as per top-level argument
29+
overlays = [
30+
haskellNix.overlay
31+
(final: prev: {
32+
haskell-nix = prev.haskell-nix // {
33+
inherit checkMaterialization;
34+
};
35+
})
36+
];
2237
# Needed for dwarf tests
23-
config = haskellNix.nixpkgsArgs.config // {
24-
permittedInsecurePackages = ["libdwarf-20210528" "libdwarf-20181024" "dwarfdump-20181024"];
38+
config = haskellNix.config // {
39+
permittedInsecurePackages = [
40+
"libdwarf-20210528"
41+
"libdwarf-20181024"
42+
"dwarfdump-20181024"
43+
];
2544
};
2645
};
46+
2747
compilerNixNames = nixpkgsName: nixpkgs:
2848
# Include only the GHC versions that are supported by haskell.nix
2949
nixpkgs.lib.filterAttrs (compiler-nix-name: _:
@@ -73,31 +93,30 @@
7393
# of 'lib.systems.examples' are not understood between all versions
7494
let lib = nixpkgs.lib;
7595
in lib.optionalAttrs (nixpkgsName == "unstable"
76-
&& ((system == "x86_64-linux" && __elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
77-
|| (system == "aarch64-linux" && __elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
78-
|| (system == "x86_64-darwin" && __elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
79-
|| (system == "aarch64-darwin" && __elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
96+
&& ((system == "x86_64-linux" && builtins.elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
97+
|| (system == "aarch64-linux" && builtins.elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
98+
|| (system == "x86_64-darwin" && builtins.elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
99+
|| (system == "aarch64-darwin" && builtins.elem compiler-nix-name ["ghc8107" "ghc962" "ghc9820230704"])
80100
)) {
81101
inherit (lib.systems.examples) ghcjs;
82102
} // lib.optionalAttrs (nixpkgsName == "unstable"
83-
&& ((system == "x86_64-linux" && __elem compiler-nix-name ["ghc8107" "ghc902" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" "ghc9820230704"])
84-
|| (system == "x86_64-darwin" && __elem compiler-nix-name []))) { # TODO add ghc versions when we have more darwin build capacity
103+
&& ((system == "x86_64-linux" && builtins.elem compiler-nix-name ["ghc8107" "ghc902" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" "ghc9820230704"])
104+
|| (system == "x86_64-darwin" && builtins.elem compiler-nix-name []))) { # TODO add ghc versions when we have more darwin build capacity
85105
inherit (lib.systems.examples) mingwW64;
86-
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && __elem compiler-nix-name ["ghc8107" "ghc902" "ghc922" "ghc923" "ghc924" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" "ghc9820230704"]) {
106+
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc8107" "ghc902" "ghc922" "ghc923" "ghc924" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" "ghc9820230704"]) {
87107
# Musl cross only works on linux
88108
# aarch64 cross only works on linux
89109
inherit (lib.systems.examples) musl64 aarch64-multiplatform;
90-
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && __elem compiler-nix-name ["ghc927" "ghc928"]) {
110+
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc927" "ghc928"]) {
91111
# TODO fix this for the compilers we build with hadrian (ghc >=9.4)
92112
inherit (lib.systems.examples) aarch64-multiplatform-musl;
93-
} // lib.optionalAttrs (system == "aarch64-linux" && nixpkgsName == "unstable" && __elem compiler-nix-name ["ghc927" "ghc928" "ghc947" "ghc962" "ghc9820230704"]) {
113+
} // lib.optionalAttrs (system == "aarch64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc927" "ghc928" "ghc947" "ghc962" "ghc9820230704"]) {
94114
inherit (lib.systems.examples) aarch64-multiplatform-musl;
95115
};
96116
isDisabled = d: d.meta.disabled or false;
97117
in
98-
dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: nixpkgs-pin:
99-
let pinnedNixpkgsSrc = sources.${nixpkgs-pin};
100-
evalPackages = import pinnedNixpkgsSrc (nixpkgsArgs // { system = evalSystem; });
118+
dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: pinnedNixpkgsSrc:
119+
let evalPackages = import pinnedNixpkgsSrc (nixpkgsArgs // { system = evalSystem; });
101120
in dimension "GHC version" (compilerNixNames nixpkgsName evalPackages) (compiler-nix-name: {runTests}:
102121
let pkgs = import pinnedNixpkgsSrc (nixpkgsArgs // { inherit system; });
103122
build = import ./build.nix { inherit pkgs evalPackages ifdLevel compiler-nix-name haskellNix; };

default.nix

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
1-
{...}@args:
1+
{ system ? builtins.currentSystem
2+
, sourcesOverride ? { }
3+
, checkMaterialization ? false
4+
, ...
5+
}:
26

37
let
4-
pins = (__fromJSON (__readFile ./flake.lock)).nodes;
5-
nixpkgsPin = pins.nixpkgs-2211.locked;
6-
flakeCompatPin = pins.flake-compat.locked;
7-
nixpkgsSrc =
8+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
9+
10+
# NOTE: This has to be whitelisted in restricted evaluation mode
11+
flake-compat =
12+
with lock.nodes.flake-compat.locked;
813
builtins.fetchTarball {
9-
url = "https://github.com/NixOS/nixpkgs/archive/${nixpkgsPin.rev}.tar.gz";
10-
sha256 = nixpkgsPin.narHash;
14+
url = "https://github.com/input-output-hk/flake-compat/archive/${rev}.tar.gz";
15+
sha256 = narHash;
1116
};
12-
pkgs = args.pkgs or (import nixpkgsSrc {});
13-
flake-compat =
14-
pkgs.fetchzip {
15-
url = "https://github.com/input-output-hk/flake-compat/archive/${flakeCompatPin.rev}.tar.gz";
16-
sha256 = flakeCompatPin.narHash;
17+
18+
# With flake-compat you will end up fetching the flake inputs with
19+
# builtins.fetchTarball. This is simply because you don't have access to any
20+
# nixpkgs before fetching the inputs.
21+
#
22+
# This won't work in restricted evaluation mode.
23+
#
24+
# Under the mild assumtion that https://github.com/NixOS is whitelisted, we
25+
# can manually fetch nixpkgs and let flake-compat fetch the rest of the
26+
# inputs with the nixpkgs just fetched.
27+
#
28+
# Manually fetch nixpkgs
29+
nixpkgs =
30+
with lock.nodes.nixpkgs.locked;
31+
builtins.fetchTarball {
32+
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
33+
sha256 = narHash;
1734
};
18-
self = import flake-compat {
35+
#
36+
# Instantiate the flake fetching the other inputs with the nixpkgs already
37+
# fetched
38+
self = (import flake-compat {
39+
pkgs = import nixpkgs { };
1940
# We bypass flake-compat's rootSrc cleaning by evading its detection of this as a git
2041
# repo.
2142
# This is done for 3 reasons:
@@ -26,7 +47,49 @@ let
2647
# in `test/default.nix`). If `flake-compat` copies the whole git repo, any change to the
2748
# repo causes a change of input for all tests.
2849
src = { outPath = ./.; };
29-
inherit pkgs;
50+
override-inputs = sourcesOverride;
51+
}).defaultNix;
52+
53+
inherit (self.inputs.nixpkgs) lib;
54+
55+
# coming from internal.compat
56+
overlays = [ self.overlay ]
57+
++ lib.optional checkMaterialization
58+
(final: prev: {
59+
haskell-nix = prev.haskell-nix // {
60+
checkMaterialization = true;
61+
};
62+
});
63+
nixpkgsArgs = {
64+
inherit overlays;
65+
inherit (self) config;
3066
};
31-
in self.defaultNix // (self.defaultNix.internal.compat
32-
({ system = args.pkgs.system or builtins.currentSystem; } // args))
67+
pkgs = import self.inputs.nixpkgs (nixpkgsArgs // {
68+
localSystem = { inherit system; };
69+
});
70+
in
71+
self // {
72+
inherit nixpkgsArgs pkgs;
73+
inherit (nixpkgsArgs) config overlays;
74+
sources = self.inputs;
75+
allOverlays = self.overlays;
76+
pkgs-2105 = import self.inputs.nixpkgs-2105 (nixpkgsArgs // {
77+
localSystem = { inherit system; };
78+
});
79+
pkgs-2111 = import self.inputs.nixpkgs-2111 (nixpkgsArgs // {
80+
localSystem = { inherit system; };
81+
});
82+
pkgs-2205 = import self.inputs.nixpkgs-2205 (nixpkgsArgs // {
83+
localSystem = { inherit system; };
84+
});
85+
pkgs-2211 = import self.inputs.nixpkgs-2211 (nixpkgsArgs // {
86+
localSystem = { inherit system; };
87+
});
88+
pkgs-2305 = import self.inputs.nixpkgs-2305 (nixpkgsArgs // {
89+
localSystem = { inherit system; };
90+
});
91+
pkgs-unstable = import self.inputs.nixpkgs-unstable (nixpkgsArgs // {
92+
localSystem = { inherit system; };
93+
});
94+
hix = import ./hix/default.nix { inherit pkgs; };
95+
}

flake.lock

Lines changed: 0 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)