From e7f54823b1f8443f616096bd100c337ab6bbfd46 Mon Sep 17 00:00:00 2001 From: Jocelyn Thode Date: Sun, 12 Mar 2023 20:54:23 +0100 Subject: [PATCH] readarr: init at 0.1.4.1596 --- .../manual/release-notes/rl-2305.section.md | 1 + nixos/modules/module-list.nix | 1 + nixos/modules/services/misc/readarr.nix | 88 +++++++++++++++++++ nixos/tests/all-tests.nix | 1 + nixos/tests/readarr.nix | 18 ++++ pkgs/servers/readarr/default.nix | 53 +++++++++++ pkgs/servers/readarr/update.sh | 44 ++++++++++ pkgs/top-level/all-packages.nix | 2 + 8 files changed, 208 insertions(+) create mode 100644 nixos/modules/services/misc/readarr.nix create mode 100644 nixos/tests/readarr.nix create mode 100644 pkgs/servers/readarr/default.nix create mode 100755 pkgs/servers/readarr/update.sh diff --git a/nixos/doc/manual/release-notes/rl-2305.section.md b/nixos/doc/manual/release-notes/rl-2305.section.md index 1bd8906cf64..2ee63841a1f 100644 --- a/nixos/doc/manual/release-notes/rl-2305.section.md +++ b/nixos/doc/manual/release-notes/rl-2305.section.md @@ -33,6 +33,7 @@ In addition to numerous new and upgraded packages, this release has the followin - [Cloudlog](https://www.magicbug.co.uk/cloudlog/), a web-based Amateur Radio logging application. Available as [services.cloudlog](#opt-services.cloudlog.enable). - [fzf](https://github.com/junegunn/fzf), a command line fuzzyfinder. Available as [programs.fzf](#opt-programs.fzf.fuzzyCompletion). +- [readarr](https://github.com/Readarr/Readarr), Book Manager and Automation (Sonarr for Ebooks). Available as [services.readarr](options.html#opt-services.readarr.enable). - [gemstash](https://github.com/rubygems/gemstash), a RubyGems.org cache and private gem server. Available as [services.gemstash](#opt-services.gemstash.enable). diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index e1e30c99a44..01c0d8f2152 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -665,6 +665,7 @@ ./services/misc/prowlarr.nix ./services/misc/pykms.nix ./services/misc/radarr.nix + ./services/misc/readarr.nix ./services/misc/redmine.nix ./services/misc/ripple-data-api.nix ./services/misc/rippled.nix diff --git a/nixos/modules/services/misc/readarr.nix b/nixos/modules/services/misc/readarr.nix new file mode 100644 index 00000000000..dd4fef6e598 --- /dev/null +++ b/nixos/modules/services/misc/readarr.nix @@ -0,0 +1,88 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.readarr; +in +{ + options = { + services.readarr = { + enable = mkEnableOption (lib.mdDoc "Readarr"); + + dataDir = mkOption { + type = types.str; + default = "/var/lib/readarr/"; + description = lib.mdDoc "The directory where Readarr stores its data files."; + }; + + package = mkOption { + type = types.package; + default = pkgs.readarr; + defaultText = literalExpression "pkgs.readarr"; + description = lib.mdDoc "The Readarr package to use"; + }; + + openFirewall = mkOption { + type = types.bool; + default = false; + description = lib.mdDoc '' + Open ports in the firewall for Readarr + ''; + }; + + user = mkOption { + type = types.str; + default = "readarr"; + description = lib.mdDoc '' + User account under which Readarr runs. + ''; + }; + + group = mkOption { + type = types.str; + default = "readarr"; + description = lib.mdDoc '' + Group under which Readarr runs. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.tmpfiles.rules = [ + "d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -" + ]; + + systemd.services.readarr = { + description = "Readarr"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + Type = "simple"; + User = cfg.user; + Group = cfg.group; + ExecStart = "${cfg.package}/bin/Readarr -nobrowser -data='${cfg.dataDir}'"; + Restart = "on-failure"; + }; + }; + + networking.firewall = mkIf cfg.openFirewall { + allowedTCPPorts = [ 8787 ]; + }; + + users.users = mkIf (cfg.user == "readarr") { + readarr = { + description = "Readarr service"; + home = cfg.dataDir; + group = cfg.group; + isSystemUser = true; + }; + }; + + users.groups = mkIf (cfg.group == "readarr") { + readarr = { }; + }; + }; +} diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index c1059f8c984..687549c42ed 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -584,6 +584,7 @@ in { radarr = handleTest ./radarr.nix {}; radicale = handleTest ./radicale.nix {}; rasdaemon = handleTest ./rasdaemon.nix {}; + readarr = handleTest ./readarr.nix {}; redis = handleTest ./redis.nix {}; redmine = handleTest ./redmine.nix {}; restartByActivationScript = handleTest ./restart-by-activation-script.nix {}; diff --git a/nixos/tests/readarr.nix b/nixos/tests/readarr.nix new file mode 100644 index 00000000000..bb7dd852984 --- /dev/null +++ b/nixos/tests/readarr.nix @@ -0,0 +1,18 @@ +import ./make-test-python.nix ({ lib, ... }: + +with lib; + +{ + name = "readarr"; + meta.maintainers = with maintainers; [ jocelynthode ]; + + nodes.machine = + { pkgs, ... }: + { services.readarr.enable = true; }; + + testScript = '' + machine.wait_for_unit("readarr.service") + machine.wait_for_open_port(8787) + machine.succeed("curl --fail http://localhost:8787/") + ''; +}) diff --git a/pkgs/servers/readarr/default.nix b/pkgs/servers/readarr/default.nix new file mode 100644 index 00000000000..9fdec498889 --- /dev/null +++ b/pkgs/servers/readarr/default.nix @@ -0,0 +1,53 @@ +{ lib, stdenv, fetchurl, libmediainfo, sqlite, curl, makeWrapper, icu, dotnet-runtime, openssl, nixosTests }: + +let + os = if stdenv.isDarwin then "osx" else "linux"; + arch = { + x86_64-linux = "x64"; + aarch64-linux = "arm64"; + x86_64-darwin = "x64"; + }."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); + hash = { + x64-linux_hash = "sha256-ABk2wxNse8dcFWEMpaXnsALz171/1JQaAFzmpz36we0="; + arm64-linux_hash = "sha256-c1eVCPE8RH9u99hYJZBiNBpanBv3WeSTVaD+Gq1yxUk="; + x64-osx_hash = "sha256-9UEi8YbpZ1baZ9lnG7SJcYnvJRgP7BsqcIt9Z3UdDv8="; + }."${arch}-${os}_hash"; +in stdenv.mkDerivation rec { + pname = "readarr"; + version = "0.1.4.1596"; + + src = fetchurl { + url = "https://github.com/Readarr/Readarr/releases/download/v${version}/Readarr.develop.${version}.${os}-core-${arch}.tar.gz"; + sha256 = hash; + }; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/{bin,share/${pname}-${version}} + cp -r * $out/share/${pname}-${version}/. + makeWrapper "${dotnet-runtime}/bin/dotnet" $out/bin/Readarr \ + --add-flags "$out/share/${pname}-${version}/Readarr.dll" \ + --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ curl sqlite libmediainfo icu openssl ]} + + runHook postInstall + ''; + + + passthru = { + updateScript = ./update.sh; + tests.smoke-test = nixosTests.readarr; + }; + + meta = with lib; { + description = "A Usenet/BitTorrent ebook downloader"; + homepage = "https://readarr.com"; + license = licenses.gpl3; + maintainers = [ maintainers.jocelynthode ]; + sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; + platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; + }; +} + diff --git a/pkgs/servers/readarr/update.sh b/pkgs/servers/readarr/update.sh new file mode 100755 index 00000000000..0372ac9fa1a --- /dev/null +++ b/pkgs/servers/readarr/update.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl gnused nix-prefetch jq + +set -e + +dirname="$(dirname "$0")" + +updateHash() +{ + version=$1 + arch=$2 + os=$3 + + hashKey="${arch}-${os}_hash" + + url="https://github.com/Readarr/Readarr/releases/download/v$version/Readarr.develop.$version.$os-core-$arch.tar.gz" + hash=$(nix-prefetch-url --type sha256 $url) + sriHash="$(nix hash to-sri --type sha256 $hash)" + + sed -i "s|$hashKey = \"[a-zA-Z0-9\/+-=]*\";|$hashKey = \"$sriHash\";|g" "$dirname/default.nix" +} + +updateVersion() +{ + sed -i "s/version = \"[0-9.]*\";/version = \"$1\";/g" "$dirname/default.nix" +} + +currentVersion=$(cd $dirname && nix eval --raw -f ../../.. readarr.version) + +# We cannot use the latest releases as in the past Readarr released old version with v2.0 and then went back to 0.1 +latestTag=$(curl https://api.github.com/repos/Readarr/Readarr/releases | jq -r ".[0].tag_name") +latestVersion="$(expr $latestTag : 'v\(.*\)')" + +if [[ "$currentVersion" == "$latestVersion" ]]; then + echo "Readarr is up-to-date: ${currentVersion}" + exit 0 +fi + +updateVersion $latestVersion + +updateHash $latestVersion x64 linux +updateHash $latestVersion arm64 linux +updateHash $latestVersion x64 osx + diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 36577abfc3c..a23f1c5be7a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11546,6 +11546,8 @@ with pkgs; react-native-debugger = callPackage ../development/tools/react-native-debugger { }; + readarr = callPackage ../servers/readarr { }; + read-edid = callPackage ../os-specific/linux/read-edid { }; readstat = callPackage ../applications/science/math/readstat { };