kore / nixos / features / kore.nix43 lines · 1168B · raw
1{ config, lib, kore, ... }:
2
3let
4 hostOptions = with lib; {
5 system = mkOption {
6 type = types.str;
7 };
8 ipv4 = mkOption {
9 type = types.nullOr types.str;
10 default = null;
11 };
12 roles = mkOption {
13 type = types.listOf types.str;
14 default = [];
15 };
16 };
17in {
18 options.kore = with lib; {
19 hosts = mkOption {
20 type = types.attrsOf (types.submodule [{ options = hostOptions; }]);
21 default = {};
22 };
23 currentHost = mkOption {
24 type = types.submodule [{ options = hostOptions; }];
25 };
26 };
27 config = {
28 warnings = lib.optional (!(kore.hosts ? ${config.networking.hostName}))
29 "no configuration for ${config.networking.hostName} found";
30
31 kore = {
32 hosts = kore.hosts;
33 currentHost = kore.hosts.${config.networking.hostName};
34 };
35
36 # /etc/hosts so machines resolve each other by name; placeholder
37 # 0.0.0.0 addresses are skipped.
38 networking.hosts = lib.mkMerge (lib.mapAttrsToList (name: host:
39 lib.optionalAttrs (host.ipv4 != null && host.ipv4 != "0.0.0.0") {
40 "${host.ipv4}" = [ "${name}.${config.networking.domain}" name ];
41 }) kore.hosts);
42 };
43}