blob: 01c98d6eed2f7cd62285cef398c98f21e03682aa (
plain) (
blame)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# nixos-config - My current NixOS configuration
#
# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This file is part of my nixos-config.
#
# You should have received a copy of the License along with this program.
# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
{
config,
lib,
pkgs,
modules,
modulesPath,
system,
specialArgs,
...
}: let
cfg = config.soispha.boot;
tailsPrefix = "EFI/tails";
in {
options.soispha.boot = {
enable = lib.mkEnableOption "Bootloader configuration";
enableIsoEntry = lib.mkEnableOption "an tails iso boot entry";
};
imports = [
modules.lanzaboote.nixosModules.lanzaboote
];
config = lib.mkIf cfg.enable {
# This should only be necessary for `lanzaboote`, but that is the current default in
# this module.
soispha.impermanence.directories = [
"/var/lib/sbctl"
"/boot"
];
fileSystems = {
# Emulate XBOOTLDR for lanzaboote (see: https://github.com/nix-community/lanzaboote/issues/173#issuecomment-1532386210)
"/efi/EFI/Linux" = {
device = "/boot/EFI/Linux";
options = ["bind"];
fsType = "btrfs";
};
"/efi/EFI/nixos" = {
device = "/boot/EFI/nixos";
options = ["bind"];
fsType = "btrfs";
};
"/efi/${tailsPrefix}" = lib.mkIf cfg.enableIsoEntry {
device = "/boot/${tailsPrefix}";
options = ["bind"];
fsType = "btrfs";
};
};
boot = {
initrd = {
kernelModules = ["nvme" "btrfs"];
};
kernelPackages = pkgs.linuxPackages_latest;
lanzaboote = {
enable = true;
pkiBundle = "/var/lib/sbctl";
settings = {
# Disable editing the kernel command line (which could allow someone to become root)
editor = false;
default = "@saved";
};
};
loader = {
external = lib.mkIf cfg.enableIsoEntry {
installHook = lib.mkForce (let
lanzabooteCfg = config.boot.lanzaboote;
lanzabooteInstallHook = import "${modulesPath}/../lib/eval-config.nix" {
inherit system specialArgs;
modules = [
modules.lanzaboote.nixosModules.lanzaboote
{
# Copy the relevant config into the eval-module context.
boot = {
inherit (config.boot) kernelPackages;
lanzaboote = {
inherit (lanzabooteCfg) enable pkiBundle;
settings = {
inherit (lanzabooteCfg.settings) editor default;
};
};
loader = {
inherit (config.boot.loader) timeout efi systemd-boot;
};
};
systemd.package = config.systemd.package;
}
];
};
install = pkgs.writeShellScript "wrapped-install-tails-iso-marker" ''
echo "[Wrapped bootloader install] Copying tails iso..."
${copyExtraFiles}
echo "[Wrapped bootloader install] Running original lanzaboote install..."
${lanzabooteInstallHook.config.boot.loader.external.installHook}
'';
copyExtraFiles = let
systemdCfg = config.boot.loader.systemd-boot;
nixosDir = "EFI/nixos";
bootMountPoint = config.boot.loader.efi.efiSysMountPoint;
install = lib.getExe' pkgs.coreutils "install";
inherit (lib) mapAttrsToList;
inherit (lib.strings) escapeShellArg concatStrings;
in
pkgs.writeShellScript "copy-extra-files" ''
${concatStrings (
mapAttrsToList (n: v: ''
${install} -Dp "${v}" "${bootMountPoint}/"${escapeShellArg n}
${install} -D /dev/null "${bootMountPoint}/${nixosDir}/.extra-files/"${escapeShellArg n}
'')
systemdCfg.extraFiles
)}
${concatStrings (
mapAttrsToList (n: v: ''
${install} -Dp "${pkgs.writeText n v}" "${bootMountPoint}/loader/entries/"${escapeShellArg n}
${install} -D /dev/null "${bootMountPoint}/${nixosDir}/.extra-files/loader/entries/"${escapeShellArg n}
'')
systemdCfg.extraEntries
)}
'';
in
install);
};
systemd-boot = lib.mkIf cfg.enableIsoEntry {
# Lanzaboote currently replaces the systemd-boot module.
enable = false;
extraEntries = {
"live.conf" = ''
title Tails Live ISO
linux /${tailsPrefix}/vmlinuz-linux
initrd /${tailsPrefix}/initramfs-linux.img
options img_dev=${config.soispha.disks.disk} img_loop=/${tailsPrefix}/tails.iso copytoram
'';
};
extraFiles = let
iso = import ./tails_iso.nix {inherit pkgs;};
in {
"/${tailsPrefix}/tails.iso" = "${iso}/tails.iso";
"/${tailsPrefix}/vmlinuz-linux" = "${iso}/live/vmlinuz-linux";
"/${tailsPrefix}/initramfs-linux.img" = "${iso}/live/initramfs-linux.img";
};
};
efi = {
canTouchEfiVariables = true;
efiSysMountPoint = "/efi";
};
};
};
};
}
|