{ config, inputs, lib, libNginx, this, ... }: with lib; let cfg = config.nixfiles.modules.piracy.radarr; port = 7878; in { options.nixfiles.modules.piracy.radarr = { enable = mkEnableOption "Radarr"; domain = mkOption { description = "Domain name sans protocol scheme."; type = with types; str; default = "radarr.${config.networking.domain}"; }; }; config = mkIf cfg.enable { secrets.radarr-api-key.file = "${inputs.self}/secrets/radarr-api-key"; ark.directories = [ "/var/lib/radarr" ]; nixfiles.modules = { nginx = { enable = true; upstreams.radarr.servers."127.0.0.1:${toString port}" = { }; virtualHosts.${cfg.domain} = { locations."/".proxyPass = "http://radarr"; extraConfig = libNginx.config.internalOnly; }; }; piracy = { enable = true; jackett.enable = true; }; }; services = { radarr = { enable = true; group = "piracy"; }; prometheus.exporters.exportarr-radarr = { enable = true; url = "http://127.0.0.1"; port = port + 10000; apiKeyFile = config.secrets.radarr-api-key.path; inherit (config.services.radarr) user; inherit (config.services.radarr) group; listenAddress = this.wireguard.ipv4.address; environment.CONFIG = "/var/lib/radarr/.config/Radarr/config.xml"; }; }; systemd = { tmpfiles.rules = with config.services.radarr; [ "d /var/lib/radarr/root 0755 ${user} ${group} - -" ]; services.lidarr.after = [ "flood.service" "jackett.service" "local-fs.target" ]; }; topology = with cfg; { nodes.${this.hostname}.services.radarr = { info = domain; details.listen.text = "127.0.0.1:${toString port}"; }; }; }; }