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 (
[
{
server1.role = "server";
}
(builtins.mapAttrs (_: switch: {
inherit (switch) model location password;
role = "switch";
}) pillar.switches)
(builtins.mapAttrs (_: ap: {
inherit (ap) model location password;
role = "ap";
}) pillar.cpe)
(builtins.mapAttrs (_: container: {
role = "container";
location = "server1";
}) pillar.containers)
] ++
(map (net:
builtins.mapAttrs (_: addr4: {
}) pillar.hosts-inet.${net}
) (builtins.attrNames pillar.hosts-inet)) ++
(builtins.concatMap (ctx:
map (net:
builtins.mapAttrs (_: addr6: {

View File

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

View File

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