From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Thompson Subject: [PATCH] services: Add transmission-service. Date: Fri, 27 Nov 2015 20:46:25 -0500 Message-ID: <87vb8mj3pq.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35585) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2Uas-0008Tf-AK for guix-devel@gnu.org; Fri, 27 Nov 2015 20:46:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2Uap-00065r-2i for guix-devel@gnu.org; Fri, 27 Nov 2015 20:46:30 -0500 Received: from mail-qk0-x236.google.com ([2607:f8b0:400d:c09::236]:35115) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2Uao-00065i-OL for guix-devel@gnu.org; Fri, 27 Nov 2015 20:46:27 -0500 Received: by qkao63 with SMTP id o63so41278186qka.2 for ; Fri, 27 Nov 2015 17:46:26 -0800 (PST) Received: from izanagi (209-6-40-86.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com. [209.6.40.86]) by smtp.gmail.com with ESMTPSA id 81sm10458485qhx.15.2015.11.27.17.46.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Nov 2015 17:46:25 -0800 (PST) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain My first service since the big service API rewrite. How did I do? --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-services-Add-transmission-service.patch Content-Transfer-Encoding: quoted-printable >From 6f483d37bf157ee0d253d2aaa919d6900d23453c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 27 Nov 2015 20:40:59 -0500 Subject: [PATCH] services: Add transmission-service. * gnu/services/bittorrent.scm: New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add it. * doc/guix.texi ("BitTorrent Services"): Document it. --- doc/guix.texi | 19 +++++++ gnu-system.am | 1 + gnu/services/bittorrent.scm | 122 ++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 142 insertions(+) create mode 100644 gnu/services/bittorrent.scm diff --git a/doc/guix.texi b/doc/guix.texi index b404453..847d196 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -6292,6 +6292,7 @@ declaration. * Desktop Services:: D-Bus and desktop services. * Database Services:: SQL databases. * Web Services:: Web servers. +* BitTorrent Services:: BitTorrent services. * Various Services:: Other services. @end menu =20 @@ -7013,6 +7014,24 @@ directories are created when the service is activate= d. =20 @end deffn =20 +@node BitTorrent Services +@subsubsection BitTorrent Services + +The @code{(gnu services bittorrent)} module provides the following service: + +@deffn {Scheme Procedure} transmission-service [#:transmission transmissio= n] @ + [#:port 9091] [#:peer-port 51413]@ + [#:download-directory ``/var/lib/transmission/downloads''] + +Return a service that runs @var{transmission}, a daemon that downloads +and shares files via the BitTorrent protocol. + +The daemon will serve the web user interface over @var{port}, handle +BitTorrent tasks over @var{peer-port}, and save downloaded files to +@var{download-directory}. + +@end deffn + @node Various Services @subsubsection Various Services =20 diff --git a/gnu-system.am b/gnu-system.am index f69645b..da1b359 100644 --- a/gnu-system.am +++ b/gnu-system.am @@ -354,6 +354,7 @@ GNU_SYSTEM_MODULES =3D \ gnu/services.scm \ gnu/services/avahi.scm \ gnu/services/base.scm \ + gnu/services/bittorrent.scm \ gnu/services/databases.scm \ gnu/services/dbus.scm \ gnu/services/desktop.scm \ diff --git a/gnu/services/bittorrent.scm b/gnu/services/bittorrent.scm new file mode 100644 index 0000000..140df53 --- /dev/null +++ b/gnu/services/bittorrent.scm @@ -0,0 +1,122 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2015 David Thompson +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu services bittorrent) + #:use-module (gnu services) + #:use-module (gnu services dmd) + #:use-module (gnu system shadow) + #:use-module (gnu packages admin) + #:use-module (gnu packages bittorrent) + #:use-module (guix records) + #:use-module (guix gexp) + #:use-module (ice-9 match) + #:export (%transmission-state-directory + + transmission-configuration + transmission-configuration? + transmission-configuration-transmission + transmission-configuration-port + transmission-configuration-peer-port + transmission-configuration-download-directory + + transmission-service-type + transmission-service)) + +;;; Commentary: +;;; +;;; BitTorrent services. +;;; +;;; Code: + +(define %transmission-state-directory "/var/lib/transmission") + +(define-record-type* + transmission-configuration make-transmission-configuration + transmission-configuration? + (transmission transmission-configuration-transmission) ; + (port transmission-configuration-port) ; integer + (peer-port transmission-configuration-peer-port) ; integer + (download-directory transmission-configuration-download-directory)) ; st= ring + +(define %transmission-accounts + (list (user-group (name "transmission") (system? #t)) + (user-account + (name "transmission") + (group "transmission") + (system? #t) + (comment "transmission daemon user") + (home-directory "/var/empty") + (shell #~(string-append #$shadow "/sbin/nologin"))))) + +(define (transmission-activation config) + (let ((download-dir (transmission-configuration-download-directory confi= g))) + #~(begin + (use-modules (guix build utils)) + + (display "creating transmission state directory\n") + (mkdir-p #$%transmission-state-directory) + (format #t "creating transmission download directory '~a'~%" + #$download-dir) + (mkdir-p #$download-dir)))) + +(define transmission-dmd-service + (match-lambda + (($ transmission port peer-port download-= dir) + (let* ((daemon #~(string-append #$transmission "/bin/transmission-dae= mon")) + (start-action + #~(make-forkexec-constructor + (list #$daemon "--foreground" + (string-append "--port=3D" (number->string #$port)) + (string-append "--peerport=3D" + (number->string #$peer-port)) + (string-append "--download-dir=3D" #$download-dir) + (string-append "--config-dir=3D" + #$%transmission-state-directory))))) + (list (dmd-service + (provision '(transmission)) + (documentation "Run the transmission daemon.") + (requirement '(user-processes loopback)) + (start start-action) + (stop #~(make-kill-destructor)))))))) + +(define transmission-service-type + (service-type (name 'transmission) + (extensions + (list (service-extension dmd-root-service-type + transmission-dmd-service) + (service-extension activation-service-type + transmission-activation) + (service-extension account-service-type + (const %transmission-accounts)))= ))) + +(define* (transmission-service #:key (transmission transmission) + (port 9091) (peer-port 51413) + (download-directory + (string-append %transmission-state-directo= ry + "/downloads"))) + "Return a service that runs TRANSMISSION, a daemon that downloads and sh= ares +files via the BitTorrent protocol. + +The daemon will serve the web user interface over PORT, handle BitTorrent +tasks over PEER-PORT, and save downloaded files to DOWNLOAD-DIRECTORY." + (service transmission-service-type + (transmission-configuration + (transmission transmission) + (port port) + (peer-port peer-port) + (download-directory download-directory)))) --=20 2.5.0 --=-=-= Content-Type: text/plain -- David Thompson GPG Key: 0FF1D807 --=-=-=--