systemd-boot: inline add_entry function
This commit is contained in:
parent
4e0423467a
commit
8bb4551273
@ -23,22 +23,6 @@ initrd {initrd}
|
||||
options {kernel_params}
|
||||
"""
|
||||
|
||||
def write_entry(generation, machine_id, kernel, initrd):
|
||||
entry_file = "@efiSysMountPoint@/loader/entries/nixos-generation-%d.conf" % (generation)
|
||||
generation_dir = os.readlink(system_dir(generation))
|
||||
tmp_path = "%s.tmp" % (entry_file)
|
||||
kernel_params = "systemConfig=%s init=%s/init " % (generation_dir, generation_dir)
|
||||
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(generation=generation,
|
||||
kernel=kernel,
|
||||
initrd=initrd,
|
||||
kernel_params=kernel_params))
|
||||
if machine_id is not None:
|
||||
f.write("machine-id %s\n" % machine_id)
|
||||
os.rename(tmp_path, entry_file)
|
||||
|
||||
def write_loader_conf(generation):
|
||||
with open("@efiSysMountPoint@/loader/loader.conf.tmp", 'w') as f:
|
||||
if "@timeout@" != "":
|
||||
@ -55,10 +39,23 @@ def copy_from_profile(generation, name, dry_run=False):
|
||||
copy_if_not_exists(store_file_path, "@efiSysMountPoint@%s" % (efi_file_path))
|
||||
return efi_file_path
|
||||
|
||||
def add_entry(generation, machine_id):
|
||||
efi_kernel_path = copy_from_profile(generation, "kernel")
|
||||
efi_initrd_path = copy_from_profile(generation, "initrd")
|
||||
write_entry(generation, machine_id, efi_kernel_path, efi_initrd_path)
|
||||
def write_entry(generation, machine_id):
|
||||
kernel = copy_from_profile(generation, "kernel")
|
||||
initrd = copy_from_profile(generation, "initrd")
|
||||
entry_file = "@efiSysMountPoint@/loader/entries/nixos-generation-%d.conf" % (generation)
|
||||
generation_dir = os.readlink(system_dir(generation))
|
||||
tmp_path = "%s.tmp" % (entry_file)
|
||||
kernel_params = "systemConfig=%s init=%s/init " % (generation_dir, generation_dir)
|
||||
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(generation=generation,
|
||||
kernel=kernel,
|
||||
initrd=initrd,
|
||||
kernel_params=kernel_params))
|
||||
if machine_id is not None:
|
||||
f.write("machine-id %s\n" % machine_id)
|
||||
os.rename(tmp_path, entry_file)
|
||||
|
||||
def mkdir_p(path):
|
||||
try:
|
||||
@ -125,7 +122,7 @@ def main():
|
||||
gens = get_generations("system")
|
||||
remove_old_entries(gens)
|
||||
for gen in gens:
|
||||
add_entry(gen, machine_id)
|
||||
write_entry(gen, machine_id)
|
||||
if os.readlink(system_dir(gen)) == args.default_config:
|
||||
write_loader_conf(gen)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user