2022-09-21 18:00:51 +02:00
|
|
|
{ nixpkgs, home-manager, hyprland, mailserver, ... }:
|
2022-08-21 11:42:17 +02:00
|
|
|
let
|
|
|
|
inherit (nixpkgs) lib;
|
|
|
|
inherit (builtins) filter mapAttrs attrValues concatLists;
|
|
|
|
import_cases = {
|
|
|
|
"lxc" = [
|
|
|
|
"${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix"
|
|
|
|
./nixos/common/generic-lxc.nix
|
|
|
|
];
|
|
|
|
"vm" = [
|
|
|
|
./nixos/common/generic-vm.nix
|
|
|
|
];
|
|
|
|
"local" = [
|
|
|
|
home-manager.nixosModules.home-manager
|
2022-08-24 18:17:29 +02:00
|
|
|
hyprland.nixosModules.default
|
2022-08-21 11:42:17 +02:00
|
|
|
];
|
|
|
|
};
|
|
|
|
resolve_imports = { hostname, realm, profile ? hostname, type ? "lxc", ... }: [
|
2022-09-21 18:00:51 +02:00
|
|
|
mailserver.nixosModules.mailserver
|
2022-08-21 11:42:17 +02:00
|
|
|
./nixos/common
|
|
|
|
"${./.}/nixos/hosts/${realm}/${profile}/configuration.nix"
|
|
|
|
] ++ import_cases.${type};
|
|
|
|
in
|
|
|
|
rec {
|
|
|
|
add_realm_to_tags = realm: hosts: map ({ tags ? [ ], ... }@host: host // { tags = [ realm ] ++ tags; inherit realm; }) hosts;
|
|
|
|
flatten_hosts = hosts: concatLists (attrValues hosts);
|
|
|
|
filter_nix_hosts = hosts: filter ({ nix ? true, ... }: nix) hosts;
|
|
|
|
|
2022-09-10 19:44:16 +02:00
|
|
|
mkColmenaHost = { ip ? null, hostname, tags, realm, type ? "lxc", ... }@host:
|
|
|
|
let
|
|
|
|
name = if realm == "thalassa" then hostname else "${hostname}.${realm}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
"${name}" = {
|
|
|
|
imports = resolve_imports host;
|
|
|
|
networking = {
|
|
|
|
hostName = hostname;
|
|
|
|
domain = realm;
|
|
|
|
};
|
|
|
|
deployment = {
|
|
|
|
inherit tags;
|
|
|
|
targetHost = ip;
|
|
|
|
allowLocalDeployment = (type == "local");
|
|
|
|
targetUser = null; # Defaults to $USER
|
|
|
|
};
|
2022-08-21 11:42:17 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|