Describe the bug
If I have an option with type attrsOf (attrTag { ... }), and use a submodule for the types of the tag, this submodule receives the tag name in name, rather than the parent attribute's name.
I understand this may be expected given how submodulesWith is defined (it has no way to know that last loc is a tag name), however, unless I've missed something obvious, it means that submodules can not get access to the parent attribute's name when used in a tag type.
I've tried to fix this myself but it kept breaking other things, and I haven't yet found a way to overcome this limitation/bug.
Steps To Reproduce
# test.nix
let pkgs = import ./nix {}; lib = pkgs.lib;
in with lib; with lib.types; let
result = evalModules {
modules = [
({ lib, ... }: let
mySubmodule = lib.types.submodule (
{ name, ... }: {
options.myName = lib.mkOption {
default = name;
type = lib.types.str;
};
}
);
in {
options.tagged = lib.mkOption {
default = { foo.myTag = {}; bar.myTag = {}; };
type = attrsOf (lib.types.attrTag {
myTag = lib.mkOption {
description = " a tag";
type = mySubmodule;
};
});
};
options.notTagged = lib.mkOption {
type = attrsOf (mySubmodule);
default = { foo = {}; bar = {}; };
};
})
];
};
in result.config
[nix-shell:/tmp/ghjk5]$ nix-instantiate --eval test.nix --strict --json
{"notTagged": {"bar":{"myName":"bar"},"foo":{"myName":"foo"}},
"tagged":{"bar":{"myTag":{"myName":"myTag"}},"foo":{"myTag":{"myName":"myTag"}}}}
Expected behavior
[nix-shell:/tmp/ghjk5]$ nix-instantiate --eval test.nix --strict --json
{"notTagged": {"bar":{"myName":"bar"},"foo":{"myName":"foo"}},
"tagged":{"bar":{"myTag":{"myName":"bar"}},"foo":{"myTag":{"myName":"foo"}}}}
Notify maintainers
@roberth
@infinisil
Metadata
Tested on nixos-unstable with Nix 2.18
Describe the bug
If I have an option with type
attrsOf (attrTag { ... }), and use a submodule for the types of the tag, this submodule receives the tag name inname, rather than the parent attribute's name.I understand this may be expected given how
submodulesWithis defined (it has no way to know thatlast locis a tag name), however, unless I've missed something obvious, it means that submodules can not get access to the parent attribute's name when used in a tag type.I've tried to fix this myself but it kept breaking other things, and I haven't yet found a way to overcome this limitation/bug.
Steps To Reproduce
Expected behavior
Notify maintainers
@roberth
@infinisil
Metadata
Tested on
nixos-unstablewith Nix 2.18