Skip to content

[feature] Impermanence integration via hook scripts for installation #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zackw opened this issue Mar 29, 2025 · 1 comment
Open

[feature] Impermanence integration via hook scripts for installation #1005

zackw opened this issue Mar 29, 2025 · 1 comment

Comments

@zackw
Copy link

zackw commented Mar 29, 2025

I would like to be able to use disko to define the partitioning of a system that uses the impermanence modules to run with an ephemeral root filesystem. An example of the sort of thing I would like to be able to do (possibly with additional setup) is shown in the attached flake.nix.

At present, this doesn't work, for two reasons. First, and most important, files that are written to the root filesystem by the installer, before impermanence gets a chance to set itself up, are lost, even if they are in a directory that impermanence tracks. (Most importantly, with the configuration in the attached flake.nix, all of /nix/var/nix is lost, as is everything in persisted subdirectories of /var.) Second, if you follow the advice in the impermanence manual to put all of /nix under persistence, disko's installation script will copy /nix/store into the ephemeral root filesystem before impermanence is up and running, which will almost certainly run the installation VM out of RAM and crash. (The attached flake.nix works around this by creating an independent, directly mounted partition for /nix/store, which I personally think is a better idea anyway, but it'd be nice if the official impermanence recommendations worked.)

To make this work as seamlessly as possible will require changes in both disko and impermanence, but I think the only thing that needs to happen on disko's side is for its installer and VM builder to permit execution of hook scripts, defined by other NixOS modules, at key moments during the process. Impermanence would want to run a hook script right after all the filesystems are created and mounted but before any other work is done (even before copy_after_disko files are copied). I can also imagine uses for a hook that executes between creating partitions and creating filesystems, and a hook that executes after installation is complete.


flake.nix

@plietar
Copy link

plietar commented Apr 21, 2025

I have a different use case for a hook script, where I want to run some code before disko formats the disks. In my case I want to configure the hardware RAID controller using a vendor-specific storcli command.

Something like:

config.disko.preFormat = ''
  ${lib.getExe pkgs.storcli} /c0/vall del
  ${lib.getExe pkgs.storcli} /c0 add vd r0 drives=252:0
'';

Admittedly I could just run those commands before I run disko, but then it wouldn't be automated with nixos-anywhere. Having this feature either in disko or in nixos-anywhere would be handy.

EDIT: I've since found out there's a config.disko.disk.<name>.preCreateHook already which can be used. An equivalent global option would be good to have as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants