host roles

This commit is contained in:
Astro 2021-03-20 00:06:31 +01:00
parent 99edf9fe53
commit 171b213603
3 changed files with 23 additions and 8 deletions

View File

@ -21,19 +21,31 @@ in
config.site.hosts = lib.mkMerge ( config.site.hosts = lib.mkMerge (
[ [
{
server1.role = "server";
}
(builtins.mapAttrs (_: switch: { (builtins.mapAttrs (_: switch: {
inherit (switch) model location password; inherit (switch) model location password;
role = "switch"; role = "switch";
}) pillar.switches) }) pillar.switches)
(builtins.mapAttrs (_: ap: { (builtins.mapAttrs (_: ap: {
inherit (ap) model location password; inherit (ap) model location password;
role = "ap"; role = "ap";
}) pillar.cpe) }) pillar.cpe)
(builtins.mapAttrs (_: container: {
role = "container";
location = "server1";
}) pillar.containers)
] ++ ] ++
(map (net: (map (net:
builtins.mapAttrs (_: addr4: { builtins.mapAttrs (_: addr4: {
}) pillar.hosts-inet.${net} }) pillar.hosts-inet.${net}
) (builtins.attrNames pillar.hosts-inet)) ++ ) (builtins.attrNames pillar.hosts-inet)) ++
(builtins.concatMap (ctx: (builtins.concatMap (ctx:
map (net: map (net:
builtins.mapAttrs (_: addr6: { builtins.mapAttrs (_: addr6: {

View File

@ -23,12 +23,18 @@ let
hostOpts = { name, ... }: { hostOpts = { name, ... }: {
options = { options = {
role = mkOption { role = mkOption {
type = types.enum [ "ap" "switch" "server" "gateway" "client" ]; type = types.enum [ "ap" "switch" "server" "container" "client" ];
default = "client"; default = "client";
}; };
model = mkOption { model = mkOption {
type = types.str; type = types.str;
default = "pc"; default = {
ap = "unknown";
switch = "unknown";
server = "pc";
container = "lxc";
client = "any";
}."${config.site.hosts.${name}.role}";
}; };
password = mkOption { password = mkOption {
type = with types; nullOr str; type = with types; nullOr str;

View File

@ -4,19 +4,16 @@ let
inherit (config.networking) hostName; inherit (config.networking) hostName;
inherit (lib) optional; inherit (lib) optional;
startsWith = prefix: s: hostConfig = config.site.hosts.${hostName};
builtins.substr 0 (builtins.stringLength prefix) s == prefix;
isServer = startsWith "server" hostName;
in in
{ {
imports = [ imports = [
./defaults.nix ./defaults.nix
] ]
++ optional isServer [ ++ optional (hostConfig.role == "server") [
./lxc-containers.nix ./lxc-containers.nix
] ]
++ optional !isServer [ ++ optional (hostConfig.role == "container") [
./container.nix ./container.nix
]; ];
} }