This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnixos-module.nix
101 lines (88 loc) · 3.08 KB
/
nixos-module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{ pkgs, lib, config, ... }:
let
inherit (lib) types;
in
{
options = {
boot.loader.secureboot = {
enable = lib.mkEnableOption "Secure Boot support";
signingKeyPath = lib.mkOption {
type = types.nullOr types.str;
default = null;
};
signingCertPath = lib.mkOption {
type = types.nullOr types.str;
default = null;
};
};
};
config = {
boot.loader.external = {
enable = true;
installHook = pkgs.writeShellScript "install-bootloader"
(
let
generatorArgs = lib.escapeShellArgs ([
"--systemd-machine-id-setup"
"${config.systemd.package}/bin/systemd-machine-id-setup"
]
++ (lib.optionals config.boot.loader.secureboot.enable [
"--unified-efi"
"--objcopy"
"${pkgs.binutils-unwrapped}/bin/objcopy"
"--systemd-efi-stub"
"${config.systemd.package}/lib/systemd/boot/efi/linuxx64.efi.stub"
]));
installerArgs = lib.escapeShellArgs
([
"--esp"
config.boot.loader.efi.efiSysMountPoint
"--console-mode"
config.boot.loader.systemd-boot.consoleMode
"--timeout"
(toString config.boot.loader.timeout)
"--bootctl"
"${config.systemd.package}/bin/bootctl"
"--generated-entries"
"./systemd-boot-entries"
]
++ (lib.optional config.boot.loader.efi.canTouchEfiVariables "--can-touch-efi-vars")
++ (lib.optionals (config.boot.loader.systemd-boot.configurationLimit != null) [
"--configuration-limit"
"${toString config.boot.loader.systemd-boot.configurationLimit}"
])
++ (lib.optionals (config.boot.loader.secureboot.signingKeyPath != null) [
"--signing-key"
config.boot.loader.secureboot.signingKeyPath
])
++ (lib.optionals (config.boot.loader.secureboot.signingCertPath != null) [
"--signing-cert"
config.boot.loader.secureboot.signingCertPath
])
++ (lib.optionals config.boot.loader.secureboot.enable [
"--unified-efi"
"--sbsign"
"${pkgs.sbsigntool}/bin/sbsign"
"--sbverify"
"${pkgs.sbsigntool}/bin/sbverify"
]));
in
''
set -eux
scratch=$(mktemp -d -t tmp.XXXXXXXXXX)
function finish {
rm -rf "$scratch"
}
trap finish EXIT
cd "$scratch" || exit 1
${pkgs.bootspec-secureboot}/bin/generator /nix/var/nix/profiles/system-*-link \
${generatorArgs}
${pkgs.bootspec-secureboot}/bin/installer \
--toplevel="$1" \
$([ ! -z ''${NIXOS_INSTALL_BOOTLOADER+x} ] && echo --install) \
${installerArgs}
''
);
};
};
}