Skip to content

Commit 7c21a5f

Browse files
m-bdfsternenseemann
authored andcommitted
sdboot-builder: fix crash in exception handling
1 parent d5f2378 commit 7c21a5f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
import datetime
1616
import glob
1717
import os.path
18-
from typing import Tuple, List, Optional
18+
from typing import NamedTuple, List, Optional
1919

20-
SystemIdentifier = Tuple[Optional[str], int, Optional[str]]
20+
class SystemIdentifier(NamedTuple):
21+
profile: Optional[str]
22+
generation: int
23+
specialisation: Optional[str]
2124

2225

2326
def copy_if_not_exists(source: str, dest: str) -> None:
@@ -151,7 +154,7 @@ def get_generations(profile: Optional[str] = None) -> List[SystemIdentifier]:
151154
gen_lines.pop()
152155

153156
configurationLimit = @configurationLimit@
154-
configurations: List[SystemIdentifier] = [ (profile, int(line.split()[0]), None) for line in gen_lines ]
157+
configurations = [SystemIdentifier(profile, int(line.split()[0]), None) for line in gen_lines]
155158
return configurations[-configurationLimit:]
156159

157160

@@ -160,7 +163,7 @@ def get_specialisations(profile: Optional[str], generation: int, _: Optional[str
160163
system_dir(profile, generation, None), "specialisation")
161164
if not os.path.exists(specialisations_dir):
162165
return []
163-
return [(profile, generation, spec) for spec in os.listdir(specialisations_dir)]
166+
return [SystemIdentifier(profile, generation, spec) for spec in os.listdir(specialisations_dir)]
164167

165168

166169
def remove_old_entries(gens: List[SystemIdentifier]) -> None:
@@ -271,7 +274,8 @@ def main() -> None:
271274
if os.readlink(system_dir(*gen)) == args.default_config:
272275
write_loader_conf(*gen)
273276
except OSError as e:
274-
print("ignoring generation '{}' in the list of boot entries because of the following error:\n{}".format(*gen, e), file=sys.stderr)
277+
profile = f"profile '{gen.profile}'" if gen.profile else "default profile"
278+
print("ignoring {} in the list of boot entries because of the following error:\n{}".format(profile, e), file=sys.stderr)
275279

276280
for root, _, files in os.walk('@efiSysMountPoint@/efi/nixos/.extra-files', topdown=False):
277281
relative_root = root.removeprefix("@efiSysMountPoint@/efi/nixos/.extra-files").removeprefix("/")

0 commit comments

Comments
 (0)