Skip to content

Can't get a vmWithDisko with btrfs home subvolume to work #1157

@Wunst

Description

@Wunst

I've been in the process of rewriting my NixOS config with disko, and wanted to test/iterate on it using a vmWithDisko. However, my setup seems to cause problems with a VM.

  • Initially, when only creating a /home subvolume, users were created before mounting subvolumes, resulting in a /home/ben directory on the root subvolume, but an empty /home subvolume mounted. As a consequence, the user now has no home directory mounted at all.
  • After adding the /home/ben sub-subvolume (seen below, as taken from the examples), /home/ben exists but is owned by root, and the user can't write to their own homedir.

Unsure what to do, I have previously installed with disko on bare metal, where this problem doesn't exist, but vmWithDisko seems to first do a complete nixos-install, then mount subvolumes, while disko-install does it the other (and more reasonable) way around.

How can I get vmWithDisko to either

  • first mount the /home subvolume before creating user directories, or
  • chown the /home/ben subvolume to my user?

Relevant disko and user config

{
  disko.devices = {
    disk = {
      main = {
        type = "disk";
        device = "/dev/nvme0n1";
        content = {
          type = "gpt";
          partitions = {
            # Boot partition.
            boot = {
              priority = 1;
              type = "EF00"; # EFI system partition.
              start = "1M";
              end = "512M";
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot";
                mountOptions = [ "umask=0077" ];
              };
            };

            # Encrypted btrfs main partition.
            luks = {
              size = "100%";
              content = {
                type = "luks";
                name = "crypt-main";
                settings = {
                  allowDiscards = true; # Pass trim commands to disk.
                };
                
                # btrfs main volume.
                content = {
                  type = "btrfs";
                  extraArgs = [ "-f" ];
                  subvolumes = {
                    "/rootfs" = {
                      mountpoint = "/";
                    };

                    "/var" = {
                      mountpoint = "/var";
                      mountOptions = [ "compress=zstd" ];
                    };

                    "/home" = {
                      mountpoint = "/home";
                      mountOptions = [ "compress=zstd" ];
                    };
                    "/home/ben" = {};

                    "/nix" = {
                      mountpoint = "/nix";
                      mountOptions = [ "compress=zstd" "noatime" ];
                    };
                  };
                };
              };
            };
          };
        };
      };
    };

    nodev = {
      "/tmp" = {
        fsType = "tmpfs";
        mountOptions = [ "size=200M" ];
      };
    };
  };

  # - snip -

  users.users.ben = {
    isNormalUser = true;
    description = "Ben";
    shell = pkgs.zsh;
    extraGroups = [
      "wheel" # Allow use of sudo.
      "networkmanager"
    ];
  };
}

Running the VM with

$ nix run -L .#nixosConfigurations.wunstpc.config.system.build.vmWithDisko

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions