I’m trying to write a nixosModule flake with different options set in different files to be imported in imports
. I’m not sure if what I’m going for is simply not possible or not the ideal way of doing in nixos modules.
Let’s say I have a tree like
./
├── subdir/
│ └── submodule.nix
└── flake.nix
in subdir/submodule
I declared
{config, ...}: {
options.mymodule.submodule = {
enable = lib.mkEnableOption "submodule";
};
config = lib.mkIf config.mymodule.submodule.enable {
# config here ....
};
}
in flake.nix
I’m trying to set the submodule option in it’s config
{
outputs = {...}: {
nixosModules.default =
{ config, lib, ... }: {
options.mymodule = {
enable = lib.mkEnableOption "module";
};
config = lib.mkIf config.mymodule.enable {
# apparently this does not work
config.mymodule.submodule = true;
# ... other configuration done here
};
imports = [
./subdir/submodule.nix
];
};
};
}
I know I could probably rearrange into something without create nested config
but the idea is to compose options and reference the ones declared in other files so it can be more elegant. I guess I’m trying resemble something like a general purpose language module system but this may impossible here. Is it?
Right now I’m only getting errors like error: The option 'config' does not exist.