From ecf5f784dc2dddb2bba7e0ac75e73cc44e2e6b99 Mon Sep 17 00:00:00 2001 From: Rudolf Tucek Date: Mon, 30 Nov 2026 01:36:52 +0100 Subject: [PATCH 1/4] dell-xps9360-nixos-btw: enable secure boot with Lanzaboote --- flake.lock | 99 +++++++++++++++++++++ flake.nix | 5 ++ hosts/dell-xps9360-nixos-btw/default.nix | 1 + hosts/dell-xps9360-nixos-btw/secureboot.nix | 22 +++++ 4 files changed, 127 insertions(+) create mode 100644 hosts/dell-xps9360-nixos-btw/secureboot.nix diff --git a/flake.lock b/flake.lock index 349bd14..95a3b21 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "crane": { + "locked": { + "lastModified": 1789760033, + "narHash": "sha256-jtT4yxZpR8seYnlCMMWSSPlFN92zO6ICuZ8pJrmi86k=", + "owner": "ipetkov", + "repo": "crane", + "rev": "73b980519cefc727a5f6cc8e5c0947a2f9be6edd", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, "disko": { "inputs": { "nixpkgs": [ @@ -21,6 +36,22 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -81,6 +112,30 @@ "type": "github" } }, + "lanzaboote": { + "inputs": { + "crane": "crane", + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit": "pre-commit", + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1790423250, + "narHash": "sha256-sr4Kfp6yaXUeyKL6n0Y8/ElcR3momIRC20HFc+LF22s=", + "owner": "nix-community", + "repo": "lanzaboote", + "rev": "c1c5edd31802d181c8aa2c71588995d93425d650", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "v1.2.0", + "repo": "lanzaboote", + "type": "github" + } + }, "nixos-hardware": { "inputs": { "nixpkgs": [ @@ -169,17 +224,61 @@ "type": "github" } }, + "pre-commit": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "lanzaboote", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1789514889, + "narHash": "sha256-PFD1nxptCXJyJoiYO1gf/5Vv43yqGpHtMC6LUhl9/pQ=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "59f4ca0d063a1a3ec722c88b51a33004862e5379", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "disko": "disko", "flake-parts": "flake-parts", "home-manager": "home-manager", + "lanzaboote": "lanzaboote", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs", "nixvim": "nixvim", "sops-nix": "sops-nix" } }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "lanzaboote", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1789889921, + "narHash": "sha256-aL/ogiN7qZCGeNovS1f9hX73jwYIKb4Pcq6AZm57WtY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1fb104a12a8667045559b2575d6d448ae2fbd99b", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, "sops-nix": { "inputs": { "nixpkgs": [ diff --git a/flake.nix b/flake.nix index 5883693..5d33e68 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,11 @@ url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + + lanzaboote = { + url = "github:nix-community/lanzaboote/v1.2.0"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = diff --git a/hosts/dell-xps9360-nixos-btw/default.nix b/hosts/dell-xps9360-nixos-btw/default.nix index 1129fb2..a90a902 100644 --- a/hosts/dell-xps9360-nixos-btw/default.nix +++ b/hosts/dell-xps9360-nixos-btw/default.nix @@ -5,6 +5,7 @@ inputs.nixos-hardware.nixosModules.dell-xps-13-9360 ../../modules ./sops.nix + ./secureboot.nix ]; networking.hostName = "dell-xps9360-nixos-btw"; diff --git a/hosts/dell-xps9360-nixos-btw/secureboot.nix b/hosts/dell-xps9360-nixos-btw/secureboot.nix new file mode 100644 index 0000000..c151e1b --- /dev/null +++ b/hosts/dell-xps9360-nixos-btw/secureboot.nix @@ -0,0 +1,22 @@ +{ + inputs, + pkgs, + lib, + ... +}: +{ + imports = [ + inputs.lanzaboote.nixosModules.lanzaboote + ]; + + environment.systemPackages = [ + pkgs.sbctl + ]; + + boot.loader.systemd-boot.enable = lib.mkForce false; + + boot.lanzaboote = { + enable = true; + pkiBundle = "/var/lib/sbctl"; + }; +} From 02f20bac4f71e17655c6c1652817972370cfb498 Mon Sep 17 00:00:00 2001 From: Rudolf Tucek Date: Mon, 30 Nov 2026 01:36:52 +0100 Subject: [PATCH 2/4] secure-boot: refactor to a nix module --- hosts/dell-xps9360-nixos-btw/default.nix | 3 +- hosts/dell-xps9360-nixos-btw/secureboot.nix | 22 ------------- modules/users/rtucek/default.nix | 1 + modules/users/rtucek/secureboot.nix | 34 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 23 deletions(-) delete mode 100644 hosts/dell-xps9360-nixos-btw/secureboot.nix create mode 100644 modules/users/rtucek/secureboot.nix diff --git a/hosts/dell-xps9360-nixos-btw/default.nix b/hosts/dell-xps9360-nixos-btw/default.nix index a90a902..1b72913 100644 --- a/hosts/dell-xps9360-nixos-btw/default.nix +++ b/hosts/dell-xps9360-nixos-btw/default.nix @@ -5,7 +5,6 @@ inputs.nixos-hardware.nixosModules.dell-xps-13-9360 ../../modules ./sops.nix - ./secureboot.nix ]; networking.hostName = "dell-xps9360-nixos-btw"; @@ -30,6 +29,8 @@ ai.claude-code.enable = true; + boot.secureboot.enable = true; + virtualisation = { docker.enable = true; podman.enable = true; diff --git a/hosts/dell-xps9360-nixos-btw/secureboot.nix b/hosts/dell-xps9360-nixos-btw/secureboot.nix deleted file mode 100644 index c151e1b..0000000 --- a/hosts/dell-xps9360-nixos-btw/secureboot.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ - inputs, - pkgs, - lib, - ... -}: -{ - imports = [ - inputs.lanzaboote.nixosModules.lanzaboote - ]; - - environment.systemPackages = [ - pkgs.sbctl - ]; - - boot.loader.systemd-boot.enable = lib.mkForce false; - - boot.lanzaboote = { - enable = true; - pkiBundle = "/var/lib/sbctl"; - }; -} diff --git a/modules/users/rtucek/default.nix b/modules/users/rtucek/default.nix index 2724dd1..7d991b3 100644 --- a/modules/users/rtucek/default.nix +++ b/modules/users/rtucek/default.nix @@ -6,6 +6,7 @@ ./git.nix ./home.nix ./hyprland.nix + ./secureboot.nix ./tmuxinator.nix ./user.nix ./virtualisation.nix diff --git a/modules/users/rtucek/secureboot.nix b/modules/users/rtucek/secureboot.nix new file mode 100644 index 0000000..418250a --- /dev/null +++ b/modules/users/rtucek/secureboot.nix @@ -0,0 +1,34 @@ +{ + config, + lib, + pkgs, + inputs, + ... +}: +let + cfg = config.rtucek.boot.secureboot; +in +{ + imports = [ + inputs.lanzaboote.nixosModules.lanzaboote + ]; + + options.rtucek.boot.secureboot = { + enable = lib.options.mkEnableOption "Secure Boot via Lanzaboote"; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ + pkgs.sbctl + ]; + + # Lanzaboote will replace systemd-boot, hence systemd-boot has to be forcefully disabled. + # As such, it will override what we configure as a sensible default in `system/core/boot.nix`. + boot.loader.systemd-boot.enable = lib.mkForce false; + + boot.lanzaboote = { + enable = true; + pkiBundle = "/var/lib/sbctl"; + }; + }; +} From b764429814c6a1320e92ab5cefe3eca65faf8eed Mon Sep 17 00:00:00 2001 From: Rudolf Tucek Date: Mon, 30 Nov 2026 01:36:53 +0100 Subject: [PATCH 3/4] readme: document secure boot setup --- README.md | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/README.md b/README.md index 8c57e22..227c17f 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,146 @@ During the installation, `hosts/tux-ibp-amdgen9-nixos-btw/hardware-configuration rewritten, based on the detected hardware. Don't forget to commit the updated file! +### Enable Secure Boot + +The flake has support for Secure Boot via [Lanzaboote](https://github.com/nix-community/lanzaboote). + +The following steps are derived from [Lanzaboote's manual](https://nix-community.github.io/lanzaboote/introduction.html) +and subsections. + + +#### Prerequisites + +Secure Boot requires NixOS to be installed in UEFI mode (not legacy BIOS) and `systemd-boot` to be +used as the boot loader. + +These prerequisites can be checked via `bootctl status`: + +``` +$ bootctl status +System: + Firmware: UEFI 2.40 (American Megatrends 5.11) + Secure Boot: disabled (disabled) + TPM2 Support: yes + Boot into FW: supported + +Current Boot Loader: + Product: systemd-boot 260.5 +... +``` + +In the `bootctl` output, the firmware needs to be `UEFI` and the current boot loader needs to be +`systemd-boot`. + +#### System preparation + +First, create the keys, which will be enrolled: + +```bash +# Unless already present, install sbctl. Note that `sudo` won't see packages +# installed into your own shell's `PATH`, so generate the keys through the +# same `nix-shell` invocation instead of a separate `sudo sbctl ...` call: +sudo nix-shell -p sbctl --run "sbctl create-keys" +``` + +Then, enable Secure Boot for the host in question. + +```diff +diff --git a/hosts/dell-xps9360-nixos-btw/default.nix b/hosts/dell-xps9360-nixos-btw/default.nix +index a90a902..1b72913 100644 +--- a/hosts/dell-xps9360-nixos-btw/default.nix ++++ b/hosts/dell-xps9360-nixos-btw/default.nix +@@ -30,6 +29,8 @@ + + ai.claude-code.enable = true; + ++ boot.secureboot.enable = true; ++ + virtualisation = { + docker.enable = true; + podman.enable = true; +``` + +Then, rebuild the system with `nixos-rebuild switch`: + +```bash +nixos-rebuild switch --flake . --sudo +``` + +Finally, verify that your machine is ready to have Secure Boot activated: + +``` +$ sudo sbctl verify +Verifying file database and EFI images in /boot... +✓ /boot/EFI/BOOT/BOOTX64.EFI is signed +✓ /boot/EFI/Linux/nixos-generation-34-2jmnpsirjequvi2dbljik3xtbnqztk7m2gyaac43z3ypsx2vwyaa.efi is signed +✓ /boot/EFI/Linux/nixos-generation-35-xyg7hzxdcrrife23cnk4fyiwemy2lfzbsg6grdct47zgfxwz666a.efi is signed +✓ /boot/EFI/Linux/nixos-generation-36-nitlhcuad5svld25r62myqwpaapjptysjm35ahcn5d2talpgwwsq.efi is signed +✓ /boot/EFI/Linux/nixos-generation-37-tch4qkd3ohb5ibbwn6mismuk42l6hcea7h2vtm3ngna34iy5z5ua.efi is signed +✓ /boot/EFI/Linux/nixos-generation-38-2wt3sto427436gacwsye5t3dscu6vmuk7wkqg4wvfg5wm4by732a.efi is signed +✓ /boot/EFI/Linux/nixos-generation-39-f2ul6j7fdirt34nfufdeof2hf53srwyygnmpydjkpgebxkppdcha.efi is signed +✗ /boot/EFI/nixos/kernel-7.3-vuo5a7ruui4lqe3pwwbusyfxitkpukuv2bpxdrk2bf4u4lcgf4pa.efi is not signed +✗ /boot/EFI/nixos/kernel-7.3.3-hrbpymjqaigqn4prjafojemdr6xnhcrh5su7mapqjjzlz33vidbq.efi is not signed +✗ /boot/EFI/nixos/kernel-7.3.5-pwtmghyal4oh3esr3cgbsztittf732hswwzvapi7am2x2itbzumq.efi is not signed +✗ /boot/EFI/nixos/kernel-7.3.6-rb7lvtbwetvcsqhgnusau7u3n4vewcy52n7uoa7dzxexq2vcbnha.efi is not signed +✓ /boot/EFI/systemd/systemd-bootx64.efi is signed +``` + +It is expected that the files starting with `kernel-` are not signed. +Only proceed with the Secure Boot activation if the check above passes! + + +#### Activate Secure Boot + +Enable Secure Boot by booting into the machine's BIOS menu. Typically, this involves pressing F2, +F8, F10 or F12 during the early boot process, such as the initial splash screen. + +Essentially, it comes down to the following 3 items: + +- enable the Secure Boot option +- enter Setup Mode +- if necessary, delete PK, KEK and DB keys. + DO NOT(!) delete the DBX keys. This represents the "Forbidden Signature Database". + +The exact steps to enter Setup Mode vary significantly by vendor. On some ThinkPads, you select +"Reset to Setup Mode" explicitly; on Framework laptops, you delete each PK/KEK/DB entry +individually (never "Erase all Secure Boot Settings"); on Microsoft Surface devices, simply +disabling Secure Boot already puts the firmware into Setup Mode. + +See [Lanzaboote's vendor-specific +instructions](https://nix-community.github.io/lanzaboote/getting-started/enable-secure-boot.html) +for steps matching your hardware. + +Once enabled and booted back into the system, enroll the keys: + +``` +$ sudo sbctl enroll-keys --microsoft +Enrolling keys to EFI variables... +With vendor keys from microsoft...✓ +Enrolled keys to the EFI variables! +``` + +Since `--microsoft` was used, double-check afterwards that the Secure Boot Forbidden Signature +Database (dbx) isn't empty, e.g. by checking the file size of `/sys/firmware/efi/efivars/dbx-*`. An +empty dbx weakens protection against revoked, Microsoft-signed bootkits. + +Reboot once more and verify that Secure Boot is active: + +``` +System: + Firmware: UEFI 2.40 (American Megatrends 5.11) + Firmware Arch: x64 + Secure Boot: enabled (user) + TPM2 Support: yes + Measured UKI: yes + Boot into FW: supported + +Current Boot Loader: + Product: systemd-boot 260.5 +... +``` + + ## FAQ The section below addresses the most frequently asked questions. From 861fb5e0582562d454c51407f39baefbef8662a3 Mon Sep 17 00:00:00 2001 From: Rudolf Tucek Date: Tue, 1 Dec 2026 23:07:17 +0100 Subject: [PATCH 4/4] readme: fix formatting --- README.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 227c17f..bde6068 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ For security reasons, each host is expected to have its own dedicated key, locat In order to generate a new key, run: -```sh +```bash age-keygen -pq ``` @@ -60,7 +60,7 @@ Store the output in a temporary file. Create a dedicated SOPS file for encrypting the host key. The general convention is to locate the host key in `./secrets/hosts/${HOSTNAME}.yaml`. -``` +```bash # Create the file via sops edit ./secrets/hosts/tux-ibp-amdgen9-nixos-btw.yaml ``` @@ -108,7 +108,7 @@ creation_rules: Finally, re-encrypt all secrets with the new key by running: -```sh +```bash find secrets -name '*.yaml' -type f -print0 | xargs -0 -l sops updatekeys --yes ``` @@ -242,13 +242,15 @@ used as the boot loader. These prerequisites can be checked via `bootctl status`: -``` +```console $ bootctl status System: - Firmware: UEFI 2.40 (American Megatrends 5.11) - Secure Boot: disabled (disabled) - TPM2 Support: yes - Boot into FW: supported + Firmware: UEFI 2.40 (American Megatrends 5.11) + Firmware Arch: x64 + Secure Boot: disabled (disabled) + TPM2 Support: yes + Measured UKI: no + Boot into FW: supported Current Boot Loader: Product: systemd-boot 260.5 @@ -295,7 +297,7 @@ nixos-rebuild switch --flake . --sudo Finally, verify that your machine is ready to have Secure Boot activated: -``` +```console $ sudo sbctl verify Verifying file database and EFI images in /boot... ✓ /boot/EFI/BOOT/BOOTX64.EFI is signed @@ -339,7 +341,7 @@ for steps matching your hardware. Once enabled and booted back into the system, enroll the keys: -``` +```console $ sudo sbctl enroll-keys --microsoft Enrolling keys to EFI variables... With vendor keys from microsoft...✓ @@ -352,7 +354,8 @@ empty dbx weakens protection against revoked, Microsoft-signed bootkits. Reboot once more and verify that Secure Boot is active: -``` +```console +$ bootctl status System: Firmware: UEFI 2.40 (American Megatrends 5.11) Firmware Arch: x64