Created
August 16, 2024 08:55
-
-
Save yunfachi/3fc4c74f90c3b0a70ca6ccaaa775240b to your computer and use it in GitHub Desktop.
default value for read only in submodule
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, | |
| config, | |
| ... | |
| }: let | |
| niceSubmodule = lib.types.submodule ({config, ...}: { | |
| options = { | |
| text = | |
| (lib.mkOption { | |
| type = lib.types.str; | |
| readOnly = true; | |
| }) | |
| // ( | |
| if (builtins.any (submodule: submodule ? config.text) config._module.args.moduleType.getSubModules) | |
| then {} | |
| else { | |
| default = "readonly default value"; | |
| } | |
| ); | |
| }; | |
| }); | |
| in { | |
| options = { | |
| original1 = lib.mkOption {type = niceSubmodule;}; | |
| copy1 = lib.mkOption {type = niceSubmodule;}; | |
| original2 = lib.mkOption {type = niceSubmodule;}; | |
| copy2 = lib.mkOption {type = niceSubmodule;}; | |
| }; | |
| config = { | |
| original1 = {text = "orig";}; | |
| copy1 = config.original1; | |
| original2 = {}; | |
| copy2 = config.original2; | |
| }; | |
| }) | |
| ]; | |
| } |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment