From c4d676c9f91cdbed42a3033ccdc0929645d950da Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Tue, 17 Dec 2024 17:26:57 +0100 Subject: [PATCH] Test new jellyseerr version --- machines/atlas/configuration.nix | 15 ++++- machines/atlas/jellyseerr-module.nix | 76 ++++++++++++++++++++++++ machines/atlas/jellyseerr.nix | 89 ++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 machines/atlas/jellyseerr-module.nix create mode 100644 machines/atlas/jellyseerr.nix diff --git a/machines/atlas/configuration.nix b/machines/atlas/configuration.nix index 6b28f8d..eb1dda3 100644 --- a/machines/atlas/configuration.nix +++ b/machines/atlas/configuration.nix @@ -1,4 +1,12 @@ -{config, ...}: { +{ + config, + pkgs, + ... +}: { + imports = [./jellyseerr-module.nix]; + + disabledModules = ["services/misc/jellyseerr.nix"]; + config = { facter.reportPath = ./facter.json; system.stateVersion = "23.05"; @@ -10,5 +18,10 @@ targetUser = "root"; tags = ["server" "kubernetes"]; }; + + services.jellyseerr = { + enable = true; + package = pkgs.callPackage ./jellyseerr.nix {}; + }; }; } diff --git a/machines/atlas/jellyseerr-module.nix b/machines/atlas/jellyseerr-module.nix new file mode 100644 index 0000000..05d5364 --- /dev/null +++ b/machines/atlas/jellyseerr-module.nix @@ -0,0 +1,76 @@ +{ + config, + pkgs, + lib, + ... +}: let + cfg = config.services.jellyseerr; +in { + meta.maintainers = with lib.maintainers; [camillemndn pizzapim]; + + options.services.jellyseerr = { + enable = lib.mkEnableOption ''Jellyseerr, a requests manager for Jellyfin''; + package = lib.mkPackageOption pkgs "jellyseerr" {}; + + openFirewall = lib.mkOption { + type = lib.types.bool; + default = false; + description = ''Open port in the firewall for the Jellyseerr web interface.''; + }; + + port = lib.mkOption { + type = lib.types.port; + default = 5055; + description = ''The port which the Jellyseerr web UI should listen to.''; + }; + + config_directory = lib.mkOption { + description = '' + The directory to save run-time configuration. + ''; + type = lib.types.str; + example = "/jellyseerr"; + default = "/var/lib/jellyseerr"; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.services.jellyseerr = { + description = "Jellyseerr, a requests manager for Jellyfin"; + after = ["network.target"]; + wantedBy = ["multi-user.target"]; + environment = { + PORT = toString cfg.port; + CONFIG_DIRECTORY = cfg.config_directory; + }; + serviceConfig = { + Type = "exec"; + StateDirectory = "jellyseerr"; + # WorkingDirectory = "${cfg.package}/libexec/jellyseerr/deps/jellyseerr"; + DynamicUser = true; + ExecStart = lib.getExe cfg.package; + # BindPaths = ["/var/lib/jellyseerr/:${cfg.package}/libexec/jellyseerr/deps/jellyseerr/config/"]; + Restart = "on-failure"; + ProtectHome = true; + ProtectSystem = "strict"; + PrivateTmp = true; + PrivateDevices = true; + ProtectHostname = true; + ProtectClock = true; + ProtectKernelTunables = true; + ProtectKernelModules = true; + ProtectKernelLogs = true; + ProtectControlGroups = true; + NoNewPrivileges = true; + RestrictRealtime = true; + RestrictSUIDSGID = true; + RemoveIPC = true; + PrivateMounts = true; + }; + }; + + networking.firewall = lib.mkIf cfg.openFirewall { + allowedTCPPorts = [cfg.port]; + }; + }; +} diff --git a/machines/atlas/jellyseerr.nix b/machines/atlas/jellyseerr.nix new file mode 100644 index 0000000..2b3b52f --- /dev/null +++ b/machines/atlas/jellyseerr.nix @@ -0,0 +1,89 @@ +{ + lib, + fetchFromGitHub, + makeWrapper, + node-pre-gyp, + nodejs, + pnpm_9, + python3, + stdenv, +}: +stdenv.mkDerivation (finalAttrs: { + pname = "jellyseerr"; + version = "2.1.0"; + + src = with finalAttrs; + fetchFromGitHub { + owner = "Fallenbagel"; + repo = "jellyseerr"; + rev = "v${version}"; + hash = "sha256-5kaeqhjUy9Lgx4/uFcGRlAo+ROEOdTWc2m49rq8R8Hs="; + }; + + nativeBuildInputs = [ + nodejs + makeWrapper + pnpm_9.configHook + + # Needed for compiling sqlite3 and bcrypt from source + node-pre-gyp + python3 + ]; + + pnpmDeps = pnpm_9.fetchDeps { + inherit (finalAttrs) pname version src; + hash = "sha256-xu6DeaBArQmnqEnIgjc1DTZujQebSkjuai9tMHeQWCk="; + }; + + buildPhase = '' + runHook preBuild + pnpm build + + # Fixes "SQLite package has not been found installed" at launch + pushd node_modules/sqlite3 + export CPPFLAGS="-I${nodejs}/include/node" + npm run install --build-from-source --nodedir=${nodejs}/include/node + popd + + pushd node_modules/bcrypt + export CPPFLAGS="-I${nodejs}/include/node" + npm run install --build-from-source --nodedir=${nodejs}/include/node + popd + + runHook postBuild + ''; + + preInstall = '' + mkdir $out + cp ./package.json $out + rm -r .next/cache + cp -R ./.next $out + cp -R ./dist $out + cp ./overseerr-api.yml $out + cp -R ./node_modules $out + ''; + + postInstall = '' + makeWrapper '${nodejs}/bin/node' "$out/bin/jellyseerr" \ + --chdir $out \ + --add-flags "$out/dist/index.js" \ + --set NODE_ENV production + ''; + + meta = with lib; { + description = "Fork of overseerr for jellyfin support"; + homepage = "https://github.com/Fallenbagel/jellyseerr"; + longDescription = '' + Jellyseerr is a free and open source software application for managing + requests for your media library. It is a a fork of Overseerr built to + bring support for Jellyfin & Emby media servers! + ''; + license = licenses.mit; + maintainers = with maintainers; [ + camillemndn + pizzapim + ]; + platforms = platforms.linux; + mainProgram = "jellyseerr"; + }; +})