Skip to content

Commit 1f34534

Browse files
Systemd tpm fixes (#343307)
2 parents 68324b7 + a0165bd commit 1f34534

File tree

5 files changed

+84
-19
lines changed

5 files changed

+84
-19
lines changed

nixos/modules/module-list.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,7 @@
16411641
./system/boot/systemd/sysupdate.nix
16421642
./system/boot/systemd/sysusers.nix
16431643
./system/boot/systemd/tmpfiles.nix
1644+
./system/boot/systemd/tpm2.nix
16441645
./system/boot/systemd/user.nix
16451646
./system/boot/systemd/userdbd.nix
16461647
./system/boot/systemd/homed.nix

nixos/modules/system/boot/luksroot.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,8 @@ in
10881088
storePaths = [
10891089
"${config.boot.initrd.systemd.package}/bin/systemd-cryptsetup"
10901090
"${config.boot.initrd.systemd.package}/lib/systemd/system-generators/systemd-cryptsetup-generator"
1091+
] ++ lib.optionals config.boot.initrd.systemd.tpm2.enable [
1092+
"${config.boot.initrd.systemd.package}/lib/cryptsetup/libcryptsetup-token-systemd-tpm2.so"
10911093
];
10921094

10931095
};

nixos/modules/system/boot/systemd.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ let
3737
"cryptsetup.target"
3838
"cryptsetup-pre.target"
3939
"remote-cryptsetup.target"
40-
] ++ optionals cfg.package.withTpm2Tss [
41-
"tpm2.target"
4240
] ++ [
4341
"sigpwr.target"
4442
"timers.target"

nixos/modules/system/boot/systemd/initrd.nix

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ let
6868
"systemd-reboot.service"
6969
"systemd-sysctl.service"
7070
"timers.target"
71-
"tpm2.target"
7271
"umount.target"
7372
"systemd-bsod.service"
7473
] ++ cfg.additionalUpstreamUnits;
@@ -349,15 +348,6 @@ in {
349348
visible = "shallow";
350349
description = "Definition of slice configurations.";
351350
};
352-
353-
enableTpm2 = mkOption {
354-
default = cfg.package.withTpm2Tss;
355-
defaultText = "boot.initrd.systemd.package.withTpm2Tss";
356-
type = types.bool;
357-
description = ''
358-
Whether to enable TPM2 support in the initrd.
359-
'';
360-
};
361351
};
362352

363353
config = mkIf (config.boot.initrd.enable && cfg.enable) {
@@ -394,9 +384,7 @@ in {
394384
# systemd needs this for some features
395385
"autofs"
396386
# systemd-cryptenroll
397-
] ++ lib.optional cfg.enableTpm2 "tpm-tis"
398-
++ lib.optional (cfg.enableTpm2 && !(pkgs.stdenv.hostPlatform.isRiscV64 || pkgs.stdenv.hostPlatform.isArmv7)) "tpm-crb"
399-
++ lib.optional cfg.package.withEfi "efivarfs";
387+
] ++ lib.optional cfg.package.withEfi "efivarfs";
400388

401389
boot.kernelParams = [
402390
"root=${config.boot.initrd.systemd.root}"
@@ -495,10 +483,6 @@ in {
495483

496484
# so NSS can look up usernames
497485
"${pkgs.glibc}/lib/libnss_files.so.2"
498-
] ++ optionals (cfg.package.withCryptsetup && cfg.enableTpm2) [
499-
# tpm2 support
500-
"${cfg.package}/lib/cryptsetup/libcryptsetup-token-systemd-tpm2.so"
501-
pkgs.tpm2-tss
502486
] ++ optionals cfg.package.withCryptsetup [
503487
# fido2 support
504488
"${cfg.package}/lib/cryptsetup/libcryptsetup-token-systemd-fido2.so"
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
lib,
3+
config,
4+
pkgs,
5+
...
6+
}:
7+
{
8+
meta.maintainers = [ lib.maintainers.elvishjerricco ];
9+
10+
imports = [
11+
(lib.mkRenamedOptionModule
12+
[
13+
"boot"
14+
"initrd"
15+
"systemd"
16+
"enableTpm2"
17+
]
18+
[
19+
"boot"
20+
"initrd"
21+
"systemd"
22+
"tpm2"
23+
"enable"
24+
]
25+
)
26+
];
27+
28+
options = {
29+
systemd.tpm2.enable = lib.mkEnableOption "systemd TPM2 support" // {
30+
default = config.systemd.package.withTpm2Tss;
31+
defaultText = "systemd.package.withTpm2Tss";
32+
};
33+
34+
boot.initrd.systemd.tpm2.enable = lib.mkEnableOption "systemd initrd TPM2 support" // {
35+
default = config.boot.initrd.systemd.package.withTpm2Tss;
36+
defaultText = "boot.initrd.systemd.package.withTpm2Tss";
37+
};
38+
};
39+
40+
# TODO: pcrphase, pcrextend, pcrfs, pcrmachine
41+
config = lib.mkMerge [
42+
# Stage 2
43+
(
44+
let
45+
cfg = config.systemd;
46+
in
47+
lib.mkIf cfg.tpm2.enable {
48+
systemd.additionalUpstreamSystemUnits = [
49+
"tpm2.target"
50+
"systemd-tpm2-setup-early.service"
51+
"systemd-tpm2-setup.service"
52+
];
53+
}
54+
)
55+
56+
# Stage 1
57+
(
58+
let
59+
cfg = config.boot.initrd.systemd;
60+
in
61+
lib.mkIf cfg.tpm2.enable {
62+
boot.initrd.systemd.additionalUpstreamUnits = [
63+
"tpm2.target"
64+
"systemd-tpm2-setup-early.service"
65+
];
66+
67+
boot.initrd.availableKernelModules =
68+
[ "tpm-tis" ]
69+
++ lib.optional (
70+
!(pkgs.stdenv.hostPlatform.isRiscV64 || pkgs.stdenv.hostPlatform.isArmv7)
71+
) "tpm-crb";
72+
boot.initrd.systemd.storePaths = [
73+
pkgs.tpm2-tss
74+
"${cfg.package}/lib/systemd/systemd-tpm2-setup"
75+
"${cfg.package}/lib/systemd/system-generators/systemd-tpm2-generator"
76+
];
77+
}
78+
)
79+
];
80+
}

0 commit comments

Comments
 (0)