Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eval-machine-info.nix: ported to modules #1508

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4853721
eval-machine-info.nix: ported to modules
pasqui23 Feb 20, 2022
8d067ed
Fixing resources submodules
pasqui23 Feb 22, 2022
845e9c0
Fixing nodes evaluation
pasqui23 Feb 23, 2022
a652e29
Added defaults to resources
pasqui23 Feb 23, 2022
1f62334
eval-machine-info: fix parenthesis
pasqui23 Mar 6, 2022
da8126d
defaults.type = defferredModules
pasqui23 Mar 11, 2022
81282e8
network.storage option is now defined
pasqui23 Mar 13, 2022
2b036d2
Split most of net's module system in separate file
pasqui23 Mar 13, 2022
33af8f8
Updated docs to use new nodes option
pasqui23 Mar 13, 2022
bda08d7
remove indentation from net expression
pasqui23 Mar 13, 2022
82934a2
eval-machine-info: Allow flakeUri to be unset
roberth Apr 6, 2022
8d1cb81
eval-machine-info: Backcompat for nodes.<name>.config parameter
roberth Apr 6, 2022
148270e
nix/net.nix: Adjust legacy node notation message
roberth Apr 6, 2022
51bdc5c
eval-machine-info: Make resources proper submodules
roberth Apr 6, 2022
a2724b1
eval-machine-info: Re-add machine resource
roberth Apr 7, 2022
4d27834
merge
pasqui23 May 15, 2022
5a225f7
Adding defineResource to quickly define a resource type
pasqui23 May 15, 2022
115d0a6
net.nix: deferredModules now import a single module
pasqui23 Jun 14, 2022
533d348
resource filtering now done in eval-machine.nix to make mypy-rachet.p…
pasqui23 Jun 19, 2022
7eba0d0
net.nix: deferredModules has been merged in nixpkgs
pasqui23 Dec 1, 2022
5182ff4
eval-machine-info: a bit of cleanup
pasqui23 Feb 2, 2023
9c534fe
eval-machine-info: move net.nix import in 1st module evaluation
pasqui23 Feb 4, 2023
0ca1faa
net.nix: allow no nodes net
pasqui23 Feb 4, 2023
38f27a5
net.nix: unify source of default hostname
pasqui23 Feb 4, 2023
49d5f5c
eval-machine-info: removing problematic resources entries better
pasqui23 Feb 4, 2023
19e74b8
simplified resource defaults logic
pasqui23 Feb 4, 2023
736d837
clarified logic defaultDeploymentModule
pasqui23 Feb 4, 2023
7b755c7
moving resource defaults in net.nix
pasqui23 Feb 4, 2023
f72d03a
Fix typo
pasqui23 Feb 5, 2023
9c9423e
net.nix: shorten defineResource definition
pasqui23 Feb 5, 2023
c796a68
eval-machines:inportedOptions eval earlier
pasqui23 Feb 5, 2023
b3a578b
eval-machine-info: rm unused bindings
pasqui23 Feb 5, 2023
5f5b25b
eval-machine-info: Fix typo
roberth Mar 1, 2023
553fa63
eval-machine-info: Add resource.nix to legacy resources
roberth Mar 1, 2023
8fd2cff
net.nix: Add placeholder for network.lock
roberth Mar 1, 2023
b3c793c
net.nix: Turn resources.machines into an alias for the nodes
roberth Mar 1, 2023
891724a
net.nix: Add TODO to consider for improving error messages
roberth Mar 1, 2023
12f87a4
net.nix: removed nodes options, all network nodes are now defined in …
pasqui23 Mar 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.formatting.provider": "black"
}
2 changes: 1 addition & 1 deletion doc/guides/deploy-without-root.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Edit your nixops.nix to specify the machine's
{
network.description = "Non-root deployment";

hermes =
resources.machines.hermes =
{ resources, ... }:
{
deployment.targetUser = "deployer";
Expand Down
6 changes: 3 additions & 3 deletions doc/manual/nixops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,9 @@ Consider the following deployment specification (``servers.nix``):

::

{ nrMachines, active }:
{ nrMachines, active, lib }:

with import <nixpkgs/lib>;
with lib;

let

Expand All @@ -1080,7 +1080,7 @@ Consider the following deployment specification (``servers.nix``):
services.httpd.adminAddr = "[email protected]";
});

in listToAttrs (map makeMachine (range 1 nrMachines))
in { resources.machines = listToAttrs (map makeMachine (range 1 nrMachines)); }

This specifies a network of nrMachines identical VirtualBox VMs that run
the Apache web server if active is set. To create 10 machines without
Expand Down
70 changes: 37 additions & 33 deletions doc/manual/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and leave ``deployment.targetEnv`` undefined. See
::

{
webserver =
resources.machines.webserver =
{ config, pkgs, ... }:
{ deployment.targetHost = "1.2.3.4";
};
Expand Down Expand Up @@ -87,11 +87,14 @@ example:
imports = [ ./common.nix ];
};

machine = { ... }: {};
resources.machines.machine = { ... }: {};
}

Each attribute is explained below:

``resources.machines.*``
Applies the given NixOS configuration to the corresponding node.

``defaults``
Applies given NixOS module to all machines defined in the network.

Expand All @@ -118,7 +121,7 @@ Here is an example of a network with network arguments:
{ maintenance ? false
}:
{
machine =
resources.machines.machine =
{ config, pkgs, ... }:
{ services.httpd.enable = maintenance;
...
Expand Down Expand Up @@ -172,7 +175,7 @@ Add a key to a machine like so.
::

{
machine =
resources.machines.machine =
{ config, pkgs, ... }:
{
deployment.keys.my-secret.text = "shhh this is a secret";
Expand All @@ -181,7 +184,7 @@ Add a key to a machine like so.
deployment.keys.my-secret.permissions = "0640";
};
}


This will create a file ``/run/keys/my-secret`` with the specified
contents, ownership, and permissions.
Expand All @@ -208,7 +211,7 @@ and otherwise inactive when the key is absent. See
::

{
machine =
resources.machines.machine =
{ config, pkgs, ... }:
{
deployment.keys.my-secret.text = "shhh this is a secret";
Expand All @@ -223,7 +226,7 @@ and otherwise inactive when the key is absent. See
};
};
}


These dependencies will ensure that the service is only started when the
keys it requires are present. For example, after a reboot, the services
Expand All @@ -243,33 +246,34 @@ This is possible by using the extra NixOS module input ``nodes``.

{
network.description = "Gollum server and reverse proxy";
resources.machines = {

gollum =
{ config, pkgs, ... }:
{
services.gollum = {
enable = true;
port = 40273;
};
networking.firewall.allowedTCPPorts = [ config.services.gollum.port ];
};

reverseproxy =
{ config, pkgs, nodes, ... }:
let
gollumPort = nodes.gollum.config.services.gollum.port;
in
{
services.nginx = {
enable = true;
virtualHosts."wiki.example.net".locations."/" = {
proxyPass = "http://gollum:${toString gollumPort}";
};
};
networking.firewall.allowedTCPPorts = [ 80 ];
};};
};

gollum =
{ config, pkgs, ... }:
{
services.gollum = {
enable = true;
port = 40273;
};
networking.firewall.allowedTCPPorts = [ config.services.gollum.port ];
};

reverseproxy =
{ config, pkgs, nodes, ... }:
let
gollumPort = nodes.gollum.config.services.gollum.port;
in
{
services.nginx = {
enable = true;
virtualHosts."wiki.example.net".locations."/" = {
proxyPass = "http://gollum:${toString gollumPort}";
};
};
networking.firewall.allowedTCPPorts = [ 80 ];
};
}


Moving the port number to a different value is now without the risk of
an inconsistent deployment.
Expand Down
52 changes: 27 additions & 25 deletions doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ machine, and leave ``deployment.targetEnv`` undefined. See
::

{
webserver =
resources.machines.webserver =
{ config, pkgs, ... }:
{ deployment.targetHost = "1.2.3.4";
};
Expand Down Expand Up @@ -92,7 +92,7 @@ example:
imports = [ ./common.nix ];
};

machine = { ... }: {};
resources.machines.machine = { ... }: {};
}

Each attribute is explained below:
Expand Down Expand Up @@ -122,7 +122,7 @@ Here is an example of a network with network arguments:
{ maintenance ? false
}:
{
machine =
resources.machines.machine =
{ config, pkgs, ... }:
{ services.httpd.enable = maintenance;
...
Expand Down Expand Up @@ -175,7 +175,7 @@ Add a key to a machine like so.
::

{
machine =
resources.machines.machine =
{ config, pkgs, ... }:
{
deployment.keys.my-secret.text = "shhh this is a secret";
Expand Down Expand Up @@ -216,7 +216,7 @@ and otherwise inactive when the key is absent. See
::

{
machine =
resources.machines.machine =
{ config, pkgs, ... }:
{
deployment.keys.my-secret.text = "shhh this is a secret";
Expand Down Expand Up @@ -251,30 +251,32 @@ This is possible by using the extra NixOS module input ``nodes``.
{
network.description = "Gollum server and reverse proxy";

gollum =
{ config, pkgs, ... }:
{
services.gollum = {
enable = true;
port = 40273;
resources.machines = {
gollum =
{ config, pkgs, ... }:
{
services.gollum = {
enable = true;
port = 40273;
};
networking.firewall.allowedTCPPorts = [ config.services.gollum.port ];
};
networking.firewall.allowedTCPPorts = [ config.services.gollum.port ];
};

reverseproxy =
{ config, pkgs, nodes, ... }:
let
gollumPort = nodes.gollum.config.services.gollum.port;
in
{
services.nginx = {
enable = true;
virtualHosts."wiki.example.net".locations."/" = {
proxyPass = "http://gollum:${toString gollumPort}";
reverseproxy =
{ config, pkgs, nodes, ... }:
let
gollumPort = nodes.gollum.config.services.gollum.port;
in
{
services.nginx = {
enable = true;
virtualHosts."wiki.example.net".locations."/" = {
proxyPass = "http://gollum:${toString gollumPort}";
};
};
networking.firewall.allowedTCPPorts = [ 80 ];
};
networking.firewall.allowedTCPPorts = [ 80 ];
};
};
}

Moving the port number to a different value is now without the risk of
Expand Down
4 changes: 4 additions & 0 deletions doc/release-notes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Release 2.0

- Major code cleanups.

- Now the network specification is using the module system from ``nixpkgs.lib``
- Now network specification files can import other files via ``imports``.
- 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.

- Removed NixOS Options

- ``deployment.autoLuks.*`` - moved to `nixos-modules-contrib`_.
Expand Down
5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
git_root=$(${pkgs.git}/bin/git rev-parse --show-toplevel)
export PYTHONPATH=$git_root:$PYTHONPATH
export PATH=$git_root/scripts:$PATH
export NIX_PATH="nixpkgs=${toString nixpkgs}:$NIX_PATH"
'';
};

Expand Down Expand Up @@ -73,6 +74,10 @@
overrides
];

postPatch = ''
substituteInPlace nix/eval-machine-info.nix --replace "<nixpkgs>" "${toString nixpkgs}"
'';

# TODO: Re-add manual build
};

Expand Down
26 changes: 26 additions & 0 deletions nix/default-deployment.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ lib, ... }: let
inherit (lib) mkOption types;
in {
options.deployment = {

name = mkOption {
type = types.str;
description = ''
The name of the NixOps deployment. This is set by NixOps.
'';
};

uuid = mkOption {
type = types.str;
description = ''
The UUID of the NixOps deployment. This is set by NixOps.
'';
};

arguments = mkOption {
description = ''
Attribute set representing the NixOps arguments. This is set by NixOps.
'';
};
};
}
Loading