Created
August 26, 2025 18:32
-
-
Save yunfachi/c38e0fe9ccdcb8c9ac6ad55094c9d815 to your computer and use it in GitHub Desktop.
strange behavior of the config argument in submodule modules when using apply
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (import <nixpkgs/lib>).evalModules { | |
| modules = [ | |
| ( | |
| { lib, ... }: | |
| { | |
| options = { | |
| someOption = lib.mkOption { | |
| default = { | |
| foo = { }; | |
| }; | |
| apply = xs: builtins.mapAttrs (name: x: x // { inherit name; }) xs; | |
| type = lib.types.attrsOf ( | |
| lib.types.submodule ( | |
| { config, ... }: | |
| { | |
| options = { | |
| name = lib.mkOption { | |
| type = lib.types.str; | |
| default = "defaultName"; | |
| }; | |
| nameClone = lib.mkOption { | |
| type = lib.types.str; | |
| default = config.name; | |
| }; | |
| }; | |
| } | |
| ) | |
| ); | |
| }; | |
| }; | |
| } | |
| ) | |
| ]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nix eval -f ./default.nix config |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually,
applydidn't run on the input module but on the output value, the result ofevalModules… I should have guessed that. And to solve this, there's already a builtinnameargument in submodules insideattrsOf