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

nixus.groups: added ability to put nodes into groups #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ nixusArgs: conf: let
modules/public-ip.nix
modules/dns.nix
modules/vpn
modules/groups.nix
conf
# Not naming it pkgs to avoid confusion and trouble for overriding scopes
{
Expand Down
55 changes: 55 additions & 0 deletions modules/groups.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ config, lib, nixus, ... }:

let
inherit (lib) types;

# we need to reference the global configuration in our submodule.
gconfig = config;

groupOpts = { config, ... }: {
options = {
deployScript = lib.mkOption {
type = types.package;
readOnly = true;
};

members = lib.mkOption {
type = types.listOf types.str;
default = [];
};
};

config.deployScript = let
mkDeployScript = members: nixus.pkgs.writeShellScript "deploy" ''
${lib.concatMapStrings (nodeName: lib.optionalString gconfig.nodes.${nodeName}.enabled ''

${gconfig.nodes.${nodeName}.deployScript} &
'') config.members}
wait
'';
in mkDeployScript config.members;
};
in {
options = {
groups = lib.mkOption {
type = types.attrsOf (types.submodule groupOpts);
default = {};
description = ''
Allows creating groups of nodes for deploying them together, instead of deploying all nodes.
Building the script for deploying can be done like `nix-build -A config.groups.home.deployScript`
'';
example = {
servers = [
"vps-web"
"vps-web2"
"vps-db"
];
home = [
"eos"
"server1"
"router"
];
};
};
};
}