From 39c2c943a1044b4182a5738f19615be9510de54d Mon Sep 17 00:00:00 2001 From: ibizaman Date: Thu, 16 Nov 2023 23:48:19 -0800 Subject: [PATCH] fix backupCfg option for arr module --- README.md | 4 ++ modules/arr.nix | 18 +++--- test/modules/arr.nix | 145 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4e8764f..3d9a7f3 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,10 @@ Currently supported services and features are: - [ ] Gitea to deploy - [ ] Scrutiny to monitor hard drives health - [ ] Export metrics to Prometheus. +- [x] Tests + - [x] Unit tests for modules. + - [x] Running in CI. + - [ ] Integration tests with real nodes. ## Usage diff --git a/modules/arr.nix b/modules/arr.nix index dd49782..105d21c 100644 --- a/modules/arr.nix +++ b/modules/arr.nix @@ -319,14 +319,16 @@ config.xml" templatedSettings) "${config.services.radarr.dataDir}/config.xml" ( shb.backup.instances = let - backupConfig = name: _defaults: lib.mkIf (cfg.${name}.backupCfg != {}) { - ${name} = { - sourceDirectories = [ - config.shb.arr.${name}.dataDir - ]; - excludePatterns = [".db-shm" ".db-wal" ".mono"]; - }; - }; + backupConfig = name: _defaults: lib.mkIf (cfg.${name}.backupCfg.enable or false) ({ + ${name} = ( + cfg.${name}.backupCfg + // { + sourceDirectories = [ + config.shb.arr.${name}.dataDir + ]; + excludePatterns = [".db-shm" ".db-wal" ".mono"]; + }); + }); in lib.mkMerge (lib.mapAttrsToList backupConfig apps); } diff --git a/test/modules/arr.nix b/test/modules/arr.nix index 939b82d..972f2dc 100644 --- a/test/modules/arr.nix +++ b/test/modules/arr.nix @@ -50,4 +50,149 @@ in }; expr = testConfig {}; }; + + testRadarr = { + expected = { + systemd.services.radarr = { + preStart = "ln -fs /nix/store/z7gk6xfj51sr1n1bjj6lsadjrwjxzc5d--config.xml /var/lib/radarr/config.xml.template\nrm /var/lib/radarr/config.xml || :\nsed -e \"s|%APIKEY%|$(cat /run/radarr/apikey)|\" /var/lib/radarr/config.xml.template > /var/lib/radarr/config.xml\n"; + serviceConfig = { + StateDirectoryMode = "0750"; + UMask = "0027"; + }; + }; + systemd.services.jackett = {}; + systemd.tmpfiles.rules = [ + "d '/var/lib/radarr' 0750 radarr radarr - -" + ]; + shb.backup = {}; + shb.nginx.autheliaProtect = [ + { + autheliaRules = [ + { + domain = "radarr.example.com"; + policy = "bypass"; + resources = [ + "^/api.*" + ]; + } + { + domain = "radarr.example.com"; + policy = "two_factor"; + subject = [ + "group:arr_user" + ]; + } + ]; + domain = "example.com"; + oidcEndpoint = "https://oidc.example.com"; + subdomain = "radarr"; + upstream = "http://127.0.0.1:7001"; + } + ]; + users.users.radarr.extraGroups = [ "media" ]; + users.groups.radarr.members = [ "backup" ]; + services.bazarr = {}; + services.jackett = {}; + services.lidarr = {}; + services.radarr = { + enable = true; + dataDir = "/var/lib/radarr"; + user = "radarr"; + group = "radarr"; + }; + services.readarr = {}; + services.sonarr = {}; + }; + expr = testConfig { + services.radarr.user = "radarr"; + services.radarr.group = "radarr"; + + shb.arr.radarr = { + subdomain = "radarr"; + domain = "example.com"; + enable = true; + oidcEndpoint = "https://oidc.example.com"; + settings = { + APIKeyFile = "/run/radarr/apikey"; + }; + }; + }; + }; + + testRadarrWithBackup = { + expected = { + systemd.services.radarr = { + preStart = "ln -fs /nix/store/z7gk6xfj51sr1n1bjj6lsadjrwjxzc5d--config.xml /var/lib/radarr/config.xml.template\nrm /var/lib/radarr/config.xml || :\nsed -e \"s|%APIKEY%|$(cat /run/radarr/apikey)|\" /var/lib/radarr/config.xml.template > /var/lib/radarr/config.xml\n"; + serviceConfig = { + StateDirectoryMode = "0750"; + UMask = "0027"; + }; + }; + systemd.services.jackett = {}; + systemd.tmpfiles.rules = [ + "d '/var/lib/radarr' 0750 radarr radarr - -" + ]; + shb.backup.instances = { + radarr = { + enable = true; + sourceDirectories = [ "/var/lib/radarr" ]; + excludePatterns = [ ".db-shm" ".db-wal" ".mono" ]; + }; + }; + shb.nginx.autheliaProtect = [ + { + autheliaRules = [ + { + domain = "radarr.example.com"; + policy = "bypass"; + resources = [ + "^/api.*" + ]; + } + { + domain = "radarr.example.com"; + policy = "two_factor"; + subject = [ + "group:arr_user" + ]; + } + ]; + domain = "example.com"; + oidcEndpoint = "https://oidc.example.com"; + subdomain = "radarr"; + upstream = "http://127.0.0.1:7001"; + } + ]; + users.users.radarr.extraGroups = [ "media" ]; + users.groups.radarr.members = [ "backup" ]; + services.bazarr = {}; + services.jackett = {}; + services.lidarr = {}; + services.radarr = { + enable = true; + dataDir = "/var/lib/radarr"; + user = "radarr"; + group = "radarr"; + }; + services.readarr = {}; + services.sonarr = {}; + }; + expr = testConfig { + services.radarr.user = "radarr"; + services.radarr.group = "radarr"; + + shb.arr.radarr = { + subdomain = "radarr"; + domain = "example.com"; + enable = true; + oidcEndpoint = "https://oidc.example.com"; + settings = { + APIKeyFile = "/run/radarr/apikey"; + }; + backupCfg = { + enable = true; + }; + }; + }; + }; }