From 56e80113004f0ea8ddbfb1d904cba133948f8ac5 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Sun, 14 Jan 2024 13:33:40 -0800 Subject: [PATCH] refactor: avahi --- ci/deploy.sh | 5 +++++ modules/nixos/access.nix | 3 +++ nixos/avahi.nix | 19 +++++++++++++++++++ nixos/home-assistant.nix | 2 +- nixos/reisen-ct/network.nix | 18 +++++++----------- systems/tei/nixos.nix | 1 + 6 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 nixos/avahi.nix diff --git a/ci/deploy.sh b/ci/deploy.sh index f8c100e5..b2fe10cd 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -7,6 +7,11 @@ NF_HOST=${NF_HOST-tewi} NIXOS_TOPLEVEL=network.nodes.$NF_HOST.system.build.toplevel NF_ADDR=${NF_ADDR-${NF_HOST}.local} +if [[ $NF_ADDR = tewi.local ]]; then + # work around homekit namespace clash + NF_ADDR=tewi.local.cutie.moe +fi + if [[ $# -eq 0 ]]; then set -- "" fi diff --git a/modules/nixos/access.nix b/modules/nixos/access.nix index 91ec8964..637536f9 100644 --- a/modules/nixos/access.nix +++ b/modules/nixos/access.nix @@ -8,6 +8,9 @@ inherit (config.networking) hostName; in { options.networking.access = with lib.types; { + static.ipv4 = mkOption { + type = str; + }; hostnameForNetwork = mkOption { type = attrsOf str; default = { }; diff --git a/nixos/avahi.nix b/nixos/avahi.nix new file mode 100644 index 00000000..8d8013d5 --- /dev/null +++ b/nixos/avahi.nix @@ -0,0 +1,19 @@ +{ + config, + lib, + ... +}: let + inherit (lib.modules) mkDefault; +in { + services.avahi = { + enable = mkDefault true; + ipv6 = mkDefault config.networking.enableIPv6; + publish = { + enable = mkDefault true; + domain = mkDefault true; + addresses = mkDefault true; + userServices = mkDefault true; + }; + wideArea = mkDefault false; + }; +} diff --git a/nixos/home-assistant.nix b/nixos/home-assistant.nix index ea3b1287..6e8e0cb1 100644 --- a/nixos/home-assistant.nix +++ b/nixos/home-assistant.nix @@ -86,7 +86,7 @@ in { homekit = [ { name = "Tewi"; port = 21063; - ip_address = "10.1.1.38"; + ip_address = config.networking.access.static.ipv4; filter = let inherit (cfg.config) google_assistant; in { diff --git a/nixos/reisen-ct/network.nix b/nixos/reisen-ct/network.nix index 4d170faa..bfe8c901 100644 --- a/nixos/reisen-ct/network.nix +++ b/nixos/reisen-ct/network.nix @@ -2,22 +2,18 @@ lib, config, options, + meta, ... }: let inherit (lib.modules) mkIf mkDefault; in { + imports = let + inherit (meta) nixos; + in [ + nixos.avahi + ]; + services.resolved.enable = true; - services.avahi = { - enable = mkDefault true; - ipv6 = mkDefault config.networking.enableIPv6; - publish = { - enable = mkDefault true; - domain = mkDefault true; - addresses = mkDefault true; - userServices = mkDefault true; - }; - wideArea = mkDefault false; - }; systemd.services.avahi-daemon = mkIf (options ? proxmoxLXC && config.services.avahi.enable) { serviceConfig.ExecStartPre = mkIf config.services.resolved.enable [ "+-${config.systemd.package}/bin/resolvectl mdns eth0 yes" diff --git a/systems/tei/nixos.nix b/systems/tei/nixos.nix index 611ddf9c..d900eb43 100644 --- a/systems/tei/nixos.nix +++ b/systems/tei/nixos.nix @@ -24,6 +24,7 @@ ]; sops.defaultSopsFile = ./secrets.yaml; + networking.access.static.ipv4 = "10.1.1.39"; system.stateVersion = "23.11"; }