nix-community / disko

Declarative disk partitioning and formatting using nix [maintainers=@Lassulus @Enzime @iFreilicht]
MIT License
1.8k stars 194 forks source link

[feature-request] mode to output fileSystems nix configuration #537

Open con-f-use opened 8 months ago

con-f-use commented 8 months ago

For debugging and when one doesn't want to use the module in one's NixOS configuraiton, it would be nice if disko had a fourth mode, that just prints the resulting fileSystems = { ... }; block for a nixos system.

$ disko --help
disko [options] disk-config.nix
or disko [options] --flake github:somebody/somewhere#disk-config

With flakes, disk-config is discovered first under the .diskoConfigurations top level attribute
or else from the disko module of a NixOS configuration of that name under .nixosConfigurations.

Options:

* -m, --mode mode
  set the mode, either format, mount or disko
    format: create partition tables, zpools, lvms, raids and filesystems
    mount: mount the partition at the specified root-mountpoint
    disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
    nix-filesystems: pirnts the `filesyStems` block of NixOS configuration
LovingMelody commented 8 months ago

Not exactly what you are looking for, but this works for flakes nix eval .#nixosConfigurations.HOST.config.fileSystems just replace HOST with the system name. If you want a pretty output nix eval .#nixosConfigurations.HOST.config.fileSystems --json | jq should do as well

intelfx commented 8 months ago

@LovingMelody sorry, I'm new to Nix — what is "works for flakes" in this context? given a (slightly patched) disko and a standalone disko config file, how can I make this expression work?

LovingMelody commented 7 months ago

@intelfx It should work so long as your NixOS configuration is using flakes.

intelfx commented 7 months ago

@LovingMelody I don't have NixOS, just a standalone disko checkout and a config file :sweat_smile:

TheRealGramdalf commented 4 months ago

If you want this manually, you can use nixos-generate-config --show-hardware-config --root /mnt once it's mounted (via mount mode, or disko mode). There's some extra stuff in there regarding kernel modules/drivers etc (which should be ignored if you are partitioning a disk for another system), but you mainly need the filesystem stuff.

iFreilicht commented 1 week ago

@intelfx: I don't have NixOS, just a standalone disko checkout and a config file 😅

In the disko repository, run this:

nix eval --impure --expr 'builtins.mapAttrs (_: v: v.contents) ((import ./. {}).config (import example/simple-efi.nix))'

When that works, replace example/simple-efi.nix with the path to your disko file.

I think this is a decent feature and would accept a PR that implements it. The code I wrote out above should be a good starting point.