init: static-hosts module #1385

Merged
clan-bot merged 1 commits from a-kenji-init/statix-hosts-module into main 2024-05-19 11:09:54 +00:00
4 changed files with 28 additions and 0 deletions

View File

@ -14,6 +14,7 @@
root-password = ./root-password;
sshd = ./sshd;
sunshine = ./sunshine;
static-hosts = ./static-hosts;
syncthing = ./syncthing;
thelounge = ./thelounge;
user-password = ./root-password;

View File

@ -0,0 +1,2 @@
Statically configure the host names of machines based on their respective zerotier-ip.
---

View File

@ -0,0 +1,24 @@
{ lib, config, ... }:
{
options.clan.static-hosts = {
excludeHosts = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ config.clanCore.machineName ];
description = "Hosts that should be excluded";
};
};
config.networking.hosts =
let
clanDir = config.clanCore.clanDir;
machineDir = clanDir + "/machines/";
zerotierIpMachinePath = machines: machineDir + machines + "/facts/zerotier-ip";
machines = builtins.readDir machineDir;
filteredMachines = lib.filterAttrs (
name: _: !(lib.elem name config.clan.static-hosts.excludeHosts)
) machines;
in
(lib.mapAttrs' (
machine: _: lib.nameValuePair (builtins.readFile (zerotierIpMachinePath machine)) [ machine ]
) filteredMachines);
}

View File

@ -62,6 +62,7 @@ nav:
- reference/clanModules/sshd.md
- reference/clanModules/sunshine.md
- reference/clanModules/syncthing.md
- reference/clanModules/static-hosts.md
- reference/clanModules/thelounge.md
- reference/clanModules/user-password.md
- reference/clanModules/xfce.md