Module arguments are not intended to be used like this.
I’m not sure why it fails; presumably this is caused by the NixOS module system not considering that arguments may not be set at all in _module.args
when they are asked for in module arguments - yes, the ?
does set default values in function arguments, but in this case the caller also looks for those names in _module.args
, and when that is not set it might break if it’s not made to consider unset arguments.
It’s odd, because I’ve definitely seen pkgs ? <something>
before. Perhaps it would work if cursorThemePackage
was set to null
in _module.args
?
Anyway, you’re abusing _module.args
and I won’t stand for this! I’m assuming you’re trying to set up multiple nixosConfigurations
, and you want to set different cursorThemePackage
s depending on which host you’re deploying. This is where you should be using the NixOS module system, not hacking around with function args.
The pattern for this is to write a custom option, i.e. something like:
{lib, pkgs, ...}: {
options.local.cursorThemePackage = lib.mkOption {
default = pkgs.capitaine-cursors;
type = lib.types.package;
};
}
You then make sure this module is included in your evaluation somewhere (add it to modules
or the imports
of ./mymodule/default.nix
or something), and then you can refer to config.local.cursorThemePackage
wherever you want to use it.
You can also override it just using any module, e.g.:
modules= [
./mymodule
{
local.cursorThemePackage = pkgs.comixcursors;
}
];
But you can also set that in a host-specific module (e.g. ./hosts/mypc
), which is a much cleaner way of setting these host-specific things that enables separating out things far more efficiently because you don’t need to define custom options or module args for everything (for e.g. multiple hardware-configuration.nix
files, or setting up multiple machines with different GPUs).
This is of course assuming there isn’t already an option for this, how do you currently use that value?