From 9660dc4e92d9053b0fd955b8e57cbaa43d4d2630 Mon Sep 17 00:00:00 2001 From: Hilton Chain Date: Sat, 3 Dec 2022 11:29:34 +0800 Subject: [PATCH] services: Add qbittorrent-service-type. * rosenthal/services/bittorrent.scm: New file. (qbittorrent-configuration,%qbittorrent-accounts,qbittorrent-activation) (qbittorrent-shepherd-service,qbittorrent-service-type): New variables. --- rosenthal/services/bittorrent.scm | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 rosenthal/services/bittorrent.scm diff --git a/rosenthal/services/bittorrent.scm b/rosenthal/services/bittorrent.scm new file mode 100644 index 0000000..1e8f9b7 --- /dev/null +++ b/rosenthal/services/bittorrent.scm @@ -0,0 +1,89 @@ +;; SPDX-FileCopyrightText: 2022 Hilton Chain +;; +;; SPDX-License-Identifier: GPL-3.0-or-later + +(define-module (rosenthal services bittorrent) + #:use-module (ice-9 match) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (gnu packages admin) + #:use-module (gnu services) + #:use-module (gnu services configuration) + #:use-module (gnu services shepherd) + #:use-module (gnu system shadow) + #:use-module (rosenthal packages bittorrent) + #:export (qbittorrent-configuration + qbittorrent-service-type)) + +;; +;; qBittorrent +;; + + +(define-configuration/no-serialization qbittorrent-configuration + (qbittorrent + (package qbittorrent-enhanced-edition-nox) + "The qBittorrent package to use, we need @command{qbittorrent-nox}.") + (log-file + (string "/var/log/qbittorrent.log") + "Where the logs go.") + (webui-port + (integer 8080) + "Change the Web UI port.") + (profile-directory + (string "/var/lib/qbittorrent") + "Directory to store configuration files in.") + (extra-options + (list-of-strings '()) + "List of extra options.")) + +(define %qbittorrent-accounts + (list (user-group (name "qbittorrent") (system? #t)) + (user-account + (name "qbittorrent") + (group "qbittorrent") + (system? #t) + (comment "qBittorrent user") + (home-directory "/var/empty") + (shell (file-append shadow "/sbin/nologin"))))) + +(define (qbittorrent-activation config) + #~(begin + (use-modules (guix build utils)) + (let ((profile-directory #$(qbittorrent-configuration-profile-directory config)) + (user (getpwnam "qbittorrent"))) + (mkdir-p profile-directory) + (chown profile-directory (passwd:uid user) (passwd:gid user))))) + +(define qbittorrent-shepherd-service + (match-lambda + (($ qbittorrent + log-file webui-port profile-directory + extra-options) + (list (shepherd-service + (documentation "Run qbittorrent.") + (provision '(qbittorrent)) + (requirement '(loopback)) + (start #~(make-forkexec-constructor + (list #$(file-append qbittorrent "/bin/qbittorrent-nox") + #$(string-append "--webui-port=" (number->string webui-port)) + #$(string-append "--profile=" profile-directory) + #$@extra-options) + #:user "qbittorrent" + #:group "qbittorrent" + #:log-file #$log-file + #:environment-variables '("QBT_ACCEPTED=true"))) + (stop #~(make-kill-destructor))))))) + +(define qbittorrent-service-type + (service-type + (name 'qbittorrent) + (extensions + (list (service-extension shepherd-root-service-type + qbittorrent-shepherd-service) + (service-extension activation-service-type + qbittorrent-activation) + (service-extension account-service-type + (const %qbittorrent-accounts)))) + (default-value (qbittorrent-configuration)) + (description "Run qBittorrent daemon.")))