|
3 | 3 | inherit (lib) mkOption types mapAttrs warn;
|
4 | 4 | inherit (types) deferredModule;
|
5 | 5 |
|
6 |
| - nodesConfigCompat = k: n: |
7 |
| - n // { |
8 |
| - config = |
9 |
| - warn |
10 |
| - "The module parameter `nodes.${lib.strings.escapeNixIdentifier k}.config' has been renamed to `nodes.${lib.strings.escapeNixIdentifier k}'" |
11 |
| - n; |
12 |
| - options = throw "nodes.<name>.options is not available anymore. You can access options information by writing a node-level module that extracts the options information and assigns it to a new option of your choosing."; |
13 |
| - }; |
14 |
| - |
15 | 6 | deploymentDefault = {
|
16 | 7 | imports = [ ./resource.nix ./default-deployment.nix ];
|
17 | 8 | inherit (config) deployment;
|
|
55 | 46 | lock = mkOption {
|
56 | 47 | # TBD
|
57 | 48 | type = types.raw;
|
58 |
| - default = {}; |
| 49 | + default = { }; |
59 | 50 | };
|
60 | 51 | };
|
61 | 52 | resources = mkOption {
|
|
64 | 55 | specialArgs.defineResource = resName: resMod: {
|
65 | 56 | options.${resName} = mkOption {
|
66 | 57 | default = { };
|
67 |
| - type = types.attrsOf (types.submodule ({ name, ... }: { |
68 |
| - imports=[ |
| 58 | + type = types.attrsOf (types.submoduleWith { |
| 59 | + specialArgs = { |
| 60 | + inherit (config) resources; |
| 61 | + inherit (config.deployment) uuid; |
| 62 | + }; |
| 63 | + modules = [ |
69 | 64 | deploymentDefault
|
70 | 65 | config.network.resourcesDefaults
|
71 | 66 | resMod
|
72 |
| - ]; |
73 |
| - _module.args = { |
74 |
| - inherit (config) resources; |
75 |
| - nodes = # inherit nodes, essentially |
76 |
| - lib.mapAttrs |
77 |
| - (nodeName: node: |
78 |
| - lib.mapAttrs |
79 |
| - (key: lib.warn "Resource ${name} accesses nodes.${nodeName}.${key}, which is deprecated. Use the equivalent option instead: nodes.${nodeName}.${{ |
| 67 | + ({ name, ... }: { |
| 68 | + _module.args.nodes = # inherit nodes, essentially |
| 69 | + lib.mapAttrs |
| 70 | + (nodeName: node: |
| 71 | + lib.mapAttrs |
| 72 | + (key: lib.warn "Resource ${name} accesses nodes.${nodeName}.${key}, which is deprecated. Use the equivalent option instead: nodes.${nodeName}.${{ |
80 | 73 | nixosRelease = "config.system.nixos.release and make sure it is set properly";
|
81 | 74 | publicIPv4 = "config.networking.publicIPv4";
|
82 | 75 | }.${key} or "config.deployment.${key}"}.")
|
83 |
| - config.nodes.${nodeName} |
84 |
| - // node) |
85 |
| - config.nodes; |
86 |
| - }; |
87 |
| - })); |
| 76 | + config.resources.machines.${nodeName} |
| 77 | + // node) |
| 78 | + config.resources.machines; |
| 79 | + }) |
| 80 | + ]; |
| 81 | + }); |
88 | 82 | };
|
89 | 83 | };
|
90 | 84 | modules = [
|
|
93 | 87 | imports = [
|
94 | 88 | (defineResource "sshKeyPairs" ./ssh-keypair.nix)
|
95 | 89 | (defineResource "commandOutput" ./command-output.nix)
|
| 90 | + (defineResource "machines" ./options.nix) |
96 | 91 | ];
|
97 |
| - options.machines = lib.mkOption { |
98 |
| - description = '' |
99 |
| - An alias for the `nodes`. |
100 |
| - ''; |
101 |
| - readOnly = true; |
102 |
| - type = types.raw; |
103 |
| - }; |
104 |
| - config = { |
105 |
| - machines = config.nodes; |
106 |
| - _module.check = false; |
| 92 | + options.machines = mkOption { |
| 93 | + description = "The NixOS configurations for the nodes in the network."; |
| 94 | + # on 1st eval nodes is not read and on 2nd lib is taken from config.nixpkgs |
| 95 | + type = types.attrsOf (lib.nixosSystem or (import /${config.nixpkgs}/nixos/lib/eval-config.nix) { |
| 96 | + inherit system lib; |
| 97 | + specialArgs = config.network.nodesExtraArgs; |
| 98 | + modules = [ config.defaults { _module.check = true; } ]; |
| 99 | + }).type; |
107 | 100 | };
|
| 101 | + config._module.check = false; |
108 | 102 | })
|
109 | 103 | ];
|
110 | 104 | };
|
111 | 105 | };
|
112 | 106 | # Compute the definitions of the machines.
|
113 |
| - nodes = mkOption { |
114 |
| - description = "The NixOS configurations for the nodes in the network."; |
115 |
| - default = { }; |
116 |
| - # on 1st eval nodes is not read and on 2nd lib is taken from config.nixpkgs |
117 |
| - type = types.attrsOf (lib.nixosSystem or (import /${config.nixpkgs}/nixos/lib/eval-config.nix) { |
118 |
| - inherit system lib; |
119 |
| - specialArgs = { |
120 |
| - inherit (config) resources; |
121 |
| - nodes = mapAttrs nodesConfigCompat config.nodes; |
122 |
| - } // config.network.nodesExtraArgs; |
123 |
| - modules = [ |
124 |
| - config.defaults |
125 |
| - # Make NixOps's deployment.* options available. |
126 |
| - ./options.nix |
127 |
| - deploymentDefault |
128 |
| - ]; |
129 |
| - }).type; |
130 |
| - }; |
131 | 107 | defaults = mkOption {
|
132 | 108 | type = deferredModule;
|
133 | 109 | default = { };
|
|
137 | 113 | };
|
138 | 114 | };
|
139 | 115 | config = {
|
140 |
| - nodes = |
| 116 | + resources.machines = |
141 | 117 | let
|
142 | 118 | nodes = removeAttrs config (builtins.attrNames options);
|
143 | 119 | in
|
|
0 commit comments