Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autobrr: init at 1.51.0 #287593

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,12 @@
githubId = 59499799;
keys = [ { fingerprint = "A0FF 4F26 6B80 0B86 726D EA5B 3C23 C7BD 9945 2036"; } ];
};
av-gal = {
email = "[email protected]";
github = "av-gal";
githubId = 32237198;
name = "Alex Galvin";
};
avh4 = {
email = "[email protected]";
github = "avh4";
Expand Down
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

- [agorakit](https://github.com/agorakit/agorakit), an organization tool for citizens' collectives. Available with [services.agorakit](#opt-services.agorakit.enable).
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,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
Expand Down
76 changes: 76 additions & 0 deletions nixos/modules/services/misc/autobrr.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{ config, pkgs, lib, ... }:

with lib;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider inherits where you find yourself using lib.* excessively.
this nix.dev page on best practices with with may be helpful
an issue (#208242) has been made to track inappropriate uses of with such as this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just prefix the used library function with lib..


let
cfg = config.services.autobrr;
configFormat = pkgs.formats.toml { };
configTemplate = 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.";
};

secretFile = mkOption {
type = types.path;
description =
"File containing the session secret for the Autobrr web interface.";
};

settings = lib.mkOption {
type = lib.types.submodule { freeformType = configFormat.type; };
default = {
host = "127.0.0.1";
port = "7474";
checkForUpdates = true;
};
example = { logLevel = "DEBUG"; };
description = ''
Autobrr configuration options.

Refer to <https://autobrr.com/configuration/autobrr>
for a full list.
'';
};

package = mkPackageOption pkgs "autobrr" { };
};
};

config = mkIf cfg.enable {
assertions = [{
assertion = cfg.settings.sessionSecret == null;
message = "Session secrets must be passed using the secretFile option.";
}];

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";
ExecPreStart =
"${lib.getExe pkgs.dasel} put -f '${configTemplate}' -v '${
builtins.readFile cfg.secretFile
}' -o %S/config.toml 'sessionSecret'";
ExecStart = "${lib.getExe pkgs.autobrr} --config %S/config.toml";
Restart = "on-failure";
};
};

networking.firewall =
mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.settings.port ]; };
};
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions nixos/tests/autobrr.nix
Original file line number Diff line number Diff line change
@@ -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/")
'';
}
)
83 changes: 83 additions & 0 deletions pkgs/by-name/au/autobrr/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
lib,
cacert,
buildGoModule,
fetchFromGitHub,
stdenvNoCC,
nix-update-script,
nodejs,
nodePackages,
pnpm_9,
typescript,
}:

let
pname = "autobrr";
version = "1.51.1";
src = fetchFromGitHub {
owner = "autobrr";
repo = "autobrr";
rev = "v${version}";
hash = "sha256-2lAIx9wyuZ/ILXX66UoDAw122xF35Ij/omT0ynvQFvg=";
};

autobrr-web = stdenvNoCC.mkDerivation {
pname = "${pname}-web";
inherit src version;

nativeBuildInputs = [
nodejs
pnpm_9.configHook
typescript
];

sourceRoot = "${src.name}/web";

pnpmDeps = pnpm_9.fetchDeps {
inherit (autobrr-web)
pname
version
src
sourceRoot
;
hash = "sha256-TcfxE18nkOSxa4UG2euK1hViPw8tY0TS6tayGJsNNog=";
};

postBuild = ''
pnpm run build
'';

installPhase = ''
cp -r dist $out
'';
};
in
buildGoModule rec {
inherit
autobrr-web
pname
version
src
;

vendorHash = "sha256-kKyRDIgPsd4uFqIsVRJlxkcQab01xlnX/q349CPIafQ=";

preBuild = ''
cp -r ${autobrr-web}/* web/dist
'';

ldflags = [
"-X main.version=${version}"
"-X main.commit=${src.rev}"
];

passthru.updateScript = nix-update-script { };

meta = with lib; {
description = "Modern, easy to use download automation for torrents and usenet";
license = licenses.gpl2Plus;
homepage = "https://autobrr.com/";
maintainers = with maintainers; [ av-gal ];
mainProgram = "autobrr";
};
av-gal marked this conversation as resolved.
Show resolved Hide resolved
}
Loading