Context:
- I have home-manager installed as a NixOS module
- In order to have USB block devices auto-mounted, I need to both enable
udiskie
in home-manager andudisks2
in the general system configuration - I don’t want to have two separate options / modules to control the same functionality. More specifically, I want to have a single module with a single option that enables both.
What I have tried:
{
inputs,
lib,
config,
osConfig,
pkgs,
...
}:
{
imports = [
];
options = {
homeConf.udiskie.enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Enable udiskie module";
};
};
osConfig = lib.mkIf config.homeConf.udiskie.enable {
services.udisks2.enable = true;
};
config = lib.mkIf config.homeConf.udiskie.enable {
services.udiskie.enable = true;
};
}
The above fails and I found here on Discourse a good explanation of why.
However, it is not clear to me what would be the correct, idiomatic way to achieve what I want (I can obviously “survive” with two separate modules and options, but it feels brittle, confusing, and overall not a good practice.
The error message does contain a suggestion:
error: Module
/nix/store/pn1mrnqzx9sznd49g99civq00va9jsn6-source/homeManagerModules/udiskie.nix' has an unsupported attribute
osConfig’. This is caused by introducing a top-levelconfig' or
options’ attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: osConfig) into the explicit `config’ attribute.
but if I understand it correctly, it is not applicable in this case, osConfig not being an arbitrary config tree of my creation, but a link to the systemConfig that is exposed by home-manager.
Any help is welcome!