From 642323930effc0c520c66ff31d84e00d481f2813 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Fri, 7 Oct 2022 19:03:15 +0800 Subject: [PATCH 1/3] nixos/systemd-boot: correctly find gen_number for specialisation Before this patch, the gen_number found by regex contains "-specialisation-foo" if specialisation is used. As a result, applying int() to gen_number raises ValueError, causing entries containing a specialisation part not being removed. --- .../system/boot/loader/systemd-boot/systemd-boot-builder.py | 2 +- 1 file changed, 1 insertion(+), 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 5398ef6b84eb..09e5e88ee022 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 @@ -175,7 +175,7 @@ def get_specialisations(profile: Optional[str], generation: int, _: Optional[str def remove_old_entries(gens: List[SystemIdentifier]) -> None: rex_profile = re.compile("^@efiSysMountPoint@/loader/entries/nixos-(.*)-generation-.*\.conf$") - rex_generation = re.compile("^@efiSysMountPoint@/loader/entries/nixos.*-generation-(.*)\.conf$") + rex_generation = re.compile("^@efiSysMountPoint@/loader/entries/nixos.*-generation-([0-9]+)(-specialisation-.*)?\.conf$") known_paths = [] for gen in gens: known_paths.append(copy_from_profile(*gen, "kernel", True)) From 437f73dd546e1cbaaa9de576608bdfa0281659e3 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Fri, 7 Oct 2022 19:31:43 +0800 Subject: [PATCH 2/3] nixos/systemd-boot: fix entry match condition in remove_old_entries Before this patch, the entry match condition always fails, causing all entries being removed. The error is not noticed because later they are re-generated. --- .../system/boot/loader/systemd-boot/systemd-boot-builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 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 09e5e88ee022..0ad967526ba5 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 @@ -185,9 +185,9 @@ def remove_old_entries(gens: List[SystemIdentifier]) -> None: if rex_profile.match(path): prof = rex_profile.sub(r"\1", path) else: - prof = "system" + prof = None gen_number = int(rex_generation.sub(r"\1", path)) - if not (prof, gen_number) in gens: + if not (prof, gen_number, None) in gens: os.unlink(path) except ValueError: pass From 42c94928296294aeed01e7ac9c77a664a4abddf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 15 Oct 2022 15:32:36 +0200 Subject: [PATCH 3/3] nixos/systemd-boot: decrease catch scope for ValueError --- .../loader/systemd-boot/systemd-boot-builder.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 0ad967526ba5..68da20615917 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 @@ -181,16 +181,16 @@ def remove_old_entries(gens: List[SystemIdentifier]) -> None: known_paths.append(copy_from_profile(*gen, "kernel", True)) known_paths.append(copy_from_profile(*gen, "initrd", True)) for path in glob.iglob("@efiSysMountPoint@/loader/entries/nixos*-generation-[1-9]*.conf"): + if rex_profile.match(path): + prof = rex_profile.sub(r"\1", path) + else: + prof = None try: - if rex_profile.match(path): - prof = rex_profile.sub(r"\1", path) - else: - prof = None gen_number = int(rex_generation.sub(r"\1", path)) - if not (prof, gen_number, None) in gens: - os.unlink(path) except ValueError: - pass + continue + if not (prof, gen_number, None) in gens: + os.unlink(path) for path in glob.iglob("@efiSysMountPoint@/efi/nixos/*"): if not path in known_paths and not os.path.isdir(path): os.unlink(path)