Skip to content

Commit 7966716

Browse files
authored
nixos/{systemd-boot,installer}: replace substituteAll with replaceVarsWith (#377620)
2 parents 024545f + dc0e094 commit 7966716

File tree

2 files changed

+69
-67
lines changed

2 files changed

+69
-67
lines changed

nixos/modules/installer/tools/tools.nix

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{ config, lib, pkgs, ... }:
55

66
let
7-
makeProg = args: pkgs.substituteAll (args // {
7+
makeProg = args: pkgs.replaceVarsWith (args // {
88
dir = "bin";
99
isExecutable = true;
1010
nativeBuildInputs = [
@@ -18,28 +18,32 @@ let
1818
nixos-generate-config = makeProg {
1919
name = "nixos-generate-config";
2020
src = ./nixos-generate-config.pl;
21-
perl = "${pkgs.perl.withPackages (p: [ p.FileSlurp ])}/bin/perl";
22-
hostPlatformSystem = pkgs.stdenv.hostPlatform.system;
23-
detectvirt = "${config.systemd.package}/bin/systemd-detect-virt";
24-
btrfs = "${pkgs.btrfs-progs}/bin/btrfs";
25-
inherit (config.system.nixos-generate-config) configuration desktopConfiguration;
26-
xserverEnabled = config.services.xserver.enable;
21+
replacements = {
22+
perl = "${pkgs.perl.withPackages (p: [ p.FileSlurp ])}/bin/perl";
23+
hostPlatformSystem = pkgs.stdenv.hostPlatform.system;
24+
detectvirt = "${config.systemd.package}/bin/systemd-detect-virt";
25+
btrfs = "${pkgs.btrfs-progs}/bin/btrfs";
26+
inherit (config.system.nixos-generate-config) configuration desktopConfiguration;
27+
xserverEnabled = config.services.xserver.enable;
28+
};
2729
manPage = ./manpages/nixos-generate-config.8;
2830
};
2931

3032
nixos-version = makeProg {
3133
name = "nixos-version";
3234
src = ./nixos-version.sh;
33-
inherit (pkgs) runtimeShell;
34-
inherit (config.system.nixos) version codeName revision;
35-
inherit (config.system) configurationRevision;
36-
json = builtins.toJSON ({
37-
nixosVersion = config.system.nixos.version;
38-
} // lib.optionalAttrs (config.system.nixos.revision != null) {
39-
nixpkgsRevision = config.system.nixos.revision;
40-
} // lib.optionalAttrs (config.system.configurationRevision != null) {
41-
configurationRevision = config.system.configurationRevision;
42-
});
35+
replacements = {
36+
inherit (pkgs) runtimeShell;
37+
inherit (config.system.nixos) version codeName revision;
38+
inherit (config.system) configurationRevision;
39+
json = builtins.toJSON ({
40+
nixosVersion = config.system.nixos.version;
41+
} // lib.optionalAttrs (config.system.nixos.revision != null) {
42+
nixpkgsRevision = config.system.nixos.revision;
43+
} // lib.optionalAttrs (config.system.configurationRevision != null) {
44+
configurationRevision = config.system.configurationRevision;
45+
});
46+
};
4347
manPage = ./manpages/nixos-version.8;
4448
};
4549

nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let
3131

3232
edk2ShellEspPath = "efi/edk2-uefi-shell/shell.efi";
3333

