From e6ed60548397627bf10f561f9438201dbba0a36e Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 21 Apr 2024 02:15:42 +0300 Subject: 2024-04-21 --- modules/lidarr.nix | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 modules/lidarr.nix (limited to 'modules/lidarr.nix') diff --git a/modules/lidarr.nix b/modules/lidarr.nix new file mode 100644 index 0000000..84d363b --- /dev/null +++ b/modules/lidarr.nix @@ -0,0 +1,60 @@ +{ + config, + inputs, + lib, + libNginx, + ... +}: +with lib; +let + cfg = config.nixfiles.modules.lidarr; +in +{ + options.nixfiles.modules.lidarr = { + enable = mkEnableOption "Lidarr"; + + domain = mkOption { + description = "Domain name sans protocol scheme."; + type = with types; str; + default = "lidarr.${config.networking.domain}"; + }; + }; + + config = mkIf cfg.enable { + secrets.lidarr-api-key.file = "${inputs.self}/secrets/lidarr-api-key"; + + ark.directories = [ "/var/lib/lidarr" ]; + + nixfiles.modules.nginx = { + enable = true; + upstreams.lidarr.servers."127.0.0.1:8686" = { }; + virtualHosts.${cfg.domain} = { + locations."/".proxyPass = "http://lidarr"; + extraConfig = libNginx.config.internalOnly; + }; + }; + + services = { + lidarr = { + enable = true; + user = "rtorrent"; + group = "rtorrent"; + }; + + prometheus.exporters.exportarr-lidarr = { + enable = true; + url = "http://127.0.0.1"; + apiKeyFile = config.secrets.lidarr-api-key.path; + port = mkDefault 9708; + inherit (config.services.lidarr) user; + inherit (config.services.lidarr) group; + listenAddress = this.wireguard.ipv4.address; + environment.CONFIG = "/var/lib/lidarr/.config/Lidarr/config.xml"; + }; + }; + + systemd.tmpfiles.rules = with config.services.lidarr; [ + "d /var/lib/lidarr/root 0755 ${user} ${group} - -" + ]; + }; +} -- cgit v1.2.3