{ lib, config, ... }: let cfg = config.this.hosts; in { options = { this.hosts.lan.home = lib.mkEnableOption "Home LAN /etc/hosts"; this.hosts.mine = lib.mkEnableOption "my /etc/hosts"; this.hosts.alef.zoar.cx = lib.mkEnableOption "alef.zoar.cx /etc/hosts"; this.hosts.yggdrasil.public = lib.mkOption { description = "Use Yggdrasil addresses for public hosts when possible."; type = lib.types.bool; default = false; }; this.hosts.yggdrasil.private = lib.mkOption { description = "Use Yggdrasil addresses for non-public hosts when possible."; type = lib.types.bool; default = false; }; }; config = { networking.hosts = lib.optionalAttrs cfg.lan.home { "172.19.0.14" = ["sage.alef.zoar.cx" "sage"]; "192.168.1.5" = ["rosemary.alef.zoar.cx" "rosemary"]; } // lib.optionalAttrs cfg.mine { "${(if cfg.yggdrasil.public then "201:c37f:8bd1:de2c:531e:a3c8:6c38:aa3e" else "45.61.184.234")}" = ["alfheim"]; } // lib.optionalAttrs cfg.alef.zoar.cx { "173.16.167.196" = ["sage.alef.zoar.cx" "sage"]; } // lib.optionalAttrs cfg.yggdrasil.private { "202:96bb:5497:1cc7:94e2:c14d:6333:a50e" = ["tomato.alef.zoar.cx" "tomato"]; "200:48e6:735d:3637:e3a2:71dc:7a74:27a3" = ["pinto.bean.alef.zoar.cx" "pinto"]; "200:99a0:d4e1:9b0d:4e72:1202:86ef:17fe" = ["carrot.alef.zoar.cx" "carrot"]; }; services.yggdrasil = lib.mkMerge [ { persistentKeys = true; settings = { Peers = [ "quic://ba.ln.ea.cx:9003" ]; }; } (lib.mkIf cfg.yggdrasil.public or cfg.yggdrasil.private { enable = lib.mkDefault true; }) ]; }; }