Fprintd and xdg portal can't be separated in `configuration.nix`

i’m trying to refactor configuration.nix so that laptop-only configs aren’t applied on other types of devices. the embedded version works, but when fprintd configs are moved into the [unique] set, i got this error:

Failed assertions:
- Setting xdg.portal.enable to true requires a portal implementation in xdg.portal.extraPortals such as xdg-desktop-portal-gtk or xdg-desktop-portal-kde.

can anyone explain what happened in such situation, and if there’s anyway for me to work around the error without having to specify xdg.portal.extraPortals? many thanks.

The // (attribute update set operator) is not recursive.

And since

{
  xdg.portal.enable = true;
  services.desktopManager.plasma6.enable = true;
} // {
  services.fprintd.enable = true;
}

is a syntactic sugar for

{
  xdg = {
    portal = {
      enable = true;
    };
  };
  services = {
    desktopManager = {
      plasma6 = {
        enable = true;
      };
    };
  };
} // {
  services = {
    fprintd = {
      enable = true;
    };
  };
}

it will evaluate to

{
  xdg = {
    portal = {
      enable = true;
    };
  };
  services = {
    fprintd = {
      enable = true;
    };
  };
}
3 Likes

To add to that: What you want to use instead in a module system context is lib.mkMerge.

2 Likes

Additionally, optional settings based on hostname will quickly get unwieldy and difficult to track/debug.
I’d recommend having a separate “entry point” per host, and all hosts could use the files containing common config in their imports.

2 Likes

may i ask where to find documentation for lib.mkMerge and the like? i searched for it in Nixpkgs Reference Manual but none matched.

As this is technically a feature of the NixOS module system, it’s apparently in the NixOS manual instead:

https://nixos.org/manual/nixos/stable/#sec-option-definitions-merging

1 Like