diff --git a/modules/nixos/server/default.nix b/modules/nixos/server/default.nix index 6394320..1102c9c 100644 --- a/modules/nixos/server/default.nix +++ b/modules/nixos/server/default.nix @@ -6,58 +6,9 @@ { options.server = { mountHelios = lib.mkEnableOption ""; - enableDDNS = lib.mkEnableOption ""; }; config = lib.mkMerge [ - (lib.mkIf config.server.enableDDNS { - services.godns = { - enable = true; - loadCredential = [ - "cf_token:${config.sops.secrets."keys/cloudflare".path}" - "telegram_bot_token:${config.sops.secrets."keys/telegram_bot".path}" - ]; - settings = { - provider = "Cloudflare"; - login_token_file = "$CREDENTIALS_DIRECTORY/cf_token"; - domains = [ - { - domain_name = "rrv.sh"; - sub_domains = [ "@" ]; - } - { - domain_name = "aenyrathia.wiki"; - sub_domains = [ "@" ]; - } - { - domain_name = "bwfiq.com"; - sub_domains = [ "*" ]; - } - { - domain_name = "slayment.com"; - sub_domains = [ "*" ]; - } - ]; - resolver = "1.1.1.1"; - ip_urls = [ - "https://wtfismyip.com/text" - "https://api.ipify.org" - "https://myip.biturl.top" - "https://api-ipv4.ip.sb/ip" - ]; - ip_type = "IPv4"; - interval = 300; - notify = { - telegram = { - enabled = true; - bot_api_key_file = "$CREDENTIALS_DIRECTORY/telegram_bot_token"; - chat_id = "384288005"; - message_template = "Domain *{{ .Domain }} has been updated to %0A{{ .CurrentIP }}"; - }; - }; - }; - }; - }) (lib.mkIf config.server.mountHelios { fileSystems."/media/helios/data" = { device = "//helios/data"; diff --git a/modules/nixos/server/networking/ddns/default.nix b/modules/nixos/server/networking/ddns/default.nix new file mode 100644 index 0000000..b50dc0b --- /dev/null +++ b/modules/nixos/server/networking/ddns/default.nix @@ -0,0 +1,62 @@ +{ config, lib, ... }: +let + inherit (lib) mkIf mkOption mkEnableOption; + inherit (lib.types) enum str listOf; + inherit (lib.lists) unique; + inherit (builtins) map; + cfg = config.server.networking.ddns; + mkDomain = domain_name: { + inherit domain_name; + sub_domains = [ + "@" + "*" + ]; + }; + # Sanitize the list of domains with unique so we can add to it with every service. + mkDomains = map mkDomain (unique cfg.domains); +in +{ + options.server.networking.ddns = { + enable = mkEnableOption ""; + type = mkOption { + type = enum [ "godns" ]; + default = "godns"; + }; + domains = mkOption { + type = listOf str; + default = [ ]; + }; + }; + + config = mkIf cfg.enable { + services.godns = { + enable = if (cfg.type == "godns") then true else false; + loadCredential = [ + "cf_token:${config.sops.secrets."keys/cloudflare".path}" + "telegram_bot_token:${config.sops.secrets."keys/telegram_bot".path}" + ]; + settings = { + provider = "Cloudflare"; + login_token_file = "$CREDENTIALS_DIRECTORY/cf_token"; + domains = mkDomains; + resolver = "1.1.1.1"; + ip_urls = [ + "https://wtfismyip.com/text" + "https://api.ipify.org" + "https://myip.biturl.top" + "https://api-ipv4.ip.sb/ip" + ]; + ip_type = "IPv4"; + interval = 300; + notify = { + telegram = { + enabled = true; + bot_api_key_file = "$CREDENTIALS_DIRECTORY/telegram_bot_token"; + chat_id = "384288005"; + message_template = "Domain *{{ .Domain }} has been updated to %0A{{ .CurrentIP }}"; + }; + }; + }; + }; + }; +} diff --git a/modules/nixos/server/web-apps/mattermost/default.nix b/modules/nixos/server/web-apps/mattermost/default.nix index 993617c..474a45a 100644 --- a/modules/nixos/server/web-apps/mattermost/default.nix +++ b/modules/nixos/server/web-apps/mattermost/default.nix @@ -1,5 +1,7 @@ { config, lib, ... }: let + inherit (lib) singleton; + inherit (lib.pantheon) mkRootDomain; cfg = config.server.web-apps.mattermost; upstreamCfg = config.services.mattermost; mkDir = directory: { @@ -37,6 +39,7 @@ in (mkDir cfg.dataDir) ]; networking.firewall.allowedTCPPorts = lib.singleton cfg.port; + server.networking.ddns.domains = singleton (mkRootDomain cfg.url); services.mattermost = { enable = true; inherit (cfg) diff --git a/systems/x86_64-linux/apollo/default.nix b/systems/x86_64-linux/apollo/default.nix index 75a76e3..05abdc3 100644 --- a/systems/x86_64-linux/apollo/default.nix +++ b/systems/x86_64-linux/apollo/default.nix @@ -20,7 +20,14 @@ }; server = { - enableDDNS = true; + networking.ddns = { + enable = true; + domains = [ + "rrv.sh" + "aenyrathia.wiki" + "slayment.com" + ]; + }; databases = { mongodb.enable = true; mysql.enable = true;