nix-community/nixos-anywhere

Make disko.rootMountPoint more easily overridable

Closed this issue · 1 comments

gbtb commented

Is your feature request related to a problem? Please describe.

Hello.

I've stumbled upon a problem with zfs configuration when tried to partition a disk with zfs pool mounted as / .
Here is how my disko config looks:

{ disks ? [ "/dev/vda" ], ... }:
{
  disk = {
    main = {
      type = "disk";
      device = builtins.elemAt disks 0;
      content = {
        type = "gpt";
        partitions = {
          boot = {
            start = "0";
            size = "1M";
            type = "EF02"; # for grub MBR
          };
          ESP = {
            size = "300M";
            content = {
              type = "filesystem";
              format = "vfat";
              mountpoint = "/boot";
            };
          };
          swap = {
              size = "512M";
              content = {
                type = "swap";
                randomEncryption = true;
              };
            };
          zfs = { 
            #start = "300M";
            size = "100%";
            content = {
              type = "zfs";
              pool = "rpool";
            };
          };
        };
      };
    };
  };
  zpool = {
    rpool = {
      type = "zpool";
      mode = "";
      mountpoint = "/";
      rootFsOptions = {
          compression = "zstd-5";
          "com.sun:auto-snapshot" = "false";
        };
      # options.mountpoint = "/";
      datasets = {};
    };
  };
}

However, when performing disk partitioning disko kept creating zpool with mountpoint being set to "/mnt".
I looked into disko sources and found the culprit - disko uses option config.disko.rootMountPoint.
I've tried to set it in my flake the obvious way - disko.rootMountPoint = "/";, however it didn't work, probably because this argument doesn't get propagated from main module into zpool submodule or because disko module gets imported before I override this value 🤷
Luckily, I've found some advice on stackoverflow about overriding arguments passed to a NixOS module through _module.args.config. Here is the excerpt from my flake:

#omitted...
            ({ modulesPath, config, ... }:
              {
                _module.args.config = config // { disko.rootMountPoint = "/"; };
                imports = [
                  (modulesPath + "/installer/scan/not-detected.nix")
                  (modulesPath + "/profiles/qemu-guest.nix")
                  disko.nixosModules.disko
                  ./selectel/configuration.nix
                  sops-nix.nixosModules.sops
                ];
                disko.devices = import selectel/disks.nix {
                  lib = nixpkgs.lib;
                  disks = [ "/dev/sda" ];
                };
#omitted...

It looks kinda ugly. I've been using NixOS for 2 years and this is a first time I've seen such an override hack, and it took me several hours to find a solution for this problem.

Describe the solution you'd like

I'd like that obvious way of setting disko.rootMountPoint = "/"; would work. Or at least this quirk should be documented (and now it is kind of documented, with this issue 🙂 )

Describe alternatives you've considered

Additional context

Mic92 commented

Please re-open this issue in the disko issue tracker: https://github.com/nix-community/disko