Skip to content

Module system types.attrTag shadows name argument for inner submodules #351888

@8aed

Description

@8aed

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: module systemAbout "NixOS" module system internals

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions