Skip to content

Commit 4ba945b

Browse files
committed
net.nix: removed nodes options, all network nodes are now defined in resources.machines
1 parent 891724a commit 4ba945b

File tree

9 files changed

+58
-111
lines changed

9 files changed

+58
-111
lines changed

doc/guides/deploy-without-root.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Edit your nixops.nix to specify the machine's
6969
{
7070
network.description = "Non-root deployment";
7171
72-
nodes.hermes =
72+
resources.machines.hermes =
7373
{ resources, ... }:
7474
{
7575
deployment.targetUser = "deployer";

doc/manual/nixops.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ Consider the following deployment specification (``servers.nix``):
10801080
services.httpd.adminAddr = "foo@example.org";
10811081
});
10821082

1083-
in { nodes = listToAttrs (map makeMachine (range 1 nrMachines)); }
1083+
in { resources.machines = listToAttrs (map makeMachine (range 1 nrMachines)); }
10841084

10851085
This specifies a network of nrMachines identical VirtualBox VMs that run
10861086
the Apache web server if active is set. To create 10 machines without

doc/manual/overview.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and leave ``deployment.targetEnv`` undefined. See
1818
::
1919

2020
{
21-
nodes.webserver =
21+
resources.machines.webserver =
2222
{ config, pkgs, ... }:
2323
{ deployment.targetHost = "1.2.3.4";
2424
};
@@ -87,12 +87,12 @@ example:
8787
imports = [ ./common.nix ];
8888
};
8989

90-
nodes.machine = { ... }: {};
90+
resources.machines.machine = { ... }: {};
9191
}
9292

9393
Each attribute is explained below:
9494

95-
``nodes.*``
95+
``resources.machines.*``
9696
Applies the given NixOS configuration to the corresponding node.
9797

9898
``defaults``
@@ -121,7 +121,7 @@ Here is an example of a network with network arguments:
121121
{ maintenance ? false
122122
}:
123123
{
124-
nodes.machine =
124+
resources.machines.machine =
125125
{ config, pkgs, ... }:
126126
{ services.httpd.enable = maintenance;
127127
...
@@ -175,7 +175,7 @@ Add a key to a machine like so.
175175
::
176176

177177
{
178-
nodes.machine =
178+
resources.machines.machine =
179179
{ config, pkgs, ... }:
180180
{
181181
deployment.keys.my-secret.text = "shhh this is a secret";
@@ -211,7 +211,7 @@ and otherwise inactive when the key is absent. See
211211
::
212212

213213
{
214-
nodes.machine =
214+
resources.machines.machine =
215215
{ config, pkgs, ... }:
216216
{
217217
deployment.keys.my-secret.text = "shhh this is a secret";
@@ -246,7 +246,7 @@ This is possible by using the extra NixOS module input ``nodes``.
246246

247247
{
248248
network.description = "Gollum server and reverse proxy";
249-
nodes = {
249+
resources.machines = {
250250

251251
gollum =
252252
{ config, pkgs, ... }:

doc/overview.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ machine, and leave ``deployment.targetEnv`` undefined. See
2121
::
2222

2323
{
24-
nodes.webserver =
24+
resources.machines.webserver =
2525
{ config, pkgs, ... }:
2626
{ deployment.targetHost = "1.2.3.4";
2727
};
@@ -92,7 +92,7 @@ example:
9292
imports = [ ./common.nix ];
9393
};
9494

95-
nodes.machine = { ... }: {};
95+
resources.machines.machine = { ... }: {};
9696
}
9797

9898
Each attribute is explained below:
@@ -122,7 +122,7 @@ Here is an example of a network with network arguments:
122122
{ maintenance ? false
123123
}:
124124
{
125-
nodes.machine =
125+
resources.machines.machine =
126126
{ config, pkgs, ... }:
127127
{ services.httpd.enable = maintenance;
128128
...
@@ -175,7 +175,7 @@ Add a key to a machine like so.
175175
::
176176

177177
{
178-
nodes.machine =
178+
resources.machines.machine =
179179
{ config, pkgs, ... }:
180180
{
181181
deployment.keys.my-secret.text = "shhh this is a secret";
@@ -216,7 +216,7 @@ and otherwise inactive when the key is absent. See
216216
::
217217

218218
{
219-
nodes.machine =
219+
resources.machines.machine =
220220
{ config, pkgs, ... }:
221221
{
222222
deployment.keys.my-secret.text = "shhh this is a secret";
@@ -250,8 +250,8 @@ This is possible by using the extra NixOS module input ``nodes``.
250250

251251
{
252252
network.description = "Gollum server and reverse proxy";
253-
254-
nodes = {
253+
254+
resources.machines = {
255255
gollum =
256256
{ config, pkgs, ... }:
257257
{

doc/release-notes/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Release 2.0
1818

1919
- Now the network specification is using the module system from ``nixpkgs.lib``
2020
- Now network specification files can import other files via ``imports``.
21-
- We have a ``nodes.*`` option where we put every NixOS configuration for the configured nodes. We suggest to use it instead of defining nodes in the top level.
21+
- We have a ``resources.machines.*`` option where we put every NixOS configuration for the configured nodes. We suggest to use it instead of defining nodes in the top level.
2222

2323
- Removed NixOS Options
2424

nix/eval-machine-info.nix

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let
2323
./net.nix mod flakeExpr
2424
{
2525
nixpkgs = lib.mkDefault flake.inputs.nixpkgs or nixpkgsBoot;
26-
network.nodesExtraArgs = { inherit uuid deploymentName; };
26+
network.nodesExtraArgs = { inherit deploymentName; };
2727
# Make NixOps's deployment.* options available.
2828
deployment = {
2929
name = deploymentName;
@@ -46,19 +46,21 @@ in rec {
4646
inherit nixpkgs;
4747
net = evalMod lib {
4848
resources.imports = pluginResourceModules;
49-
network.resourcesDefaults._module.args = { inherit pkgs uuid; };
49+
network.resourcesDefaults._module.args.pkgs = lib.mkOptionDefault pkgs;
5050
};
5151

5252
# for backward compatibility
53-
network = lib.mapAttrs (n: v: [v]) net.config;
53+
network = lib.mapAttrs (n: v: [ v ]) net.config;
5454
networks = [ net.config ];
5555
defaults = [ net.config.defaults ];
5656
nodes = #TODO: take options and other modules outputs for each node
57-
lib.mapAttrs (n: v: {
57+
lib.mapAttrs
58+
(n: v: {
5859
config = v;
59-
options = net.options.nodes.${n};
60+
options = net.options.resources.machines.${n};
6061
inherit (v.nixpkgs) pkgs;
61-
}) net.config.nodes;
62+
})
63+
net.config.resources.machines;
6264

6365
# ./resource.nix is imported in resource opt but does not define resource types
6466
# we have to remove those entries as they do not otherwise conform to the resource schema

nix/machine-resource.nix

-16
This file was deleted.

nix/net.nix

+30-54
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ let
33
inherit (lib) mkOption types mapAttrs warn;
44
inherit (types) deferredModule;
55

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-
156
deploymentDefault = {
167
imports = [ ./resource.nix ./default-deployment.nix ];
178
inherit (config) deployment;
@@ -55,7 +46,7 @@ in
5546
lock = mkOption {
5647
# TBD
5748
type = types.raw;
58-
default = {};
49+
default = { };
5950
};
6051
};
6152
resources = mkOption {
@@ -64,27 +55,30 @@ in
6455
specialArgs.defineResource = resName: resMod: {
6556
options.${resName} = mkOption {
6657
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 = [
6964
deploymentDefault
7065
config.network.resourcesDefaults
7166
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}.${{
8073
nixosRelease = "config.system.nixos.release and make sure it is set properly";
8174
publicIPv4 = "config.networking.publicIPv4";
8275
}.${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+
});
8882
};
8983
};
9084
modules = [
@@ -93,41 +87,23 @@ in
9387
imports = [
9488
(defineResource "sshKeyPairs" ./ssh-keypair.nix)
9589
(defineResource "commandOutput" ./command-output.nix)
90+
(defineResource "machines" ./options.nix)
9691
];
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;
107100
};
101+
config._module.check = false;
108102
})
109103
];
110104
};
111105
};
112106
# 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-
};
131107
defaults = mkOption {
132108
type = deferredModule;
133109
default = { };
@@ -137,7 +113,7 @@ in
137113
};
138114
};
139115
config = {
140-
nodes =
116+
resources.machines =
141117
let
142118
nodes = removeAttrs config (builtins.attrNames options);
143119
in

nix/options.nix

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
{ name, config, lib, ... }:
2-
32
with lib;
4-
5-
let
6-
7-
cfg = config.deployment;
8-
9-
in
10-
113
{
12-
13-
imports =
14-
[
15-
./keys.nix
16-
];
17-
18-
4+
imports = [ ./keys.nix ];
195
options = {
20-
216
deployment.targetEnv = mkOption {
227
default = "none";
238
example = "ec2";
@@ -74,7 +59,7 @@ in
7459

7560
deployment.sshOptions = mkOption {
7661
type = types.listOf types.str;
77-
default = [];
62+
default = [ ];
7863
description = ''
7964
Extra options passed to the OpenSSH client verbatim, and are not executed by a shell.
8065
'';
@@ -109,7 +94,7 @@ in
10994
};
11095

11196
deployment.owners = mkOption {
112-
default = [];
97+
default = [ ];
11398
type = types.listOf types.str;
11499
description = ''
115100
List of email addresses of the owners of the machines. Used

0 commit comments

Comments
 (0)