I’m trying to define a NixOS module with an option that has a type like this:
test = mkOption {
type = types.oneOf [
(types.submodule {
options = {
type = mkOption {
type = types.enum [ "a" ];
};
a1 = mkOption {
type = types.int;
};
a2 = mkOption {
type = types.int;
};
};
})
(types.submodule {
options = {
type = mkOption {
type = types.enum [ "b" ];
};
b1 = mkOption {
type = types.int;
};
b2 = mkOption {
type = types.int;
};
};
})
];
};
but when I try to provide a value for this like:
test = {
type = "b";
b1 = 3;
b2 = 3;
};
it says that the option test.b1
does not exist. However this does work:
test = {
type = "a";
a1 = 3;
a2 = 3;
};
Also, if I don’t use two submodules but instead a primitive and a submodule like:
test = mkOption {
type = types.oneOf [
types.int
(types.submodule {
options = {
type = mkOption {
type = types.enum [ "b" ];
};
b1 = mkOption {
type = types.int;
};
b2 = mkOption {
type = types.int;
};
};
})
];
};
then a configuration like
test = {
type = "b";
b1 = 3;
b2 = 3;
};
does work!
So it seems like types.oneOf
has problems dealing with multiple submodule options with different sets of attributes. Is there any way around this? Or some other approach to representing mutually exclusive sets of submodule options?