From 2f55cdb11dea0508177403e134f1e7036e867a51 Mon Sep 17 00:00:00 2001 From: Thibault Polge Date: Mon, 4 Sep 2023 14:12:24 +0200 Subject: [PATCH] nixos/systemd-boot: Add reboot-for-bitlocker support Windows with BitLocker and TPM enabled doesn't support boot chaining. This option activates a special experimental mode in systemd-boot that tries to detect such systems and, if detected and selected by the user at the boot menu, set the BootNext EFI variable to it before resetting. (cherry picked from commit a68b81c429734e19699f4b7ca61beb986c24b151) --- .../systemd-boot/systemd-boot-builder.py | 3 +++ .../boot/loader/systemd-boot/systemd-boot.nix | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py index 03bff1dee5b9..bf5ad74fc09c 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py @@ -28,6 +28,7 @@ DISTRO_NAME = "@distroName@" NIX = "@nix@" SYSTEMD = "@systemd@" CONFIGURATION_LIMIT = int("@configurationLimit@") +REBOOT_FOR_BITLOCKER = bool("@rebootForBitlocker@") CAN_TOUCH_EFI_VARIABLES = "@canTouchEfiVariables@" GRACEFUL = "@graceful@" COPY_EXTRA_FILES = "@copyExtraFiles@" @@ -99,6 +100,8 @@ def write_loader_conf(profile: str | None, generation: int, specialisation: str f.write("default %s\n" % generation_conf_filename(profile, generation, specialisation)) if not EDITOR: f.write("editor 0\n") + if REBOOT_FOR_BITLOCKER: + f.write("reboot-for-bitlocker yes\n"); f.write(f"console-mode {CONSOLE_MODE}\n") f.flush() os.fsync(f.fileno()) diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix index cee8663f0040..f66501431df2 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix @@ -38,7 +38,7 @@ let configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit; - inherit (cfg) consoleMode graceful editor; + inherit (cfg) consoleMode graceful editor rebootForBitlocker; inherit (efi) efiSysMountPoint canTouchEfiVariables; @@ -317,6 +317,22 @@ in { ''; }; + rebootForBitlocker = mkOption { + default = false; + + type = types.bool; + + description = '' + Enable *EXPERIMENTAL* BitLocker support. + + Try to detect BitLocker encrypted drives along with an active + TPM. If both are found and Windows Boot Manager is selected in + the boot menu, set the "BootNext" EFI variable and restart the + system. The firmware will then start Windows Boot Manager + directly, leaving the TPM PCRs in expected states so that + Windows can unseal the encryption key. + ''; + }; }; config = mkIf cfg.enable {