Skip to content

Commit 69fde53

Browse files
committed
Clean up packaging a bit
- Multiple choices of stdenv are handled more consistently, especially for the dev shells which were previously not done correctly. - Some stray nix code was moving into the `packaging` directory
1 parent 43a170a commit 69fde53

File tree

6 files changed

+48
-57
lines changed

6 files changed

+48
-57
lines changed

flake.nix

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,7 @@
6666

6767
forAllCrossSystems = lib.genAttrs crossSystems;
6868

69-
forAllStdenvs = f:
70-
lib.listToAttrs
71-
(map
72-
(stdenvName: {
73-
name = "${stdenvName}Packages";
74-
value = f stdenvName;
75-
})
76-
stdenvs);
69+
forAllStdenvs = lib.genAttrs stdenvs;
7770

7871

7972
# We don't apply flake-parts to the whole flake so that non-development attributes
@@ -89,32 +82,29 @@
8982
# Memoize nixpkgs for different platforms for efficiency.
9083
nixpkgsFor = forAllSystems
9184
(system: let
92-
make-pkgs = crossSystem: stdenv: import nixpkgs {
93-
localSystem = {
94-
inherit system;
95-
};
96-
crossSystem = if crossSystem == null then null else {
97-
config = crossSystem;
98-
} // lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") {
99-
useLLVM = true;
100-
};
101-
overlays = [
102-
(overlayFor (p: p.${stdenv}))
103-
];
104-
};
105-
stdenvs = forAllStdenvs (make-pkgs null);
106-
native = stdenvs.stdenvPackages;
107-
in {
108-
inherit stdenvs native;
109-
static = native.pkgsStatic;
110-
llvm = native.pkgsLLVM;
111-
cross = forAllCrossSystems (crossSystem: make-pkgs crossSystem "stdenv");
85+
make-pkgs = crossSystem:
86+
forAllStdenvs (stdenv: import nixpkgs {
87+
localSystem = {
88+
inherit system;
89+
};
90+
crossSystem = if crossSystem == null then null else {
91+
config = crossSystem;
92+
} // lib.optionalAttrs (crossSystem == "x86_64-unknown-freebsd13") {
93+
useLLVM = true;
94+
};
95+
overlays = [
96+
(overlayFor (pkgs: pkgs.${stdenv}))
97+
];
98+
});
99+
in rec {
100+
nativeForStdenv = make-pkgs null;
101+
crossForStdenv = forAllCrossSystems make-pkgs;
102+
# Alias for convenience
103+
native = nativeForStdenv.stdenv;
104+
cross = forAllCrossSystems (crossSystem:
105+
crossForStdenv.${crossSystem}.stdenv);
112106
});
113107

