summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJulien Malka <julien@malka.sh>2023-11-16 23:48:19 +0000
committerJulien Malka <julien@malka.sh>2023-11-17 14:39:04 +0100
commit81e378618e3f201e1d55abcbd920fdca394c21a5 (patch)
tree20a881bb044d717bd089801f67f30a9d26200451 /nixos
parent4fae7293f40740bbc584df9056d8856a1c7b0dbe (diff)
downloadnixpkgs-81e378618e3f201e1d55abcbd920fdca394c21a5.tar
nixpkgs-81e378618e3f201e1d55abcbd920fdca394c21a5.tar.gz
nixpkgs-81e378618e3f201e1d55abcbd920fdca394c21a5.tar.bz2
nixpkgs-81e378618e3f201e1d55abcbd920fdca394c21a5.tar.lz
nixpkgs-81e378618e3f201e1d55abcbd920fdca394c21a5.tar.xz
nixpkgs-81e378618e3f201e1d55abcbd920fdca394c21a5.tar.zst
nixpkgs-81e378618e3f201e1d55abcbd920fdca394c21a5.zip
nixos/systemd-boot: allow for bootspec-less generations
Generation built with old versions of NixOS with no bootspec
support may still be present on the system and must be
accounted for.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py17
-rw-r--r--nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix2
-rw-r--r--nixos/tests/systemd-boot.nix16
3 files changed, 32 insertions, 3 deletions
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 96b42066b22..7d06e0131d9 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
@@ -88,9 +88,20 @@ def write_loader_conf(profile: str | None, generation: int, specialisation: str
 
 
 def get_bootspec(profile: str | None, generation: int) -> BootSpec:
-    boot_json_path = os.path.realpath("%s/%s" % (system_dir(profile, generation, None), "boot.json"))
-    boot_json_f = open(boot_json_path, 'r')
-    bootspec_json = json.load(boot_json_f)
+    system_directory = system_dir(profile, generation, None)
+    boot_json_path = os.path.realpath("%s/%s" % (system_directory, "boot.json"))
+    if os.path.isfile(boot_json_path):
+        boot_json_f = open(boot_json_path, 'r')
+        bootspec_json = json.load(boot_json_f)
+    else:
+        boot_json_str = subprocess.check_output([
+        "@bootspecTools@/bin/synthesize",
+        "--version",
+        "1",
+        system_directory,
+        "/dev/stdout"],
+        universal_newlines=True)
+        bootspec_json = json.loads(boot_json_str)
     return bootspec_from_json(bootspec_json)
 
 def bootspec_from_json(bootspec_json: Dict) -> BootSpec:
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 1086ab80b14..9d55c21077d 100644
--- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
+++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix
@@ -16,6 +16,8 @@ let
 
     systemd = config.systemd.package;
 
+    bootspecTools = pkgs.bootspec;
+
     nix = config.nix.package.out;
 
     timeout = optionalString (config.boot.loader.timeout != null) config.boot.loader.timeout;
diff --git a/nixos/tests/systemd-boot.nix b/nixos/tests/systemd-boot.nix
index 13007d0d80d..a592504addc 100644
--- a/nixos/tests/systemd-boot.nix
+++ b/nixos/tests/systemd-boot.nix
@@ -277,4 +277,20 @@ in
       machine.wait_for_unit("multi-user.target")
     '';
   };
+
+  no-bootspec = makeTest
+    {
+      name = "systemd-boot-no-bootspec";
+      meta.maintainers = with pkgs.lib.maintainers; [ julienmalka ];
+
+      nodes.machine = {
+        imports = [ common ];
+        boot.bootspec.enable = false;
+      };
+
+      testScript = ''
+        machine.start()
+        machine.wait_for_unit("multi-user.target")
+      '';
+    };
 }