summaryrefslogtreecommitdiffstats
path: root/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py
diff options
context:
space:
mode:
authorr-vdp <ramses@well-founded.dev>2024-01-24 18:15:28 +0100
committerr-vdp <ramses@well-founded.dev>2024-03-02 02:11:32 +0100
commita8ab8b59a75a4bf0675fb3785e76c54873044f9e (patch)
tree965e489b9c8c00ca3fbf74859bfe0abfd818a07c /nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py
parent0267739e11e44bb791b747565758c6446b01eac7 (diff)
systemd-boot: introduce options to set a sort-key for systemd-boot entries
Without sort-keys specified on entries, the entries are sorted only by file name (in decreasing order, so starting at the end of the alphabet!), without taking any other fields into account (see [the boot loader specification reference][1]). Moreover, entries without a sort-key are always ordered after all entries with a sort-key, so by not adding a sort-key to the NixOS ones, we cannot add a sort-key to any other entry while keeping it below the NixOS entries. So currently we have options to set the file names for additional entries like memtest and netbootxyz. However, as mentioned above, the sorting by file name is not very intuitive and actually sorts in the opposite order of what is currently mentioned in the option descriptions. With this commit, we set a configurable sort-key on all NixOS entries, and add options for setting the sort-keys for the memtest and netbootxyz entries. The sorting by sort-key is more intuitive (it starts at the start of the alphabet) and also takes into account the machine-id and version for entries with identical sort-keys. We use a bootspec extension to store the sort keys, which allows us to redefine the sort key for individual specialisations without needing any special casing. [1]: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
Diffstat (limited to 'nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py')
-rw-r--r--nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py11
1 files changed, 10 insertions, 1 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 258cf622a894..03bff1dee5b9 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
@@ -43,6 +43,7 @@ class BootSpec:
system: str
toplevel: str
specialisations: Dict[str, "BootSpec"]
+ sortKey: str
initrdSecrets: str | None = None
@@ -73,6 +74,7 @@ def system_dir(profile: str | None, generation: int, specialisation: str | None)
return d
BOOT_ENTRY = """title {title}
+sort-key {sort_key}
version Generation {generation} {description}
linux {kernel}
initrd {initrd}
@@ -123,7 +125,13 @@ def get_bootspec(profile: str | None, generation: int) -> BootSpec:
def bootspec_from_json(bootspec_json: Dict) -> BootSpec:
specialisations = bootspec_json['org.nixos.specialisation.v1']
specialisations = {k: bootspec_from_json(v) for k, v in specialisations.items()}
- return BootSpec(**bootspec_json['org.nixos.bootspec.v1'], specialisations=specialisations)
+ systemdBootExtension = bootspec_json.get('org.nixos.systemd-boot', {})
+ sortKey = systemdBootExtension.get('sortKey', 'nixos')
+ return BootSpec(
+ **bootspec_json['org.nixos.bootspec.v1'],
+ specialisations=specialisations,
+ sortKey=sortKey
+ )
def copy_from_file(file: str, dry_run: bool = False) -> str:
@@ -170,6 +178,7 @@ def write_entry(profile: str | None, generation: int, specialisation: str | None
with open(tmp_path, 'w') as f:
f.write(BOOT_ENTRY.format(title=title,
+ sort_key=bootspec.sortKey,
generation=generation,
kernel=kernel,
initrd=initrd,