nixos/limine: tidy up the boot menu

This commit is contained in:
hustlerone
2025-05-22 20:45:00 +05:30
committed by Masum Reza
parent 6ac3a69b20
commit de6905ee37
@@ -168,14 +168,29 @@ def config_entry(levels: int, bootspec: BootSpec, label: str, time: str) -> str:
return entry
def generate_config_entry(profile: str, gen: str) -> str:
def generate_config_entry(profile: str, gen: str, special: bool) -> str:
time = datetime.datetime.fromtimestamp(os.stat(get_system_path(profile,gen), follow_symlinks=False).st_mtime).strftime("%F %H:%M:%S")
boot_json = json.load(open(os.path.join(get_system_path(profile, gen), 'boot.json'), 'r'))
boot_spec = bootjson_to_bootspec(boot_json)
entry = config_entry(2, boot_spec, f'Generation {gen}', time)
for spec, spec_boot_spec in boot_spec.specialisations.items():
entry += config_entry(2, spec_boot_spec, f'Generation {gen}, Specialisation {spec}', str(time))
specialisation_list = boot_spec.specialisations.items()
depth = 2
entry = ""
if len(specialisation_list) > 0:
depth += 1
entry += '/' * (depth-1)
if special:
entry += '+'
entry += f'Generation {gen}' + '\n'
entry += config_entry(depth, boot_spec, f'Default', str(time))
else:
entry += config_entry(depth, boot_spec, f'Generation {gen}', str(time))
for spec, spec_boot_spec in specialisation_list:
entry += config_entry(depth, spec_boot_spec, f'{spec}', str(time))
return entry
@@ -269,13 +284,17 @@ def main():
editor_enabled = 'yes' if config('enableEditor') else 'no'
hash_mismatch_panic = 'yes' if config('panicOnChecksumMismatch') else 'no'
last_gen = get_gens()[-1]
last_gen_json = json.load(open(os.path.join(get_system_path('system', last_gen), 'boot.json'), 'r'))
last_gen_boot_spec = bootjson_to_bootspec(last_gen_json)
config_file = config('extraConfig') + '\n'
config_file += textwrap.dedent(f'''
timeout: {timeout}
editor_enabled: {editor_enabled}
hash_mismatch_panic: {hash_mismatch_panic}
graphics: yes
default_entry: 2
default_entry: {3 if len(last_gen_boot_spec.specialisations.items()) > 0 else 2}
''')
for wallpaper in config('style', 'wallpapers'):
@@ -307,8 +326,11 @@ def main():
group_name = 'default profile' if profile == 'system' else f"profile '{profile}'"
config_file += f'/+NixOS {group_name}\n'
isFirst = True
for gen in sorted(gens, key=lambda x: x, reverse=True):
config_file += generate_config_entry(profile, gen)
config_file += generate_config_entry(profile, gen, isFirst)
isFirst = False
config_file_path = os.path.join(limine_dir, 'limine.conf')
config_file += '\n# NixOS boot entries end here\n\n'