NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.32k stars 14.29k forks source link

services.deluge cannot produce(working) deluged / delugeweb systemd services #315217

Open SmolPatches opened 6 months ago

SmolPatches commented 6 months ago

Describe the bug

services.deluge fails to create a working systemd service for delugeweb and deluged while nixos-rebuild succeeds.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Enable services.deluge
  2. Enable services.delugeweb
  3. Save configuration.
  4. nixos-rebuild switch

Expected behavior

Given a proper nixos configuration, a running systemd service that actively listens for incoming connections to the main daemon and the webui was expected. Rebuilds completed successfully yet the systemd services continue to fail.

Screenshots

journalctl -u deluged

May 27 20:03:11 homelab systemd[1]: Starting Deluge BitTorrent Daemon...
May 27 20:03:11 homelab systemd[1]: Started Deluge BitTorrent Daemon.
May 27 20:03:12 homelab deluged[39826]: 20:03:12 [ERROR   ][deluge.component              :1622] [Failure instance: Traceback: <class 'PermissionError'>: [Errno 13] Permission denie>
May 27 20:03:12 homelab deluged[39826]: /nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/base.py:703:mainLoop
May 27 20:03:12 homelab deluged[39826]: /nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/base.py:1088:runUntilCurr>
May 27 20:03:12 homelab deluged[39826]: /nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/defer.py:900:callback
May 27 20:03:12 homelab deluged[39826]: /nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/defer.py:1007:_startRunCa>
May 27 20:03:12 homelab deluged[39826]: --- <exception caught here> ---
May 27 20:03:12 homelab deluged[39826]: /nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/defer.py:1101:_runCallbac>
May 27 20:03:12 homelab deluged[39826]: /nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/task.py:872:cb
May 27 20:03:12 homelab deluged[39826]: /nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py:68:start
May 27 20:03:12 homelab deluged[39826]: /nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py:279:__load_au>
May 27 20:03:12 homelab deluged[39826]: /nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/common.py:1221:create_localclient>
May 27 20:03:12 homelab deluged[39826]: ]
May 27 20:03:12 homelab deluged[39826]: Unhandled error in Deferred:
May 27 20:03:12 homelab deluged[39826]: Traceback (most recent call last):
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/base.py", line 70>
May 27 20:03:12 homelab deluged[39826]:     self.runUntilCurrent()
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/base.py", line 10>
May 27 20:03:12 homelab deluged[39826]:     call.func(*call.args, **call.kw)
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/defer.py", line 9>
May 27 20:03:12 homelab deluged[39826]:     self._startRunCallbacks(result)
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/defer.py", line 1>
May 27 20:03:12 homelab deluged[39826]:     self._runCallbacks()
May 27 20:03:12 homelab deluged[39826]: --- <exception caught here> ---
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/defer.py", line 1>
May 27 20:03:12 homelab deluged[39826]:     current.result = callback(  # type: ignore[misc]
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/task.py", line 87>
May 27 20:03:12 homelab deluged[39826]:     return callable(*args, **kw)
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py", lin>
May 27 20:03:12 homelab deluged[39826]:     self.__load_auth_file()
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py", lin>
May 27 20:03:12 homelab deluged[39826]:     create_localclient_account(True)
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/common.py", line 1221, in>
May 27 20:03:12 homelab deluged[39826]:     with open(auth_file, 'a' if append else 'w', encoding='utf8') as _file:
May 27 20:03:12 homelab deluged[39826]: builtins.PermissionError: [Errno 13] Permission denied: '/var/lib/deluge/.config/deluge/auth'

journalctl -u delugeweb

May 27 18:04:12 homelab systemd[1]: delugeweb.service: Failed with result 'exit-code'.
May 27 20:02:33 homelab systemd[1]: Started Deluge BitTorrent WebUI.
May 27 20:02:33 homelab deluge-web[39733]: Traceback (most recent call last):
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/bin/..deluge-web-wrapped-wrapped", line 9, in <module>
May 27 20:02:33 homelab deluge-web[39733]:     sys.exit(start())
May 27 20:02:33 homelab deluge-web[39733]:              ^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/web/__init__.py", l>
May 27 20:02:33 homelab deluge-web[39733]:     web.start()
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/web/web.py", line 7>
May 27 20:02:33 homelab deluge-web[39733]:     self.__server = server.DelugeWeb(options=self.options)
May 27 20:02:33 homelab deluge-web[39733]:                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/web/server.py", lin>
May 27 20:02:33 homelab deluge-web[39733]:     self.web_api = WebApi()
May 27 20:02:33 homelab deluge-web[39733]:                    ^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/web/json_api.py", l>
May 27 20:02:33 homelab deluge-web[39733]:     self.hostlist = HostList()
May 27 20:02:33 homelab deluge-web[39733]:                     ^^^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/hostlist.py", line >
May 27 20:02:33 homelab deluge-web[39733]:     default_hostlist(),
May 27 20:02:33 homelab deluge-web[39733]:     ^^^^^^^^^^^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/hostlist.py", line >
May 27 20:02:33 homelab deluge-web[39733]:     username, password = get_localhost_auth()
May 27 20:02:33 homelab deluge-web[39733]:     ^^^^^^^^^^^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]: TypeError: cannot unpack non-iterable NoneType object
May 27 20:02:33 homelab systemd[1]: delugeweb.service: Main process exited, code=exited, status=1/FAILURE
May 27 20:02:33 homelab systemd[1]: delugeweb.service: Failed with result 'exit-code'.

