nix-community/nixos-anywhere

FR: Separate Disko Flake / Config

cvoges12 opened this issue · 10 comments

Problem / Rationale

I (as well as many others) like to keep a separate disko configuration. This is to ensure that disko will not run again and force me to recover my system along with its data.

I'm aware that disko does not run again as long as you do not change it. But I (like many other nix users) modify and continuously maintain my nix configurations instead of for only one shot deployments but for other deployments as well. And when I make changes, even after running --dry-run, I still fear that disko might reformat my drive(s).

Proposal

I propose to have a command line option to run disko with a separate flake. I would prefer to have capability for disko flakes. But I'm aware that not everyone wants to use flakes as well: #194 #190. So maybe there should be a way to detect whether the argument is a flake or not. Or there could be two different command line options: one for flakes and one for non-flake configurations.

I'm imagining something like --disko <flake-uri>#<configuration> or --disko <path-to-non-flake-disko-conflig>.

Mic92 commented

This won't work well because the disko module needs to be part of your nixos configuration. Otherwise it won't set the right filesystems and other options in the nixos configuration. Disko is also not run if you change it. It needs to be explicitly called from tools like the disko cli or nixos-anywhere.

@Mic92
I run disko already without it being a part of my nixos configuration. And it is able to set the filesystems just fine. I've even set file systems on LVM volumes and LUKS mapped devices. So I'm not sure what you mean.

Disko is also not run if you change it.

I'm not sure how this is possible if somone uses the same flake to install with nixos-anywhere that they do to nixos-rebuild which is fairly common. I'd hate to have to maintain two different configurations for every system: one to install with nixos-anywhere and the other to rebuild after every time I make a change to my configuration.

Oh. On second thought, do you mean that you want to have the filesystem options on nixos set automatically by disko? Hmm, I can see how that could be of issue. Is there no way to roll your own filesystem configurations in the nixos configuration? I could imagine this being possible if you named the device partitions in disko explicitely.

(Still confused on what you mean by changing it does not run disko again. Would still like you to explain)

Mic92 commented

Now I am confused what problem you actually want to solve here. I don't really want to add the complexity that a separate --disko flag would bring in nixos-anywhere without a good reason of what use-cases it would add. You can already import disko configuration from other flakes into your nixos configuration and you can have multiple nixos systems that are almost the same except for the disko configuration.

I'm wanting an option for nixos-anywhere to run disko before running the nixos install.

Effectively doing:

nix --extra-experimental-features nix-command --extra-experimental-features flakes run github:nix-community/disko -- --mode disko --flake <flake>
nixos-install --flake <flake>

You can already import disko configuration from other flakes into your nixos configuration and you can have multiple nixos systems that are almost the same except for the disko configuration.

This kind of defeats the purpose of not having it in your nixos configuration though. I'm saying that I wouldn't want this because it risks overwriting the specified disk(s) with any changes to the disko configuration.

Mic92 commented

Ok. Sorry, this is out of scope of nixos-anywhere just now.

But you can just do this (or have it in a script):

ssh root@your-machine <<EOF
nix --extra-experimental-features nix-command --extra-experimental-features flakes run github:nix-community/disko -- --mode disko --flake <flake>
nixos-install --flake <flake>
EOF

nixos-rebuild switch will not run any of the diskoScripts again, the only thing that changes if you change your disko config is the fileSystem, boot and swapDevices of your nixos configuration if you actually use the module.

@Mic92
I'm not sure why this is out of scope when already using disko is within scope. And no, the equivalent script does not work as I would need to kexec and all which is what nixos-anywhere is good for. I still want this to work for deploying to systems which aren't nixos.

@Lassulus Ah, okay. That clears up a lot then. Ig in that case this isn't so necessary.

you can actually use the non flakes mode of nixos-anywhere with -s and do something like:
nixos-anywhere -s $(nix build 'github:my-org/my-repo#disko-config' --print-out-paths --no-link) $(nix build 'github:myorg/my-repo#my-system' --print-out-paths --no-link)