{ pkgs, lib, self, }: pkgs.testers.runNixOSTest { name = "arr-init-partial-config"; nodes.machine = { pkgs, lib, ... }: let mocks = import ./lib/mocks.nix { inherit pkgs; }; in { imports = [ self.nixosModules.default ]; system.stateVersion = "24.11"; virtualisation.memorySize = 4096; environment.systemPackages = with pkgs; [ curl jq gnugrep ]; systemd.services.mock-qbittorrent = mocks.mkMockQbittorrent { }; systemd.tmpfiles.rules = [ "d /media/tv 0755 sonarr sonarr -" ]; services.sonarr = { enable = true; dataDir = "/var/lib/sonarr/.config/NzbDrone"; settings.server.port = lib.mkDefault 8989; }; services.radarr = { enable = true; dataDir = "/var/lib/radarr/.config/Radarr"; settings.server.port = lib.mkDefault 7878; }; services.prowlarr = { enable = true; }; # Test 1: Only rootFolders (no downloadClients) services.arrInit.sonarr = { enable = true; serviceName = "sonarr"; dataDir = "/var/lib/sonarr/.config/NzbDrone"; port = 8989; rootFolders = [ "/media/tv" ]; # downloadClients = []; (default empty) # syncedApps = []; (default empty) }; # Test 2: Only downloadClients (no rootFolders) services.arrInit.radarr = { enable = true; serviceName = "radarr"; dataDir = "/var/lib/radarr/.config/Radarr"; port = 7878; downloadClients = [ { name = "qBittorrent"; implementation = "QBittorrent"; configContract = "QBittorrentSettings"; protocol = "torrent"; fields = { host = "127.0.0.1"; port = 6011; useSsl = false; movieCategory = "movies"; }; } ]; # rootFolders = []; (default empty) # syncedApps = []; (default empty) }; # Test 3: Only syncedApps (Prowlarr) services.arrInit.prowlarr = { enable = true; serviceName = "prowlarr"; dataDir = "/var/lib/prowlarr"; port = 9696; apiVersion = "v1"; syncedApps = [ { name = "Sonarr"; implementation = "Sonarr"; configContract = "SonarrSettings"; prowlarrUrl = "http://localhost:9696"; baseUrl = "http://localhost:8989"; apiKeyFrom = "/var/lib/sonarr/.config/NzbDrone/config.xml"; syncCategories = [ 5000 ]; serviceName = "sonarr"; } ]; # downloadClients = []; (default empty) # rootFolders = []; (default empty) }; }; testScript = '' start_all() # Wait for mock and services machine.wait_for_unit("mock-qbittorrent.service") machine.wait_until_succeeds("curl -sf http://localhost:6011/api/v2/app/version", timeout=30) machine.wait_for_unit("sonarr.service") machine.wait_for_unit("radarr.service") machine.wait_for_unit("prowlarr.service") # Wait for APIs to be ready machine.wait_until_succeeds( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/sonarr/.config/NzbDrone/config.xml) && " "curl -sf http://localhost:8989/api/v3/system/status -H \"X-Api-Key: $API_KEY\"", timeout=120, ) machine.wait_until_succeeds( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/radarr/.config/Radarr/config.xml) && " "curl -sf http://localhost:7878/api/v3/system/status -H \"X-Api-Key: $API_KEY\"", timeout=120, ) machine.wait_until_succeeds( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/prowlarr/config.xml) && " "curl -sf http://localhost:9696/api/v1/system/status -H \"X-Api-Key: $API_KEY\"", timeout=180, ) # Trigger init services machine.succeed("systemctl restart sonarr-init.service") machine.succeed("systemctl restart radarr-init.service") machine.succeed("systemctl restart prowlarr-init.service") machine.wait_for_unit("sonarr-init.service") machine.wait_for_unit("radarr-init.service") machine.wait_for_unit("prowlarr-init.service") # Test 1: Sonarr - only rootFolders should exist, no download clients result = machine.succeed( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/sonarr/.config/NzbDrone/config.xml) && " "curl -sf http://localhost:8989/api/v3/rootfolder -H \"X-Api-Key: $API_KEY\" | " "jq '. | length'" ).strip() assert result == "1", f"Expected 1 Sonarr root folder, got {result}" result = machine.succeed( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/sonarr/.config/NzbDrone/config.xml) && " "curl -sf http://localhost:8989/api/v3/downloadclient -H \"X-Api-Key: $API_KEY\" | " "jq '. | length'" ).strip() assert result == "0", f"Expected 0 Sonarr download clients, got {result}" # Test 2: Radarr - only downloadClients should exist, no root folders result = machine.succeed( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/radarr/.config/Radarr/config.xml) && " "curl -sf http://localhost:7878/api/v3/downloadclient -H \"X-Api-Key: $API_KEY\" | " "jq '. | length'" ).strip() assert result == "1", f"Expected 1 Radarr download client, got {result}" result = machine.succeed( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/radarr/.config/Radarr/config.xml) && " "curl -sf http://localhost:7878/api/v3/rootfolder -H \"X-Api-Key: $API_KEY\" | " "jq '. | length'" ).strip() assert result == "0", f"Expected 0 Radarr root folders, got {result}" # Test 3: Prowlarr - only syncedApps should exist result = machine.succeed( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/prowlarr/config.xml) && " "curl -sf http://localhost:9696/api/v1/applications -H \"X-Api-Key: $API_KEY\" | " "jq '. | length'" ).strip() assert result == "1", f"Expected 1 Prowlarr synced app, got {result}" # Verify Sonarr is the synced app machine.succeed( "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/prowlarr/config.xml) && " "curl -sf http://localhost:9696/api/v1/applications -H \"X-Api-Key: $API_KEY\" | " "jq -e '.[] | select(.name == \"Sonarr\")'" ) ''; }