diff --git a/nixos/doc/manual/release-notes/rl-2605.section.md b/nixos/doc/manual/release-notes/rl-2605.section.md index e7bbe1501de4..80a40403e09c 100644 --- a/nixos/doc/manual/release-notes/rl-2605.section.md +++ b/nixos/doc/manual/release-notes/rl-2605.section.md @@ -164,6 +164,8 @@ - [LogiOps](https://github.com/PixlOne/logiops), a unofficial userspace driver for HID++ Logitech devices. Available as [services.logiops](#opt-services.logiops.enable). +- [Unpackerr](https://unpackerr.zip), extracts downloads for Radarr, Sonarr, Lidarr, Readarr, and/or a Watch folder. Available as [services.unpackerr](#opt-services.unpackerr.enable). + ## Backward Incompatibilities {#sec-release-26.05-incompatibilities} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index c57b627e875c..3a5cd4d5de07 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -993,6 +993,7 @@ ./services/misc/tuxclocker.nix ./services/misc/tzupdate.nix ./services/misc/uhub.nix + ./services/misc/unpackerr.nix ./services/misc/wastebin.nix ./services/misc/weechat.nix ./services/misc/workout-tracker.nix diff --git a/nixos/modules/services/misc/unpackerr.nix b/nixos/modules/services/misc/unpackerr.nix new file mode 100644 index 000000000000..710c44346b66 --- /dev/null +++ b/nixos/modules/services/misc/unpackerr.nix @@ -0,0 +1,102 @@ +{ + config, + pkgs, + lib, + utils, + ... +}: + +let + cfg = config.services.unpackerr; + configFormat = pkgs.formats.toml { }; + configFile = configFormat.generate "unpackerr.conf" cfg.settings; + inherit (lib) + mkEnableOption + mkOption + mkPackageOption + mkIf + getExe + types + ; +in +{ + options = { + services.unpackerr = { + enable = mkEnableOption "Unpackerr"; + + settings = mkOption { + type = configFormat.type; + default = { }; + example = { + radarr = [ + { + url = "http://127.0.0.1:8989"; + api_key = "0123456789abcdef0123456789abcdef"; + } + ]; + sonarr = [ + { + url = "http://127.0.0.1:7878"; + api_key = "0123456789abcdef0123456789abcdef"; + } + ]; + }; + description = '' + Unpackerr TOML configuration as a Nix attribute set. + Refer to [Unpackerr docs](https://unpackerr.zip/docs/install/configuration) for details. + For setting secrets refer to this [section](https://unpackerr.zip/docs/install/configuration/#secrets-and-passwords). + ''; + }; + + user = mkOption { + type = types.str; + default = "unpackerr"; + description = "User account under which Unpackerr runs."; + }; + + group = mkOption { + type = types.str; + default = "unpackerr"; + description = "Group under which Unpackerr runs."; + }; + + package = mkPackageOption pkgs "unpackerr" { }; + }; + }; + + config = mkIf cfg.enable { + # Upstream service: https://github.com/Unpackerr/unpackerr/blob/main/init/systemd/unpackerr.service + systemd = { + services.unpackerr = { + description = "Unpackerr - archive extraction daemon"; + wants = [ "network.target" ]; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "exec"; + User = cfg.user; + Group = cfg.group; + ExecStart = utils.escapeSystemdExecArgs [ + (getExe cfg.package) + "--config=${configFile}" + ]; + Restart = "always"; + RestartSec = 10; + }; + }; + }; + + users.users = mkIf (cfg.user == "unpackerr") { + unpackerr = { + inherit (cfg) group; + isSystemUser = true; + }; + }; + + users.groups = mkIf (cfg.group == "unpackerr") { + unpackerr = { }; + }; + }; + + meta.maintainers = with lib.maintainers; [ Wekuz ]; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index f9ecf72845ed..094c51303df0 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1737,6 +1737,7 @@ in unifi = runTest ./unifi.nix; unit-perl = runTest ./web-servers/unit-perl.nix; unit-php = runTest ./web-servers/unit-php.nix; + unpackerr = runTest ./unpackerr.nix; upnp.iptables = handleTest ./upnp.nix { useNftables = false; }; upnp.nftables = handleTest ./upnp.nix { useNftables = true; }; uptermd = runTest ./uptermd.nix; diff --git a/nixos/tests/unpackerr.nix b/nixos/tests/unpackerr.nix new file mode 100644 index 000000000000..d0a918f772a3 --- /dev/null +++ b/nixos/tests/unpackerr.nix @@ -0,0 +1,39 @@ +{ lib, ... }: + +{ + name = "unpackerr"; + meta.maintainers = with lib.maintainers; [ Wekuz ]; + + nodes.machine = + { pkgs, ... }: + { + environment.systemPackages = with pkgs; [ zip ]; + + systemd.tmpfiles.settings."10-unpackerr"."/srv/unpackerr".d = { + mode = "0775"; + user = "unpackerr"; + group = "users"; + }; + + services.unpackerr = { + enable = true; + group = "users"; + settings = { + start_delay = "15s"; + folder = [ + { + path = "/srv/unpackerr"; + } + ]; + }; + }; + }; + + testScript = '' + machine.wait_for_unit("unpackerr.service") + machine.wait_until_succeeds("journalctl -u unpackerr.service --grep '\\[Folder\\] Watching \\(fsnotify\\)'", timeout=60) + machine.succeed("echo unpackerr-test > /tmp/file.txt && cd /tmp && zip /srv/unpackerr/test.zip ./file.txt && rm ./file.txt") + machine.wait_until_succeeds("[[ -d /srv/unpackerr/test ]]", timeout=120) + machine.succeed("""[[ 'unpackerr-test' == "$(< /srv/unpackerr/test/file.txt)" ]]""") + ''; +}