34-
systemdBootBuilder = pkgs.substituteAll rec {
34+
systemdBootBuilder = pkgs.replaceVarsWith {
3535
name = "systemd-boot";
3636

3737
dir = "bin";
@@ -40,68 +40,66 @@ let
4040

4141
isExecutable = true;
4242

43-
inherit (builtins) storeDir;
43+
replacements = rec {
44+
inherit (builtins) storeDir;
4445

45-
inherit (pkgs) python3;
46+
inherit (pkgs) python3;
4647

47-
systemd = config.systemd.package;
48+
systemd = config.systemd.package;
4849

49-
bootspecTools = pkgs.bootspec;
50+
bootspecTools = pkgs.bootspec;
5051

51-
nix = config.nix.package.out;
52+
nix = config.nix.package.out;
5253

53-
timeout = if config.boot.loader.timeout == null then "menu-force" else config.boot.loader.timeout;
54+
timeout = if config.boot.loader.timeout == null then "menu-force" else config.boot.loader.timeout;
5455

55-
configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit;
56+
configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit;
5657

57-
inherit (cfg)
58-
consoleMode
59-
graceful
60-
editor
61-
rebootForBitlocker
62-
;
58+
inherit (cfg)
59+
consoleMode
60+
graceful
61+
editor
62+
rebootForBitlocker
63+
;
6364

64-
inherit (efi) efiSysMountPoint canTouchEfiVariables;
65+
inherit (efi) efiSysMountPoint canTouchEfiVariables;
6566

66-
bootMountPoint =
67-
if cfg.xbootldrMountPoint != null then cfg.xbootldrMountPoint else efi.efiSysMountPoint;
67+
bootMountPoint =
68+
if cfg.xbootldrMountPoint != null then cfg.xbootldrMountPoint else efi.efiSysMountPoint;
6869

69-
nixosDir = "/EFI/nixos";
70+
nixosDir = "/EFI/nixos";
7071

71-
inherit (config.system.nixos) distroName;
72+
inherit (config.system.nixos) distroName;
7273

73-
memtest86 = optionalString cfg.memtest86.enable pkgs.memtest86plus;
74-
75-
netbootxyz = optionalString cfg.netbootxyz.enable pkgs.netbootxyz-efi;
74+
checkMountpoints = pkgs.writeShellScript "check-mountpoints" ''
75+
fail() {
76+
echo "$1 = '$2' is not a mounted partition. Is the path configured correctly?" >&2
77+
exit 1
78+
}
79+
${pkgs.util-linuxMinimal}/bin/findmnt ${efiSysMountPoint} > /dev/null || fail efiSysMountPoint ${efiSysMountPoint}
80+
${lib.optionalString (cfg.xbootldrMountPoint != null)
81+
"${pkgs.util-linuxMinimal}/bin/findmnt ${cfg.xbootldrMountPoint} > /dev/null || fail xbootldrMountPoint ${cfg.xbootldrMountPoint}"
82+
}
83+
'';
7684

77-
checkMountpoints = pkgs.writeShellScript "check-mountpoints" ''
78-
fail() {
79-
echo "$1 = '$2' is not a mounted partition. Is the path configured correctly?" >&2
80-
exit 1
81-
}
82-
${pkgs.util-linuxMinimal}/bin/findmnt ${efiSysMountPoint} > /dev/null || fail efiSysMountPoint ${efiSysMountPoint}
83-
${lib.optionalString (cfg.xbootldrMountPoint != null)
84-
"${pkgs.util-linuxMinimal}/bin/findmnt ${cfg.xbootldrMountPoint} > /dev/null || fail xbootldrMountPoint ${cfg.xbootldrMountPoint}"
85-
}
86-
'';
87-
88-
copyExtraFiles = pkgs.writeShellScript "copy-extra-files" ''
89-
empty_file=$(${pkgs.coreutils}/bin/mktemp)
90-
91-
${concatStrings (
92-
mapAttrsToList (n: v: ''
93-
${pkgs.coreutils}/bin/install -Dp "${v}" "${bootMountPoint}/"${escapeShellArg n}
94-
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/"${escapeShellArg n}
95-
'') cfg.extraFiles
96-
)}
97-
98-
${concatStrings (
99-
mapAttrsToList (n: v: ''
100-
${pkgs.coreutils}/bin/install -Dp "${pkgs.writeText n v}" "${bootMountPoint}/loader/entries/"${escapeShellArg n}
101-
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/loader/entries/"${escapeShellArg n}
102-
'') cfg.extraEntries
103-
)}
104-
'';
85+
copyExtraFiles = pkgs.writeShellScript "copy-extra-files" ''
86+
empty_file=$(${pkgs.coreutils}/bin/mktemp)
87+
88+
${concatStrings (
89+
mapAttrsToList (n: v: ''
90+
${pkgs.coreutils}/bin/install -Dp "${v}" "${bootMountPoint}/"${escapeShellArg n}
91+
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/"${escapeShellArg n}
92+
'') cfg.extraFiles
93+
)}
94+
95+
${concatStrings (
96+
mapAttrsToList (n: v: ''
97+
${pkgs.coreutils}/bin/install -Dp "${pkgs.writeText n v}" "${bootMountPoint}/loader/entries/"${escapeShellArg n}
98+
${pkgs.coreutils}/bin/install -D $empty_file "${bootMountPoint}/${nixosDir}/.extra-files/loader/entries/"${escapeShellArg n}
99+
'') cfg.extraEntries
100+
)}
101+
'';
102+
};
105103
};
106104

107105
finalSystemdBootBuilder = pkgs.writeScript "install-systemd-boot.sh" ''

0 commit comments

Comments
 (0)