From 7247996024d6e2ea1fa3b48e895c17179b207c2a Mon Sep 17 00:00:00 2001 From: Alex Galvin Date: Fri, 9 Feb 2024 17:55:06 -0500 Subject: [PATCH] nixos/autobrr: init --- .../manual/release-notes/rl-2505.section.md | 2 + nixos/modules/module-list.nix | 1 + nixos/modules/services/misc/autobrr.nix | 71 +++++++++++++++++++ nixos/tests/all-tests.nix | 1 + nixos/tests/autobrr.nix | 20 ++++++ 5 files changed, 95 insertions(+) create mode 100644 nixos/modules/services/misc/autobrr.nix create mode 100644 nixos/tests/autobrr.nix diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index 10645d55e8389..7b297b9037fa6 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -14,6 +14,8 @@ - [Kimai](https://www.kimai.org/), a web-based multi-user time-tracking application. Available as [services.kimai](option.html#opt-services.kimai). +- [autobrr](https://autobrr.com), a modern download automation tool for torrents and usenets. Available as [services.autobrr](#opt-services.autobrr.enable). + - [Amazon CloudWatch Agent](https://github.com/aws/amazon-cloudwatch-agent), the official telemetry collector for AWS CloudWatch and AWS X-Ray. Available as [services.amazon-cloudwatch-agent](#opt-services.amazon-cloudwatch-agent.enable). diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 91ecee0ef265c..8e58605aec493 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -727,6 +727,7 @@ ./services/misc/anki-sync-server.nix ./services/misc/apache-kafka.nix ./services/misc/atuin.nix + ./services/misc/autobrr.nix ./services/misc/autofs.nix ./services/misc/autorandr.nix ./services/misc/autosuspend.nix diff --git a/nixos/modules/services/misc/autobrr.nix b/nixos/modules/services/misc/autobrr.nix new file mode 100644 index 0000000000000..10efc9ea554a9 --- /dev/null +++ b/nixos/modules/services/misc/autobrr.nix @@ -0,0 +1,71 @@ +{ + config, + pkgs, + lib, + ... +}: + +with lib; + +let + cfg = config.services.autobrr; + configFormat = pkgs.formats.toml { }; + configFile = configFormat.generate "autobrr.toml" cfg.settings; +in +{ + options = { + services.autobrr = { + enable = mkEnableOption "Autobrr"; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = "Open ports in the firewall for the Autobrr web interface."; + }; + + package = mkPackageOption pkgs "autobrr" { }; + + settings = lib.mkOption { + type = lib.types.submodule { freeformType = configFormat.type; }; + default = { + host = "127.0.0.1"; + port = "7474"; + checkForUpdates = true; + sessionSecret = "not-sure-how-to-store-this-safely"; + }; + example = { + logLevel = "DEBUG"; + }; + description = '' + Autobrr configuration options. + + Refer to + for a full list. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.services.autobrr = { + description = "Autobrr"; + after = [ + "syslog.target" + "network-online.target" + ]; + wants = [ "network-online.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Type = "simple"; + DynamicUser = true; + StateDirectory = "autobrr"; + StateDirectoryMode = "0700"; + ExecStart = "${pkgs.autobrr}/bin/autobrr --config '${configFile}'"; + Restart = "on-failure"; + }; + }; + + networking.firewall = mkIf cfg.openFirewall { allowedTCPPorts = [ 7575 ]; }; + }; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 6f941cc254ad4..eede2fc66db51 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -143,6 +143,7 @@ in { audiobookshelf = handleTest ./audiobookshelf.nix {}; auth-mysql = handleTest ./auth-mysql.nix {}; authelia = handleTest ./authelia.nix {}; + autobrr = handleTest ./autobrr.nix {}; avahi = handleTest ./avahi.nix {}; avahi-with-resolved = handleTest ./avahi.nix { networkd = true; }; ayatana-indicators = runTest ./ayatana-indicators.nix; diff --git a/nixos/tests/autobrr.nix b/nixos/tests/autobrr.nix new file mode 100644 index 0000000000000..4558fd1a781a5 --- /dev/null +++ b/nixos/tests/autobrr.nix @@ -0,0 +1,20 @@ +import ./make-test-python.nix ( + { lib, ... }: + + { + name = "autobrr"; + meta.maintainers = with lib.maintainers; [ av-gal ]; + + nodes.machine = + { pkgs, ... }: + { + services.autobrr.enable = true; + }; + + testScript = '' + machine.wait_for_unit("autobrr.service") + machine.wait_for_open_port(7474) + machine.succeed("curl --fail http://localhost:7474/") + ''; + } +)