2023-06-02 17:16:36 +02:00
|
|
|
{ nixpkgs, home-manager, mailserver, lanzaboote, attic, ... }:
|
2022-08-21 11:42:17 +02:00
|
|
|
let
|
2022-12-26 15:13:04 +01:00
|
|
|
inherit (builtins) filter attrValues concatMap mapAttrs;
|
|
|
|
inherit (nixpkgs.lib.attrsets) mapAttrsToList;
|
2023-04-28 10:28:06 +02:00
|
|
|
base_imports = [
|
2023-12-18 15:49:08 +01:00
|
|
|
./common
|
2023-04-28 10:28:06 +02:00
|
|
|
home-manager.nixosModules.home-manager
|
|
|
|
mailserver.nixosModules.mailserver
|
2023-06-02 17:16:36 +02:00
|
|
|
attic.nixosModules.atticd
|
2023-04-28 10:28:06 +02:00
|
|
|
];
|
2023-09-25 11:56:02 +02:00
|
|
|
type_import =
|
|
|
|
let
|
|
|
|
import_cases = {
|
|
|
|
"lxc" = [
|
|
|
|
"${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix"
|
|
|
|
./common/generic-lxc.nix
|
|
|
|
];
|
|
|
|
"vm" = [ ./common/generic-vm.nix ];
|
|
|
|
"local" = [
|
|
|
|
lanzaboote.nixosModules.lanzaboote
|
|
|
|
./common/desktop
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
type: import_cases.${type} ++ base_imports;
|
2023-04-28 10:28:06 +02:00
|
|
|
# Helper function to resolve what should be imported depending on the type of config (lxc, vm, bare metal)
|
|
|
|
resolve_imports = { hostname, realm, profile ? hostname, type ? "lxc", ... }:
|
|
|
|
type_import type
|
2023-12-18 15:49:08 +01:00
|
|
|
++ [ "${./.}/hosts/${realm}/${profile}/configuration.nix" ];
|
2023-04-28 10:28:06 +02:00
|
|
|
|
2022-09-25 23:49:26 +02:00
|
|
|
# Add to whatever realm a host belong to its list of tags
|
2022-12-26 15:13:04 +01:00
|
|
|
add_realm_to_tags = mapAttrs (realm:
|
2023-05-04 13:06:08 +02:00
|
|
|
mapAttrs (_hostname:
|
2023-05-22 20:09:00 +02:00
|
|
|
{ type ? "lxc", tags ? [ ], ... }@host:
|
2022-12-26 13:02:48 +01:00
|
|
|
host // {
|
2023-05-22 20:09:00 +02:00
|
|
|
# Tags are for deployment, so don't add them to local machines
|
|
|
|
tags = tags ++ (if type == "local" then [ ] else [ realm ]);
|
2022-12-26 13:02:48 +01:00
|
|
|
inherit realm;
|
2022-12-26 15:13:04 +01:00
|
|
|
}));
|
|
|
|
|
2022-09-25 23:49:26 +02:00
|
|
|
# Flatten all hosts to a single list
|
2022-12-26 15:13:04 +01:00
|
|
|
flatten_hosts = realms:
|
|
|
|
concatMap (mapAttrsToList (name: value: value // { hostname = name; }))
|
2023-09-25 11:56:02 +02:00
|
|
|
(attrValues realms);
|
2022-12-26 15:13:04 +01:00
|
|
|
|
2022-09-25 23:49:26 +02:00
|
|
|
# Filter out all hosts which aren't nixos
|
2022-12-01 22:13:05 +01:00
|
|
|
filter_nix_hosts = filter ({ nix ? true, ... }: nix);
|
2022-08-21 11:42:17 +02:00
|
|
|
|
2023-05-04 15:14:36 +02:00
|
|
|
# outputs
|
|
|
|
|
2022-09-25 23:49:26 +02:00
|
|
|
# Helper function to build a colmena host definition
|
2023-09-25 11:56:02 +02:00
|
|
|
mkColmenaHost =
|
|
|
|
{ ip ? null
|
|
|
|
, exposes ? null
|
|
|
|
, hostname
|
|
|
|
, tags
|
|
|
|
, realm
|
|
|
|
, type ? "lxc"
|
|
|
|
, ...
|
|
|
|
}@host:
|
2022-09-10 19:44:16 +02:00
|
|
|
let
|
2022-09-25 23:49:26 +02:00
|
|
|
# this makes local apply work a bit nicer
|
2023-04-29 15:25:11 +02:00
|
|
|
name = if type == "local" then hostname else "${hostname}.${realm}";
|
2023-09-25 11:56:02 +02:00
|
|
|
in
|
|
|
|
{
|
2022-09-10 19:44:16 +02:00
|
|
|
"${name}" = {
|
|
|
|
imports = resolve_imports host;
|
|
|
|
networking = {
|
|
|
|
hostName = hostname;
|
|
|
|
domain = realm;
|
|
|
|
};
|
2023-05-04 15:14:36 +02:00
|
|
|
meta = {
|
|
|
|
inherit exposes;
|
|
|
|
ipv4 = ip;
|
|
|
|
};
|
2022-09-10 19:44:16 +02:00
|
|
|
deployment = {
|
|
|
|
inherit tags;
|
|
|
|
targetHost = ip;
|
2022-12-01 22:13:05 +01:00
|
|
|
allowLocalDeployment = type == "local";
|
2023-11-26 17:29:50 +01:00
|
|
|
targetUser = null; # Defaults to $USER
|
2022-09-10 19:44:16 +02:00
|
|
|
};
|
2022-08-21 11:42:17 +02:00
|
|
|
};
|
|
|
|
};
|
2023-05-04 15:14:36 +02:00
|
|
|
hosts = add_realm_to_tags (import ./hosts);
|
|
|
|
flat_hosts = flatten_hosts hosts;
|
|
|
|
nixHosts = filter_nix_hosts flat_hosts;
|
2023-09-25 11:56:02 +02:00
|
|
|
in
|
|
|
|
{ inherit base_imports mkColmenaHost hosts flat_hosts nixHosts; }
|