114-
binaryTarball = nix: pkgs: pkgs.callPackage ./scripts/binary-tarball.nix {
115-
inherit nix;
116-
};
117-
118108
overlayFor = getStdenv: final: prev:
119109
let
120110
stdenv = getStdenv final;
@@ -175,7 +165,6 @@
175165
hydraJobs = import ./packaging/hydra.nix {
176166
inherit
177167
inputs
178-
binaryTarball
179168
forAllCrossSystems
180169
forAllSystems
181170
lib
@@ -211,7 +200,7 @@
211200
# TODO: enable static builds for darwin, blocked on:
212201
# https://github.com/NixOS/nixpkgs/issues/320448
213202
# TODO: disabled to speed up GHA CI.
214-
#"static-" = nixpkgsFor.${system}.static;
203+
#"static-" = nixpkgsFor.${system}.native.pkgsStatic;
215204
})
216205
(nixpkgsPrefix: nixpkgs:
217206
flatMapAttrs nixpkgs.nixComponents
@@ -282,16 +271,16 @@
282271
(pkgName: { supportsCross ? true }: {
283272
# These attributes go right into `packages.<system>`.
284273
"${pkgName}" = nixpkgsFor.${system}.native.nixComponents.${pkgName};
285-
"${pkgName}-static" = nixpkgsFor.${system}.static.nixComponents.${pkgName};
286-
"${pkgName}-llvm" = nixpkgsFor.${system}.llvm.nixComponents.${pkgName};
274+
"${pkgName}-static" = nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName};
275+
"${pkgName}-llvm" = nixpkgsFor.${system}.native.pkgsLLVM.nixComponents.${pkgName};
287276
}
288277
// lib.optionalAttrs supportsCross (flatMapAttrs (lib.genAttrs crossSystems (_: { })) (crossSystem: {}: {
289278
# These attributes go right into `packages.<system>`.
290279
"${pkgName}-${crossSystem}" = nixpkgsFor.${system}.cross.${crossSystem}.nixComponents.${pkgName};
291280
}))
292281
// flatMapAttrs (lib.genAttrs stdenvs (_: { })) (stdenvName: {}: {
293282
# These attributes go right into `packages.<system>`.
294-
"${pkgName}-${stdenvName}" = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".nixComponents.${pkgName};
283+
"${pkgName}-${stdenvName}" = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.nixComponents.${pkgName};
295284
})
296285
)
297286
// lib.optionalAttrs (builtins.elem system linux64BitSystems) {
@@ -317,21 +306,22 @@
317306
in
318307
forAllSystems (system:
319308
prefixAttrs "native" (forAllStdenvs (stdenvName: makeShell {
320-
pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages";
309+
pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName};
321310
})) //
322311
lib.optionalAttrs (!nixpkgsFor.${system}.native.stdenv.isDarwin) (
323312
prefixAttrs "static" (forAllStdenvs (stdenvName: makeShell {
324-
pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".pkgsStatic;
313+
pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsStatic;
325314
})) //
326315
prefixAttrs "llvm" (forAllStdenvs (stdenvName: makeShell {
327-
pkgs = nixpkgsFor.${system}.stdenvs."${stdenvName}Packages".pkgsLLVM;
316+
pkgs = nixpkgsFor.${system}.nativeForStdenv.${stdenvName}.pkgsLLVM;
328317
})) //
329318
prefixAttrs "cross" (forAllCrossSystems (crossSystem: makeShell {
330319
pkgs = nixpkgsFor.${system}.cross.${crossSystem};
331320
}))
332321
) //
333322
{
334-
default = self.devShells.${system}.native-stdenvPackages;
323+
native = self.devShells.${system}.native-stdenv;
324+
default = self.devShells.${system}.native;
335325
}
336326
);
337327
};
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ in
2222

2323
runCommand "nix-binary-tarball-${version}" env ''
2424
cp ${installerClosureInfo}/registration $TMPDIR/reginfo
25-
cp ${./create-darwin-volume.sh} $TMPDIR/create-darwin-volume.sh
26-
substitute ${./install-nix-from-tarball.sh} $TMPDIR/install \
25+
cp ${../scripts/create-darwin-volume.sh} $TMPDIR/create-darwin-volume.sh
26+
substitute ${../scripts/install-nix-from-tarball.sh} $TMPDIR/install \
2727
--subst-var-by nix ${nix} \
2828
--subst-var-by cacert ${cacert}
2929
30-
substitute ${./install-darwin-multi-user.sh} $TMPDIR/install-darwin-multi-user.sh \
30+
substitute ${../scripts/install-darwin-multi-user.sh} $TMPDIR/install-darwin-multi-user.sh \
3131
--subst-var-by nix ${nix} \
3232
--subst-var-by cacert ${cacert}
33-
substitute ${./install-systemd-multi-user.sh} $TMPDIR/install-systemd-multi-user.sh \
33+
substitute ${../scripts/install-systemd-multi-user.sh} $TMPDIR/install-systemd-multi-user.sh \
3434
--subst-var-by nix ${nix} \
3535
--subst-var-by cacert ${cacert}
36-
substitute ${./install-multi-user.sh} $TMPDIR/install-multi-user \
36+
substitute ${../scripts/install-multi-user.sh} $TMPDIR/install-multi-user \
3737
--subst-var-by nix ${nix} \
3838
--subst-var-by cacert ${cacert}
3939

