add hm modules: riff

This commit is contained in:
Vivian 2022-12-26 13:02:48 +01:00
parent 205e7de702
commit f91842b292
6 changed files with 79 additions and 45 deletions

View file

@ -3,32 +3,31 @@ let
inherit (builtins) filter attrValues concatLists;
# Helper function to resolve what should be imported depending on the type of config (lxc, vm, bare metal)
resolve_imports =
let
# lookup table
import_cases = {
"lxc" = [
"${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix"
./common/generic-lxc.nix
];
"vm" = [
./common/generic-vm.nix
];
"local" = [
hyprland.nixosModules.default
];
};
in
{ hostname, realm, profile ? hostname, type ? "lxc", ... }: [
home-manager.nixosModules.home-manager
mailserver.nixosModules.mailserver
./common
"${./.}/hosts/${realm}/${profile}/configuration.nix"
] ++ import_cases.${type};
in
{
resolve_imports = let
# lookup table
import_cases = {
"lxc" = [
"${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix"
./common/generic-lxc.nix
];
"vm" = [ ./common/generic-vm.nix ];
"local" = [ hyprland.nixosModules.default ];
};
in { hostname, realm, profile ? hostname, type ? "lxc", ... }:
[
home-manager.nixosModules.home-manager
mailserver.nixosModules.mailserver
./common
"${./.}/hosts/${realm}/${profile}/configuration.nix"
] ++ import_cases.${type};
in {
# Add to whatever realm a host belong to its list of tags
add_realm_to_tags = realm: map ({ tags ? [ ], ... }@host: host // { tags = [ realm ] ++ tags; inherit realm; });
add_realm_to_tags = realm:
map ({ tags ? [ ], ... }@host:
host // {
tags = [ realm ] ++ tags;
inherit realm;
});
# Flatten all hosts to a single list
flatten_hosts = hosts: concatLists (attrValues hosts);
# Filter out all hosts which aren't nixos
@ -39,8 +38,7 @@ in
let
# this makes local apply work a bit nicer
name = if realm == "thalassa" then hostname else "${hostname}.${realm}";
in
{
in {
"${name}" = {
imports = resolve_imports host;
networking = {