[Nix-dev] nixos modules: Setting attrsOf sub-options
Rickard Nilsson
rickard.nilsson at telia.com
Wed Jul 1 00:31:24 CEST 2015
Hi,
I'm stuck on the following problem with the NixOS module system:
Say I have an option definition like this:
let
subOpts = { ... }: {
options = {
opt1 = mkOption { ... };
opt2 = mkOption { ... };
};
};
in {
options = {
top = mkOption {
type = with types; attrsOf (submodule subOpts);
default = {};
};
};
}
Then I use it like this:
top = {
one.opt1 = ...;
two.opt1 = ...;
};
And now I want to set top.*.opt2 in a separate module, based on the
existing attributes. Essentially something like this:
top = mkMerge (
map (a: { ${a}.opt2 = f a; }) (attrNames config.top)
)
But of course, the above results in an infinite recursion since I'm
using config.top in its own definition.
What I want is simply to be able to plug in a module that defines some
sub-options without having explicit knowledge about the attribute set.
Does anyone know a way of achieveing this?
/ Rickard
More information about the nix-dev
mailing list