mkMerge as the body of a configuration?

NixOS modules have three (main) sections: imports, options and config. And mkMerge only works on the config section, as do mkIf, mkForce and co. So you can’t use any of these modifiers on the imports or the options section (and if you try, you’ll get errors as if imports and options are missing options).

Note however that if a NixOS module doesn’t have either a config or options section, the whole thing is assumed to be a config section. So e.g. this works:

{ lib, ... }: mkMerge [{
  environment.systemPackages = [ ... ];
}]

Because it implicitly gets turned into

{ lib, ... }: {
  config = mkMerge [{
    environment.systemPackages = [ ... ];
  }];
}
12 Likes