2022-08-24 18:17:29 +02:00
|
|
|
{ nixpkgs, home-manager, hyprland, ... }:
|
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", ... }: [
|
|
|
|
./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;
|
|
|
|
|
|
|
|
mkNixosSystem = specialArgs: { hostname, realm, system ? "x86_64-linux", ... }@host: {
|
|
|
|
"${hostname}.${realm}" = lib.nixosSystem {
|
|
|
|
inherit system specialArgs;
|
2022-09-10 19:44:16 +02:00
|
|
|
modules =
|
|
|
|
[
|
|
|
|
({ config, pkgs, ... }: {
|
|
|
|
nixpkgs.overlays = [ (import ./nixos/pkgs) ];
|
|
|
|
networking = {
|
|
|
|
hostName = hostname;
|
|
|
|
domain = realm;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
] ++
|
|
|
|
(resolve_imports host);
|
2022-08-21 11:42:17 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkNixosConfigurations = specialArgs: hosts: lib.foldr (el: acc: acc // mkNixosSystem specialArgs el) { } hosts;
|
|
|
|
}
|