systemctl status deluge

● deluged.service - Deluge BitTorrent Daemon
     Loaded: loaded (/etc/systemd/system/deluged.service; enabled; preset: enabled)
     Active: active (running) since Mon 2024-05-27 20:03:11 EDT; 9min ago
    Process: 39823 ExecStartPre=/nix/store/ip0mm5ygv7q1cfaxfnhx7b7arj3n7h19-unit-script-deluged-pre-start/bin/deluged-pre-start (code=exited, status=0/SUCCESS)
   Main PID: 39826 (..deluged-wrapp)
         IP: 49.3K in, 34.5K out
         IO: 0B read, 8.0K written
      Tasks: 4 (limit: 17855)
     Memory: 41.3M
        CPU: 1.894s
     CGroup: /system.slice/deluged.service
             └─39826 /nix/store/y0v7086iqc3gwir0vf67jwy31aqk3zpx-python3-3.11.8/bin/python3.11 /nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/bin/..deluged->

May 27 20:03:12 homelab deluged[39826]:     current.result = callback(  # type: ignore[misc]
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/task.py", line 87>
May 27 20:03:12 homelab deluged[39826]:     return callable(*args, **kw)
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py", lin>
May 27 20:03:12 homelab deluged[39826]:     self.__load_auth_file()
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py", lin>
May 27 20:03:12 homelab deluged[39826]:     create_localclient_account(True)
May 27 20:03:12 homelab deluged[39826]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/common.py", line 1221, in>
May 27 20:03:12 homelab deluged[39826]:     with open(auth_file, 'a' if append else 'w', encoding='utf8') as _file:
May 27 20:03:12 homelab deluged[39826]: builtins.PermissionError: [Errno 13] Permission denied: '/var/lib/deluge/.config/deluge/auth'

systemctl status delugeweb

× delugeweb.service - Deluge BitTorrent WebUI
     Loaded: loaded (/etc/systemd/system/delugeweb.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2024-05-27 20:02:33 EDT; 8min ago
   Duration: 679ms
    Process: 39733 ExecStart=/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/bin/deluge-web --do-not-daemonize --config /var/lib/deluge/.config/deluge --port>
   Main PID: 39733 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 674ms

May 27 20:02:33 homelab deluge-web[39733]:                     ^^^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/hostlist.py", line >
May 27 20:02:33 homelab deluge-web[39733]:     default_hostlist(),
May 27 20:02:33 homelab deluge-web[39733]:     ^^^^^^^^^^^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/ui/hostlist.py", line >
May 27 20:02:33 homelab deluge-web[39733]:     username, password = get_localhost_auth()
May 27 20:02:33 homelab deluge-web[39733]:     ^^^^^^^^^^^^^^^^^^
May 27 20:02:33 homelab deluge-web[39733]: TypeError: cannot unpack non-iterable NoneType object
May 27 20:02:33 homelab systemd[1]: delugeweb.service: Main process exited, code=exited, status=1/FAILURE
May 27 20:02:33 homelab systemd[1]: delugeweb.service: Failed with result 'exit-code'.

Additional context

configuration.nix

services = {
    deluge = {
      enable = true;
      #dataDir = "/var/lib/deluge"; # default path put it here for verbosity
      web = {
        port = 8112;
        enable = true;
        openFirewall = true;
      };
      # consider using age to encrypt this file use the decrypted one at build time

#      authFile = let deluge_auth_file = (pkgs.writeText "auth" ''
      authFile = let deluge_auth_file = (builtins.toFile "auth" ''
      nixxy:password123:5
      ''); in deluge_auth_file;
      declarative = true;
      config = {

      };
      openFirewall = true;
    };
...

Note:

I have played around a lot, setting declarative to false or using a path for authFile that both deluge, root and my normalUser have access to. As well as setting services.deluge.user to nixxy(normal user), deluge(default) and root since root should have access to the directory. Setting the user to root results in

May 27 20:25:27 homelab deluged[43402]:     current.result = callback(  # type: ignore[misc]
May 27 20:25:27 homelab deluged[43402]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-packages/twisted/internet/task.py", line 87>
May 27 20:25:27 homelab deluged[43402]:     return callable(*args, **kw)
May 27 20:25:27 homelab deluged[43402]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py", lin>
May 27 20:25:27 homelab deluged[43402]:     self.__load_auth_file()
May 27 20:25:27 homelab deluged[43402]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/core/authmanager.py", lin>
May 27 20:25:27 homelab deluged[43402]:     create_localclient_account(True)
May 27 20:25:27 homelab deluged[43402]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site-packages/deluge/common.py", line 1221, in>
May 27 20:25:27 homelab deluged[43402]:     with open(auth_file, 'a' if append else 'w', encoding='utf8') as _file:
May 27 20:25:27 homelab deluged[43402]: builtins.OSError: [Errno 30] Read-only file system: '/var/lib/deluge/.config/deluge/auth'

Notify maintainers

@exarkun @Scriptkiddi @domenkozar @ebzzry

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.90, NixOS, 23.11 (Tapir), 23.11.7093.44072e24566c`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

liamwb commented 5 months ago

I think I am having the same or a similar issue. Here is my error:

building Nix...
building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for liam-server...
restarting sysinit-reactivation.target
warning: the following units failed: deluged.service

× deluged.service - Deluge BitTorrent Daemon
     Loaded: loaded (/etc/systemd/system/deluged.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Wed 2024-06-19 18:10:42 AEST; 197ms ago
   Duration: 1.205s
    Process: 122177 ExecStartPre=/nix/store/lbfbbmvndvlsr7ylrpzmycmfvq0icnhi-unit-script-deluged-pre-start/bin/deluged-pre-start (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 4ms

Jun 19 18:10:42 nixos-server systemd[1]: Starting Deluge BitTorrent Daemon...
Jun 19 18:10:42 nixos-server deluged-pre-start[122178]: cp: cannot create regular file '/var/lib/deluge/.config/deluge/core.conf': Permission denied
Jun 19 18:10:42 nixos-server systemd[1]: deluged.service: Control process exited, code=exited, status=1/FAILURE
Jun 19 18:10:42 nixos-server systemd[1]: deluged.service: Failed with result 'exit-code'.
Jun 19 18:10:42 nixos-server systemd[1]: Failed to start Deluge BitTorrent Daemon.
warning: error(s) occurred while switching to the new configuration

And here is the relevant snippet of my configuration.nix:

  # configure deluge
  services.deluge = {
    enable = true;
    web.enable = true;
    declarative = true;  # applies config, openFirewall, authFile options
    config = {
      max_active_seeding = 100;
      max_active_downloading = 100;
      max_active_limit = 200;
    };
    authFile = "/run/keys/deluge-auth";
    user = "liam-server";
  };

It's important to note that I don't know what I'm doing -- I apologise if this is not a helpful contribution.

PabloMarcendo commented 4 months ago

The Deluge documentation says

There should always be a 'localclient' entry for use by the UIs running locally by your user.

It seems that if the auth file does not contain a 'localclient' entry, deluge will attempt to add it, but since files created with builtins.toFile are readonly, this fails. By manually adding the 'localclient' entry to the auth file, the deluge service works again.

      authFile = let deluge_auth_file = (builtins.toFile "auth" ''
      localclient:password321:10
      nixxy:password123:5
      ''); in deluge_auth_file;

liamwb's issue seems to be a different one.

SmolPatches commented 4 months ago

The Deluge documentation says

There should always be a 'localclient' entry for use by the UIs running locally by your user.

It seems that if the auth file does not contain a 'localclient' entry, deluge will attempt to add it, but since files created with builtins.toFile are readonly, this fails. By manually adding the 'localclient' entry to the auth file, the deluge service works again.

      authFile = let deluge_auth_file = (builtins.toFile "auth" ''
      localclient:password321:10
      nixxy:password123:5
      ''); in deluge_auth_file;

liamwb's issue seems to be a different one.

Thanks alot, your recommendation helped! Now the original issue is remedied, I now I have a similar issue to liamwb's where the service cannot write to /var/lib/deluge/.config cannot be written to due permission errors.

deluged.service - Deluge BitTorrent Daemon
     Loaded: loaded (/etc/systemd/system/deluged.service; enabled; preset: enabled)
     Active: active (running) since Wed 2024-07-03 22:42:22 EDT; 23h ago
   Main PID: 1013 (..deluged-wrapp)
         IP: 0B in, 0B out
         IO: 32.1M read, 12.0K written
      Tasks: 5 (limit: 17855)
     Memory: 74.9M
        CPU: 2min 25.395s
     CGroup: /system.slice/deluged.service
             └─1013 /nix/store/y0v7086iqc3gwir0vf67jwy31aqk3zpx-python3-3.11.8/bin/python3.11 /nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07->

Jul 03 22:42:23 homelab deluged[1013]:     current.result = callback(  # type: ignore[misc]
Jul 03 22:42:23 homelab deluged[1013]:   File "/nix/store/czds2hrgxh9x3m9p1r4yzp1f5zzhpsi1-python3.11-twisted-23.8.0/lib/python3.11/site-p>
Jul 03 22:42:23 homelab deluged[1013]:     return callable(*args, **kw)
Jul 03 22:42:23 homelab deluged[1013]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site>
Jul 03 22:42:23 homelab deluged[1013]:     self.__load_auth_file()
Jul 03 22:42:23 homelab deluged[1013]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site>
Jul 03 22:42:23 homelab deluged[1013]:     create_localclient_account(True)
Jul 03 22:42:23 homelab deluged[1013]:   File "/nix/store/bazg52ja240d6psfx19y0hdpr7rj3g07-python3.11-deluge-gtk-2.1.1/lib/python3.11/site>
Jul 03 22:42:23 homelab deluged[1013]:     with open(auth_file, 'a' if append else 'w', encoding='utf8') as _file:
Jul 03 22:42:23 homelab deluged[1013]: builtins.OSError: [Errno 30] Read-only file system: '/var/lib/deluge/.config/deluge/auth'

To fix it, I created a folder /home/deluge and set this in configuration.nix, deluge.dataDir = "/home/deluge". After that everything worked. Let me know @liamwb if this helps you too.