nix-community / disko

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

NixOS modules with disko config don't merge #678

Open jmbaur opened 5 months ago

jmbaur commented 5 months ago

I would expect setting disko config in two different NixOS modules would properly merge together. A minimal reproducer is the config below, where I would expect evaluating it to fail with conflicting definitions for mountpoint, but rather the mountpoint ends up getting set to /boot.

let
  nixpkgs = builtins.getFlake "github:nixos/nixpkgs/nixos-unstable";
  disko = builtins.getFlake "github:nix-community/disko/master";
in
(nixpkgs.lib.nixosSystem {
  modules = [
    disko.nixosModules.default
    { nixpkgs.hostPlatform = "x86_64-linux"; }
    {
      disko.devices.disk.disk0 = {
        device = "/dev/foobar";
        type = "disk";
        content = {
          type = "gpt";
          partitions.foo = {
            type = "EF00";
            content = {
              type = "filesystem";
              format = "vfat";
              mountpoint = "/boot";
            };
          };
        };
      };
    }
    {
      disko.devices.disk.disk0 = {
        type = "disk";
        content = {
          type = "gpt";
          partitions.foo = {
            type = "EF00";
            content = {
              type = "filesystem";
              mountpoint = null;
            };
          };
        };
      };
    }
  ];
}).config.disko.devices.disk.disk0.content.partitions.foo.content.mountpoint
Lassulus commented 5 months ago

but you have conflicting definitions? not sure whats the error here? what should happen otherwise?

jmbaur commented 5 months ago

That's the thing, I would expect that evaluating the above expression would error out due to the fact that there are conflicting definitions, but it does not.

Result from evaluation (where test.nix contains the contents as posted above):

~ > nix eval -f test.nix
"/boot"
jmbaur commented 5 months ago

Seems related: https://github.com/NixOS/nixpkgs/pull/254790#discussion_r1358073458