mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-12 05:16:25 +03:00
nixos/limine: carefully remove files instead of nuking them
This commit is contained in:
parent
2c7659b1ff
commit
a094b5d8cc
1 changed files with 16 additions and 13 deletions
|
@ -74,6 +74,7 @@ def is_encrypted(device: str) -> bool:
|
||||||
def is_fs_type_supported(fs_type: str) -> bool:
|
def is_fs_type_supported(fs_type: str) -> bool:
|
||||||
return fs_type.startswith('vfat')
|
return fs_type.startswith('vfat')
|
||||||
|
|
||||||
|
paths = {}
|
||||||
|
|
||||||
def get_copied_path_uri(path: str, target: str) -> str:
|
def get_copied_path_uri(path: str, target: str) -> str:
|
||||||
result = ''
|
result = ''
|
||||||
|
@ -85,6 +86,8 @@ def get_copied_path_uri(path: str, target: str) -> str:
|
||||||
|
|
||||||
if not os.path.exists(dest_path):
|
if not os.path.exists(dest_path):
|
||||||
copy_file(path, dest_path)
|
copy_file(path, dest_path)
|
||||||
|
else:
|
||||||
|
paths[dest_path] = True
|
||||||
|
|
||||||
path_with_prefix = os.path.join('/limine', target, dest_file)
|
path_with_prefix = os.path.join('/limine', target, dest_file)
|
||||||
result = f'boot():{path_with_prefix}'
|
result = f'boot():{path_with_prefix}'
|
||||||
|
@ -206,6 +209,8 @@ def copy_file(from_path: str, to_path: str):
|
||||||
shutil.copyfile(from_path, to_path + ".tmp")
|
shutil.copyfile(from_path, to_path + ".tmp")
|
||||||
os.rename(to_path + ".tmp", to_path)
|
os.rename(to_path + ".tmp", to_path)
|
||||||
|
|
||||||
|
paths[to_path] = True
|
||||||
|
|
||||||
def option_from_config(name: str, config_path: List[str], conversion: Callable[[str], str] | None = None) -> str:
|
def option_from_config(name: str, config_path: List[str], conversion: Callable[[str], str] | None = None) -> str:
|
||||||
if config(*config_path):
|
if config(*config_path):
|
||||||
return f'{name}: {conversion(config(*config_path)) if conversion else config(*config_path)}\n'
|
return f'{name}: {conversion(config(*config_path)) if conversion else config(*config_path)}\n'
|
||||||
|
@ -246,12 +251,10 @@ def main():
|
||||||
|
|
||||||
if not os.path.exists(limine_dir):
|
if not os.path.exists(limine_dir):
|
||||||
os.makedirs(limine_dir)
|
os.makedirs(limine_dir)
|
||||||
|
else:
|
||||||
if os.path.exists(os.path.join(limine_dir, 'kernels')):
|
for dir, dirs, files in os.walk(limine_dir, topdown=True):
|
||||||
print(f'nuking {os.path.join(limine_dir, "kernels")}')
|
for file in files:
|
||||||
shutil.rmtree(os.path.join(limine_dir, 'kernels'))
|
paths[os.path.join(dir, file)] = False
|
||||||
|
|
||||||
os.makedirs(os.path.join(limine_dir, "kernels"))
|
|
||||||
|
|
||||||
profiles = [('system', get_gens())]
|
profiles = [('system', get_gens())]
|
||||||
|
|
||||||
|
@ -271,13 +274,6 @@ def main():
|
||||||
default_entry: 2
|
default_entry: 2
|
||||||
''')
|
''')
|
||||||
|
|
||||||
if os.path.exists(os.path.join(limine_dir, 'wallpapers')):
|
|
||||||
print(f'nuking {os.path.join(limine_dir, "wallpapers")}')
|
|
||||||
shutil.rmtree(os.path.join(limine_dir, 'wallpapers'))
|
|
||||||
|
|
||||||
if len(config('style', 'wallpapers')) > 0:
|
|
||||||
os.makedirs(os.path.join(limine_dir, 'wallpapers'))
|
|
||||||
|
|
||||||
for wallpaper in config('style', 'wallpapers'):
|
for wallpaper in config('style', 'wallpapers'):
|
||||||
config_file += f'''wallpaper: {get_copied_path_uri(wallpaper, 'wallpapers')}\n'''
|
config_file += f'''wallpaper: {get_copied_path_uri(wallpaper, 'wallpapers')}\n'''
|
||||||
|
|
||||||
|
@ -319,6 +315,8 @@ def main():
|
||||||
file.truncate()
|
file.truncate()
|
||||||
file.write(config_file.strip())
|
file.write(config_file.strip())
|
||||||
|
|
||||||
|
paths[config_file_path] = True
|
||||||
|
|
||||||
for dest_path, source_path in config('additionalFiles').items():
|
for dest_path, source_path in config('additionalFiles').items():
|
||||||
dest_path = os.path.join(limine_dir, dest_path)
|
dest_path = os.path.join(limine_dir, dest_path)
|
||||||
|
|
||||||
|
@ -410,4 +408,9 @@ def main():
|
||||||
'Failed to deploy BIOS stage 1 Limine bootloader!\n' +
|
'Failed to deploy BIOS stage 1 Limine bootloader!\n' +
|
||||||
'You might want to try enabling the `boot.loader.limine.forceMbr` option.')
|
'You might want to try enabling the `boot.loader.limine.forceMbr` option.')
|
||||||
|
|
||||||
|
print("removing unused boot files...")
|
||||||
|
for path in paths:
|
||||||
|
if not paths[path]:
|
||||||
|
os.remove(path)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue