unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] services: Add transmission-service.
@ 2015-11-28  1:46 David Thompson
  2015-11-28 14:07 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: David Thompson @ 2015-11-28  1:46 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 68 bytes --]

My first service since the big service API rewrite.  How did I do?


[-- Attachment #2: 0001-services-Add-transmission-service.patch --]
[-- Type: text/x-patch, Size: 7814 bytes --]

From 6f483d37bf157ee0d253d2aaa919d6900d23453c Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
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
 
@@ -7013,6 +7014,24 @@ directories are created when the service is activated.
 
 @end deffn
 
+@node BitTorrent Services
+@subsubsection BitTorrent Services
+
+The @code{(gnu services bittorrent)} module provides the following service:
+
+@deffn {Scheme Procedure} transmission-service [#:transmission transmission] @
+       [#: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
 
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 =				\
   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 © 2015 David Thompson <davet@gnu.org>
+;;;
+;;; 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 <http://www.gnu.org/licenses/>.
+
+(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>
+  transmission-configuration make-transmission-configuration
+  transmission-configuration?
+  (transmission       transmission-configuration-transmission) ; <package>
+  (port               transmission-configuration-port) ; integer
+  (peer-port          transmission-configuration-peer-port) ; integer
+  (download-directory transmission-configuration-download-directory)) ; string
+
+(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 config)))
+    #~(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-configuration> transmission port peer-port download-dir)
+     (let* ((daemon #~(string-append #$transmission "/bin/transmission-daemon"))
+            (start-action
+             #~(make-forkexec-constructor
+                (list #$daemon "--foreground"
+                      (string-append "--port=" (number->string #$port))
+                      (string-append "--peerport="
+                                     (number->string #$peer-port))
+                      (string-append "--download-dir=" #$download-dir)
+                      (string-append "--config-dir="
+                                     #$%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-directory
+                                               "/downloads")))
+  "Return a service that runs TRANSMISSION, a daemon that downloads and shares
+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))))
-- 
2.5.0


[-- Attachment #3: Type: text/plain, Size: 38 bytes --]


-- 
David Thompson
GPG Key: 0FF1D807

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] services: Add transmission-service.
  2015-11-28  1:46 [PATCH] services: Add transmission-service David Thompson
@ 2015-11-28 14:07 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2015-11-28 14:07 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> My first service since the big service API rewrite.  How did I do?

I’d give you an A.  ;-)

> From 6f483d37bf157ee0d253d2aaa919d6900d23453c Mon Sep 17 00:00:00 2001
> From: David Thompson <dthompson2@worcester.edu>
> 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.

[...]

> +@deffn {Scheme Procedure} transmission-service [#:transmission transmission] @
                                                                  ^^^
@var{transmission}

> +       [#:download-directory ``/var/lib/transmission/downloads'']

Use straight quotes here because this is code.

> +(define (transmission-activation config)
> +  (let ((download-dir (transmission-configuration-download-directory config)))
> +    #~(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))))

Should it be chown’d to “transmission”?  Maybe the daemon takes care of this?

> +(define* (transmission-service #:key (transmission transmission)
> +                               (port 9091) (peer-port 51413)
> +                               (download-directory
> +                                (string-append %transmission-state-directory
> +                                               "/downloads")))
> +  "Return a service that runs TRANSMISSION, a daemon that downloads and shares
> +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."

You can use the same Texi string as in the manual here.

Otherwise LGTM!

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-28 14:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-28  1:46 [PATCH] services: Add transmission-service David Thompson
2015-11-28 14:07 ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).