From f15bcc27b4b58df409eaad060b4c83c087246d84 Mon Sep 17 00:00:00 2001 From: lassulus Date: Tue, 10 Nov 2026 12:49:34 +0100 Subject: [PATCH] luks: don't define boot.initrd.systemd.enable where the option was removed NixOS 26.11 dropped scripted stage 1 (NixOS/nixpkgs#573038) and replaced boot.initrd.systemd.enable with mkRemovedOptionModule, whose assertion fails as soon as the option is defined. The luks type set it for enrollFido2, so FIDO2 configs stopped evaluating (#1303). The old mkIf would also break once the removal shim is dropped, because mkIf cannot define an option that is not declared at all. Emit the definition via lib.optional only when diskoLib.systemdInitrdToggleable says the option still has its bool type. The removed-option stub is untyped; renamed or hidden declarations keep bool, so unlike checking `visible` this does not misfire on aliases. Where the option is gone, stage 1 is always systemd, so nothing needs to be set. The flag reaches the types through globals.canToggleSystemdInitrd: - module.nix derives it from the system's options; - default.nix accepts canToggleSystemdInitrd (default true, the pre-26.11 behaviour) for direct callers of the legacy outputs; - the test harness probes the nixpkgs under test for direct mode. The test harness itself read config.boot.initrd.systemd.enable, which throws on 26.11; guard it as done in lib/tests.nix of https://github.com/nix-community/disko/pull/1304/changes#diff-605c7b66854ad3072529f715252655bb5b4e5e5b53a99edec9dc929fd85162cd --- default.nix | 3 ++- lib/default.nix | 20 ++++++++++++++++++-- lib/tests.nix | 22 ++++++++++++++++++---- lib/types/luks.nix | 10 ++++++---- module.nix | 2 ++ 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/default.nix b/default.nix index 5bc1151..7691b28 100644 --- a/default.nix +++ b/default.nix @@ -1,8 +1,9 @@ { lib ? import , rootMountPoint ? "/mnt", + canToggleSystemdInitrd ? true, checked ? false, - diskoLib ? import ./lib { inherit lib rootMountPoint; }, + diskoLib ? import ./lib { inherit lib rootMountPoint canToggleSystemdInitrd; }, }: let eval = diff --git a/lib/default.nix b/lib/default.nix index 4bc7561..f1571fa 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -4,6 +4,7 @@ makeTest ? import , eval-config ? import , qemu-common ? import , + canToggleSystemdInitrd ? true, }: let # qemu-common is a function that takes { lib, stdenv } and returns QEMU utilities @@ -22,6 +23,7 @@ let makeTest eval-config qemu-common-lib + diskoLib ; }; # like lib.types.oneOf but instead of a list takes an attrset @@ -481,7 +483,7 @@ let }; config._module.args = { inherit diskoLib; - globals = { inherit rootMountPoint; }; + globals = { inherit rootMountPoint canToggleSystemdInitrd; }; }; } ]; @@ -647,6 +649,17 @@ let */ vmToolsSupportsCustomQemu = final_lib: lib.versionAtLeast final_lib.version "24.11.20240709"; + /* + Checks whether `boot.initrd.systemd.enable` can still be defined in a NixOS configuration. + + NixOS 26.11 removed scripted initrd and replaced the option with `mkRemovedOptionModule`, + which declares an untyped option whose definition fails an assertion. + Real, hidden or renamed declarations keep their bool type. + + systemdInitrdToggleable :: options -> bool + */ + systemdInitrdToggleable = options: (options.boot.initrd.systemd.enable.type.name or null) == "bool"; + /* Checks whether vmTools supports the kernelModules argument. Older nixpkgs versions only supported overriding `kernel` with an aggregated modules tree. @@ -1169,7 +1182,10 @@ let lib.listToAttrs (map (option: lib.nameValuePair option type.options.${option}) options); typesSerializerLib = { - globals.rootMountPoint = ""; + globals = { + rootMountPoint = ""; + canToggleSystemdInitrd = true; + }; options = null; config = { _module = { diff --git a/lib/tests.nix b/lib/tests.nix index eef986d..a0baac2 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -3,6 +3,7 @@ makeTest, eval-config, qemu-common-lib, + diskoLib, ... }: @@ -120,7 +121,16 @@ let # so /dev/vdb becomes /dev/vda etc. testConfigBooted = testLib.prepareDiskoConfig diskoConfigWithArgs testLib.devices; - tsp-generator = pkgs.callPackage ../. { checked = true; }; + # direct mode feeds tsp-config straight into NixOS, so probe the options of the nixpkgs under test + tsp-generator = pkgs.callPackage ../. { + checked = true; + canToggleSystemdInitrd = + diskoLib.systemdInitrdToggleable + (eval-config { + modules = [ ]; + system = pkgs.stdenv.hostPlatform.system; + }).options; + }; tsp-format = (tsp-generator._cliFormat testConfigInstall) pkgs; tsp-mount = (tsp-generator._cliMount testConfigInstall) pkgs; tsp-unmount = (tsp-generator._cliUnmount testConfigInstall) pkgs; @@ -129,7 +139,11 @@ let num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk); installed-system = - { config, ... }: + { config, options, ... }: + let + # boot.initrd.systemd.enable throws once removed (NixOS 26.11+), where stage 1 is always systemd + systemdInitrd = !diskoLib.systemdInitrdToggleable options || config.boot.initrd.systemd.enable; + in { imports = [ (lib.optionalAttrs (testMode == "direct") tsp-config) @@ -146,10 +160,10 @@ let documentation.enable = false; hardware.enableAllFirmware = lib.mkForce false; # FIXME: we don't have an systemd in stage-1 equialvent for this - boot.initrd.preDeviceCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' + boot.initrd.preDeviceCommands = lib.mkIf (!systemdInitrd) '' echo -n 'secretsecret' > /tmp/secret.key ''; - boot.initrd.secrets = lib.mkIf config.boot.initrd.systemd.enable { + boot.initrd.secrets = lib.mkIf systemdInitrd { "/tmp/secret.key" = pkgs.writeText "secret.key" "secretsecret"; }; boot.consoleLogLevel = lib.mkForce 100; diff --git a/lib/types/luks.nix b/lib/types/luks.nix index aa6a5fc..0998148 100644 --- a/lib/types/luks.nix +++ b/lib/types/luks.nix @@ -3,6 +3,7 @@ options, lib, diskoLib, + globals, parent, device, ... @@ -359,12 +360,13 @@ in crypttabExtraOpts = lib.mkIf config.enrollFido2 [ "fido2-device=auto" ]; } // config.settings; - - # If FIDO2 is used, systemd stage 1 is absolutely necessary. - # Should we turn this into an assertion? - boot.initrd.systemd.enable = lib.mkIf config.enrollFido2 true; } ]) + # FIDO2 unlock requires systemd stage 1. NixOS 26.11+ always uses it and has removed the option, + # so only define it where it can still be toggled. + ++ (lib.optional (config.initrdUnlock && config.enrollFido2 && globals.canToggleSystemdInitrd) { + boot.initrd.systemd.enable = true; + }) ++ (lib.optional (config.content != null) config.content._config); description = "NixOS configuration"; }; diff --git a/module.nix b/module.nix index e9f33ff..8062939 100644 --- a/module.nix +++ b/module.nix @@ -1,5 +1,6 @@ { config, + options, lib, pkgs, extendModules, @@ -270,6 +271,7 @@ in makeTest = import "${modulesPath}/../tests/make-test-python.nix"; eval-config = import "${modulesPath}/../lib/eval-config.nix"; qemu-common = import "${modulesPath}/../lib/qemu-common.nix"; + canToggleSystemdInitrd = diskoLib.systemdInitrdToggleable options; }; system.build =