1{ lib, ... }:
2let
3 inherit (lib) types mkOption;
4
5 attrsOfModule = mkOption {
6 type = types.attrsOf (
7 types.submodule {
8 options.bar = mkOption {
9 type = types.int;
10 };
11 }
12 );
13 };
14
15 listOfModule = mkOption {
16 type = types.listOf (
17 types.submodule {
18 options.bar = mkOption {
19 type = types.int;
20 };
21 }
22 );
23 };
24
25in
26{
27 imports = [
28 # Module A
29 ({
30 options.attrsOfModule = attrsOfModule;
31 options.mergedAttrsOfModule = attrsOfModule;
32 options.listOfModule = listOfModule;
33 options.mergedListOfModule = listOfModule;
34 })
35 # Module B
36 ({
37 options.mergedAttrsOfModule = attrsOfModule;
38 options.mergedListOfModule = listOfModule;
39 })
40 # Values
41 # It is important that the value is defined in a separate module
42 # Without valueMeta the actual value and sub-options wouldn't be accessible via:
43 # options.attrsOfModule.type.getSubOptions
44 ({
45 attrsOfModule = {
46 foo.bar = 42;
47 };
48 mergedAttrsOfModule = {
49 foo.bar = 42;
50 };
51 })
52 (
53 { options, ... }:
54 {
55 config.listOfModule = [
56 {
57 bar = 42;
58 }
59 ];
60 config.mergedListOfModule = [
61 {
62 bar = 42;
63 }
64 ];
65 # Result options to expose the list module to bash as plain attribute path
66 options.listResult = mkOption {
67 default = (builtins.head options.listOfModule.valueMeta.list).configuration.options.bar.value;
68 };
69 options.mergedListResult = mkOption {
70 default = (builtins.head options.mergedListOfModule.valueMeta.list).configuration.options.bar.value;
71 };
72 }
73 )
74 ];
75}