diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-11-23 17:31:33 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-11-23 17:31:33 +0530 |
| commit | 0ff25a315c87a30963ee6be4799d0f30fe911f7f (patch) | |
| tree | ccfbec6df2adc9356abf2644f49c01883f2b4b81 | |
| parent | f5f2198da113394bc14e0bfad4e4aaa9ec038033 (diff) | |
| download | homeserver-nixos-config-0ff25a315c87a30963ee6be4799d0f30fe911f7f.tar.gz homeserver-nixos-config-0ff25a315c87a30963ee6be4799d0f30fe911f7f.zip | |
Lazylibrarian service (without docker)
| -rw-r--r-- | modules/media/books.nix | 40 | ||||
| -rw-r--r-- | modules/media/default.nix | 2 | ||||
| -rw-r--r-- | services/lazylibrarian/default.nix | 32 | ||||
| -rw-r--r-- | services/lazylibrarian/fix-setup.diff | 40 | ||||
| -rw-r--r-- | services/lazylibrarian/package.nix | 135 |
5 files changed, 232 insertions, 17 deletions
diff --git a/modules/media/books.nix b/modules/media/books.nix index 89aacdd..b423741 100644 --- a/modules/media/books.nix +++ b/modules/media/books.nix @@ -1,24 +1,32 @@ { settings, pkgs, ... }: { + imports = [ + ../../services/lazylibrarian/default.nix + ]; + systemd.tmpfiles.rules = [ "d ${settings.media.booksDir} 0770 - ${settings.media.group} - -" ]; - virtualisation.oci-containers.containers.lazy-librarian = { - image = "linuxserver/lazylibrarian"; - # user = "lazylibrarian:${settings.media.group}"; - imageFile = pkgs.dockerTools.pullImage { - imageName = "linuxserver/lazylibrarian"; - finalImageTag = "version-68d7f93c"; - imageDigest = "sha256:5d0c935283e5393ff57fb52e88660ccc596c170cc6f68c58045cd2c792108fdd"; - sha256 = "sha256-jpdOJhf02Nbw/yRjEzTw+unZb7Ou+Lh9kPB/0oqHYV4="; - }; - extraOptions = ["--network=host"]; - ports = ["${toString settings.network.ports.lazylibrarian}:5299"]; - volumes = [ - "${settings.media.booksDir}:/books" - "${settings.media.downloadsDir}:/downloads" - "/var/lib/lazylibrarian:/config" - ]; + services.lazylibrarian = { + enable = true; }; + + # virtualisation.oci-containers.containers.lazy-librarian = { + # image = "linuxserver/lazylibrarian"; + # # user = "lazylibrarian:${settings.media.group}"; + # imageFile = pkgs.dockerTools.pullImage { + # imageName = "linuxserver/lazylibrarian"; + # finalImageTag = "version-68d7f93c"; + # imageDigest = "sha256:5d0c935283e5393ff57fb52e88660ccc596c170cc6f68c58045cd2c792108fdd"; + # sha256 = "sha256-jpdOJhf02Nbw/yRjEzTw+unZb7Ou+Lh9kPB/0oqHYV4="; + # }; + # extraOptions = ["--network=host"]; + # ports = ["${toString settings.network.ports.lazylibrarian}:5299"]; + # volumes = [ + # "${settings.media.booksDir}:/books" + # "${settings.media.downloadsDir}:/downloads" + # "/var/lib/lazylibrarian:/config" + # ]; + # }; } diff --git a/modules/media/default.nix b/modules/media/default.nix index 7925295..78adefb 100644 --- a/modules/media/default.nix +++ b/modules/media/default.nix @@ -4,7 +4,7 @@ ./torrent.nix ./servarr.nix ./jellyfin.nix - # ./books.nix + ./books.nix ]; systemd.tmpfiles.rules = [ diff --git a/services/lazylibrarian/default.nix b/services/lazylibrarian/default.nix new file mode 100644 index 0000000..4514713 --- /dev/null +++ b/services/lazylibrarian/default.nix @@ -0,0 +1,32 @@ +{ config, pkgs, lib, ... }: +with lib; +let + lazylibrarian = pkgs.callPackage ./package.nix {}; + cfg = config.services.lazylibrarian; +in +{ + options.services.lazylibrarian = { + enable = mkEnableOption "lazy librarian"; + # port = mkOption { type = types.int; default = 53; }; + # hosts = mkOption { type = types.attrsOf types.str; default = {}; }; + }; + + environment.systemPackages = [lazylibrarian]; + + config.systemd.services.lazylibrarian = mkIf cfg.enable { + description = "Lazylibrarian"; + after = [ "network.service" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = "${lazylibrarian}/bin/lazylibrarian"; + Restart = "on-failure"; + RestartSec = 3; + TimeoutSec = "5min"; + IgnoreSIGPIPE = "no"; + KillMode = "process"; + GuessMainPID = "no"; + RemainAfterExit = "yes"; + }; + }; +} diff --git a/services/lazylibrarian/fix-setup.diff b/services/lazylibrarian/fix-setup.diff new file mode 100644 index 0000000..d86a2d7 --- /dev/null +++ b/services/lazylibrarian/fix-setup.diff @@ -0,0 +1,40 @@ +diff --git a/MANIFEST.in b/MANIFEST.in +new file mode 100644 +index 00000000..bec3e4d2 +--- /dev/null ++++ b/MANIFEST.in +@@ -0,0 +1 @@ ++recursive-include src/data * +diff --git a/pyproject.toml b/pyproject.toml +index b415e8cb..252f761e 100644 +--- a/pyproject.toml ++++ b/pyproject.toml +@@ -2,9 +2,6 @@ + requires = ["setuptools", "ez_setup"] + build-backend = "setuptools.build_meta" + +-[tool.setuptools.packages.find] +-where = ["lazylibrarian"] +- + [project] + name = "LazyLibrarian" + version = "2025.01.09" +@@ -16,7 +13,7 @@ classifiers = [ + ] + + dependencies = [ +- 'bs4', ++ 'beautifulsoup4', + 'html5lib', + 'webencodings', + 'requests[use_chardet_on_py3]', +@@ -44,6 +41,9 @@ dependencies = [ + "Documentation" = "https://lazylibrarian.gitlab.io/" + "Issue Tracker" = "https://gitlab.com/LazyLibrarian/LazyLibrarian/-/issues" + ++[project.scripts] ++lazylibrarian = "LazyLibrarian:main" ++ + # Config file for pytest + [tool.pytest.ini_options] + pythonpath = "." diff --git a/services/lazylibrarian/package.nix b/services/lazylibrarian/package.nix new file mode 100644 index 0000000..0df6845 --- /dev/null +++ b/services/lazylibrarian/package.nix @@ -0,0 +1,135 @@ +# https://github.com/NixOS/nixpkgs/pull/423722/files +{ + calibre, + fetchFromGitLab, + fetchPypi, + ffmpeg-headless, + lib, + nix-update-script, + python3Packages, + calibreSupport ? true, + ffmpegSupport ? true, +}: +let + ez_setup = python3Packages.buildPythonPackage rec { + pname = "ez_setup"; + version = "0.9"; + pyproject = true; + + src = fetchPypi { + inherit pname version; + hash = "sha256-MDxbF9VS0eP7BQXYBUn4V59VfhPY3JDl7O88B9f1hkI="; + }; + + build-system = with python3Packages; [ + distutils + setuptools + wheel + ]; + + pythonImportsCheck = [ + "ez_setup" + ]; + }; + + slskd-api = python3Packages.buildPythonPackage rec { + pname = "slskd-api"; + version = "0.1.5"; + pyproject = true; + + src = fetchPypi { + inherit pname version; + hash = "sha256-LmWP7bnK5IVid255qS2NGOmyKzGpUl3xsO5vi5uJI88="; + }; + + build-system = with python3Packages; [ + setuptools + setuptools-git-versioning + wheel + ]; + + dependencies = with python3Packages; [ + requests + ]; + + pythonImportsCheck = [ + "slskd_api" + ]; + }; +in +python3Packages.buildPythonApplication rec { + pname = "lazylibrarian"; + version = "2025.01.09-unstable-2025-07-08"; + pyproject = true; + + src = fetchFromGitLab { + owner = "LazyLibrarian"; + repo = "LazyLibrarian"; + rev = "d88acba6332ebcc517b1d071a27a0b5afe522c0f"; + hash = "sha256-HMoV9pLCdgppmSHJfJcpEWiogTJys1qIjeHvXpT+3fo="; + }; + + patches = [ + ./fix-setup.diff + ]; + + postPatch = '' + mkdir -p src + mv LazyLibrarian.py lazylibrarian lib data src + ''; + + build-system = with python3Packages; [ + ez_setup + setuptools + ]; + + dependencies = + with python3Packages; + [ + apprise + apscheduler + beautifulsoup4 + cherrypy + cherrypy-cors + deluge-client + html5lib + httpagentparser + httplib2 + irc + mako + pillow + pyopenssl + pyparsing + pypdf + python-magic + rapidfuzz + requests + tzdata + urllib3 + webencodings + ] + ++ [ slskd-api ] + ++ lib.optional calibreSupport [ calibre ] + ++ lib.optional ffmpegSupport [ ffmpeg-headless ]; + + pythonImportsCheck = [ + "lazylibrarian" + ]; + + makeWrapperArgs = [ + # Avoid automatic updates. + "--set DOCKER 1" + # Avoid `datadir` being on `/nix/store` by default. + "--add-flags --datadir=\\$XDG_DATA_HOME/${meta.mainProgram}" + ]; + + passthru.updateScript = nix-update-script { }; + + meta = { + description = "Usenet/BitTorrent ebook, audiobook and magazine downloader"; + homepage = "https://lazylibrarian.gitlab.io/"; + license = lib.licenses.gpl3Only; + maintainers = with lib.maintainers; [ xelden ]; + mainProgram = "lazylibrarian"; + }; +} |
