nixos/limine: tidy up the boot menu

authored by hustlerone and committed by Masum Reza de6905ee 6ac3a69b

+28 -6
+28 -6
nixos/modules/system/boot/loader/limine/limine-install.py
··· 168 168 return entry 169 169 170 170 171 - def generate_config_entry(profile: str, gen: str) -> str: 171 + def generate_config_entry(profile: str, gen: str, special: bool) -> str: 172 172 time = datetime.datetime.fromtimestamp(os.stat(get_system_path(profile,gen), follow_symlinks=False).st_mtime).strftime("%F %H:%M:%S") 173 173 boot_json = json.load(open(os.path.join(get_system_path(profile, gen), 'boot.json'), 'r')) 174 174 boot_spec = bootjson_to_bootspec(boot_json) 175 175 176 - entry = config_entry(2, boot_spec, f'Generation {gen}', time) 177 - for spec, spec_boot_spec in boot_spec.specialisations.items(): 178 - entry += config_entry(2, spec_boot_spec, f'Generation {gen}, Specialisation {spec}', str(time)) 176 + specialisation_list = boot_spec.specialisations.items() 177 + depth = 2 178 + entry = "" 179 + 180 + if len(specialisation_list) > 0: 181 + depth += 1 182 + entry += '/' * (depth-1) 183 + 184 + if special: 185 + entry += '+' 186 + 187 + entry += f'Generation {gen}' + '\n' 188 + entry += config_entry(depth, boot_spec, f'Default', str(time)) 189 + else: 190 + entry += config_entry(depth, boot_spec, f'Generation {gen}', str(time)) 191 + 192 + for spec, spec_boot_spec in specialisation_list: 193 + entry += config_entry(depth, spec_boot_spec, f'{spec}', str(time)) 179 194 return entry 180 195 181 196 ··· 269 284 editor_enabled = 'yes' if config('enableEditor') else 'no' 270 285 hash_mismatch_panic = 'yes' if config('panicOnChecksumMismatch') else 'no' 271 286 287 + last_gen = get_gens()[-1] 288 + last_gen_json = json.load(open(os.path.join(get_system_path('system', last_gen), 'boot.json'), 'r')) 289 + last_gen_boot_spec = bootjson_to_bootspec(last_gen_json) 290 + 272 291 config_file = config('extraConfig') + '\n' 273 292 config_file += textwrap.dedent(f''' 274 293 timeout: {timeout} 275 294 editor_enabled: {editor_enabled} 276 295 hash_mismatch_panic: {hash_mismatch_panic} 277 296 graphics: yes 278 - default_entry: 2 297 + default_entry: {3 if len(last_gen_boot_spec.specialisations.items()) > 0 else 2} 279 298 ''') 280 299 281 300 for wallpaper in config('style', 'wallpapers'): ··· 307 326 group_name = 'default profile' if profile == 'system' else f"profile '{profile}'" 308 327 config_file += f'/+NixOS {group_name}\n' 309 328 329 + isFirst = True 330 + 310 331 for gen in sorted(gens, key=lambda x: x, reverse=True): 311 - config_file += generate_config_entry(profile, gen) 332 + config_file += generate_config_entry(profile, gen, isFirst) 333 + isFirst = False 312 334 313 335 config_file_path = os.path.join(limine_dir, 'limine.conf') 314 336 config_file += '\n# NixOS boot entries end here\n\n'