3
0
Fork 0
forked from mirrors/nixpkgs

nixos/systemd-boot: improve initrd-secrets error messages

This is the equivalent of eccc1e5b but for systemd-boot
This commit is contained in:
rnhmjoj 2023-01-19 19:18:19 +01:00
parent 2bc5625877
commit 4ed9893770
No known key found for this signature in database
GPG key ID: BFBAF4C975F76450

View file

@ -42,7 +42,7 @@ def system_dir(profile: Optional[str], generation: int, specialisation: Optional
else:
return d
BOOT_ENTRY = """title @distroName@{profile}{specialisation}
BOOT_ENTRY = """title {title}
version Generation {generation} {description}
linux {kernel}
initrd {initrd}
@ -106,14 +106,29 @@ def describe_generation(generation_dir: str) -> str:
return description
def write_entry(profile: Optional[str], generation: int, specialisation: Optional[str], machine_id: str) -> None:
def write_entry(profile: Optional[str], generation: int, specialisation: Optional[str],
machine_id: str, current: bool) -> None:
kernel = copy_from_profile(profile, generation, specialisation, "kernel")
initrd = copy_from_profile(profile, generation, specialisation, "initrd")
title = "@distroName@{profile}{specialisation}".format(
profile=" [" + profile + "]" if profile else "",
specialisation=" (%s)" % specialisation if specialisation else "")
try:
append_initrd_secrets = profile_path(profile, generation, specialisation, "append-initrd-secrets")
subprocess.check_call([append_initrd_secrets, "@efiSysMountPoint@%s" % (initrd)])
except FileNotFoundError:
pass
except subprocess.CalledProcessError:
if current:
print("failed to create initrd secrets!", file=sys.stderr)
sys.exit(1)
else:
print("warning: failed to create initrd secrets "
f'for "{title} - Configuration {generation}", an older generation', file=sys.stderr)
print("note: this is normal after having removed "
"or renamed a file in `boot.initrd.secrets`", file=sys.stderr)
entry_file = "@efiSysMountPoint@/loader/entries/%s" % (
generation_conf_filename(profile, generation, specialisation))
generation_dir = os.readlink(system_dir(profile, generation, specialisation))
@ -123,8 +138,7 @@ def write_entry(profile: Optional[str], generation: int, specialisation: Optiona
with open("%s/kernel-params" % (generation_dir)) as params_file:
kernel_params = kernel_params + params_file.read()
with open(tmp_path, 'w') as f:
f.write(BOOT_ENTRY.format(profile=" [" + profile + "]" if profile else "",
specialisation=" (%s)" % specialisation if specialisation else "",
f.write(BOOT_ENTRY.format(title=title,
generation=generation,
kernel=kernel,
initrd=initrd,
@ -281,10 +295,11 @@ def main() -> None:
remove_old_entries(gens)
for gen in gens:
try:
write_entry(*gen, machine_id)
is_default = os.readlink(system_dir(*gen)) == args.default_config
write_entry(*gen, machine_id, current=is_default)
for specialisation in get_specialisations(*gen):
write_entry(*specialisation, machine_id)
if os.readlink(system_dir(*gen)) == args.default_config:
write_entry(*specialisation, machine_id, current=is_default)
if is_default:
write_loader_conf(*gen)
except OSError as e:
profile = f"profile '{gen.profile}'" if gen.profile else "default profile"