packaging/hydra.nix

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{ inputs
2-
, binaryTarball
32
, forAllCrossSystems
43
, forAllSystems
54
, lib
@@ -12,7 +11,7 @@ let
1211
inherit (inputs) nixpkgs nixpkgs-regression;
1312

1413
installScriptFor = tarballs:
15-
nixpkgsFor.x86_64-linux.native.callPackage ../scripts/installer.nix {
14+
nixpkgsFor.x86_64-linux.native.callPackage ./installer {
1615
inherit tarballs;
1716
};
1817

@@ -62,7 +61,7 @@ in
6261
[ "i686-linux" ];
6362

6463
buildStatic = forAllPackages (pkgName:
65-
lib.genAttrs linux64BitSystems (system: nixpkgsFor.${system}.static.nixComponents.${pkgName}));
64+
lib.genAttrs linux64BitSystems (system: nixpkgsFor.${system}.native.pkgsStatic.nixComponents.${pkgName}));
6665

6766
buildCross = forAllPackages (pkgName:
6867
# Hack to avoid non-evaling package
@@ -99,13 +98,12 @@ in
9998
# Binary tarball for various platforms, containing a Nix store
10099
# with the closure of 'nix' package, and the second half of
101100
# the installation script.
102-
binaryTarball = forAllSystems (system: binaryTarball nixpkgsFor.${system}.native.nix nixpkgsFor.${system}.native);
101+
binaryTarball = forAllSystems (system:
102+
nixpkgsFor.${system}.native.callPackage ./binary-tarball.nix {});
103103

104104
binaryTarballCross = lib.genAttrs [ "x86_64-linux" ] (system:
105105
forAllCrossSystems (crossSystem:
106-
binaryTarball
107-
nixpkgsFor.${system}.cross.${crossSystem}.nix
108-
nixpkgsFor.${system}.cross.${crossSystem}));
106+
nixpkgsFor.${system}.cross.${crossSystem}.callPackage ./binary-tarball.nix {}));
109107

110108
# The first half of the installation script. This is uploaded
111109
# to https://nixos.org/nix/install. It downloads the binary
@@ -124,7 +122,7 @@ in
124122
self.hydraJobs.binaryTarballCross."x86_64-linux"."riscv64-unknown-linux-gnu"
125123
];
126124

127-
installerScriptForGHA = forAllSystems (system: nixpkgsFor.${system}.native.callPackage ../scripts/installer.nix {
125+
installerScriptForGHA = forAllSystems (system: nixpkgsFor.${system}.native.callPackage ./installer {
128126
tarballs = [ self.hydraJobs.binaryTarball.${system} ];
129127
});
130128

@@ -147,7 +145,10 @@ in
147145
external-api-docs = nixpkgsFor.x86_64-linux.native.nixComponents.nix-external-api-docs;
148146

149147
# System tests.
150-
tests = import ../tests/nixos { inherit lib nixpkgs nixpkgsFor self; } // {
148+
tests = import ../tests/nixos {
149+
inherit lib nixpkgs nixpkgsFor;
150+
inherit (self.inputs) nixpkgs-23-11;
151+
} // {
151152

152153
# Make sure that nix-env still produces the exact same result
153154
# on a particular version of Nixpkgs.

tests/nixos/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, nixpkgs, nixpkgsFor, self }:
1+
{ lib, nixpkgs, nixpkgsFor, nixpkgs-23-11 }:
22

33
let
44

@@ -64,7 +64,7 @@ let
6464
otherNixes.nix_2_13.setNixPackage = { lib, pkgs, ... }: {
6565
imports = [ checkOverrideNixVersion ];
6666
nix.package = lib.mkForce (
67-
self.inputs.nixpkgs-23-11.legacyPackages.${pkgs.stdenv.hostPlatform.system}.nixVersions.nix_2_13.overrideAttrs (o: {
67+
nixpkgs-23-11.legacyPackages.${pkgs.stdenv.hostPlatform.system}.nixVersions.nix_2_13.overrideAttrs (o: {
6868
meta = o.meta // { knownVulnerabilities = []; };
6969
})
7070
);

0 commit comments

Comments
 (0)