You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* lib/options: add moduleOptions
* lib/options!: improve moduleOptions
allows to not pass the `args` variable if they are needed inside and the
arguments are closer to the scope
* docs/src/options/introduction: add moduleOptions
* docs/src/ru/options/introduction: add moduleOpt...
...ions
* docs/src/options/introduction: add semicolon
* docs/src: fix second moduleOptions example
i actually forgot that only `options` attribute can be assigned to a
function and not something nested 💀
* docs/src: fix indent in moduleOptions examples
-`moduleOptions <opts> <args>` - creates an attribute set with `<opts>` for the current module path. Usually, you need to use the module `name` once again to define all options, but this wrapper does this automatically. `<args>` is a set with [passed arguments](/modules/structure#passed-arguments). If `<opts>` is a function, then `<args>` set is automatically passed to it. See the example:
56
+
57
+
```nix
58
+
# current module's name is "programs.category.example".
59
+
60
+
# if `singleEnableOption` is not enough:
61
+
options = with delib; moduleOptions {
62
+
enable = boolOption true;
63
+
device = strOption "desktop";
64
+
};
65
+
66
+
# `options` block above is the same as:
67
+
options.programs.category.example = with delib; {
68
+
enable = boolOption true;
69
+
device = strOption "desktop";
70
+
};
71
+
72
+
# but if `singleCascadeEnableOption` is not enough:
73
+
options = with delib; moduleOptions ({ parent, ... }: {
74
+
enable = boolOption parent.enable;
75
+
device = strOption "desktop";
76
+
}); # notice the parentheses
77
+
78
+
# once again, `options` block above is the same as:
79
+
options = with delib; { parent, ... }: {
80
+
programs.category.example = {
81
+
enable = boolOption parent.enable;
82
+
device = strOption "desktop";
83
+
};
84
+
};
85
+
```
86
+
55
87
The list of current options can be found in the source code: [github:yunfachi/denix?path=lib/options.nix](https://github.com/yunfachi/denix/blob/master/lib/options.nix)
-`moduleOptions <opts> <args>` - создаёт attribute set с `<opts>` для пути текущего модуля. Обычно, необходимо использовать `name` ещё раз, чтобы обозначить опции, но эта функция делает это автоматически. `<args>` это набор [передаваемых аргументов](/ru/modules/structure#passed-arguments). Если `<opts>` это функция, тогда `<args>` является её аргументом. Пример:
56
+
57
+
```nix
58
+
# имя текущего модуля это "programs.category.example".
59
+
60
+
# если не хватает `singleEnableOption`:
61
+
options = with delib; moduleOptions {
62
+
enable = boolOption true;
63
+
device = strOption "desktop";
64
+
};
65
+
66
+
# блок опций выше эквивалентен блоку ниже:
67
+
options.programs.category.example = with delib; {
68
+
enable = boolOption true;
69
+
device = strOption "desktop";
70
+
};
71
+
72
+
# а если не хватает `singleCascadeEnableOption`:
73
+
options = with delib; moduleOptions ({ parent, ... }: {
74
+
enable = boolOption parent.enable;
75
+
device = strOption "desktop";
76
+
}); # обратите внимание на скобки
77
+
78
+
# снова, блок опций выше эквивалентен блоку ниже:
79
+
options = with delib; { parent, ... }: {
80
+
programs.category.example = {
81
+
enable = boolOption parent.enable;
82
+
device = strOption "desktop";
83
+
};
84
+
};
85
+
```
86
+
55
87
Список актуальных опций можно найти в исходном коде: [github:yunfachi/denix?path=lib/options.nix](https://github.com/yunfachi/denix/blob/master/lib/options.nix)
0 commit comments