add the patches from exported patch attic
[oweals/gnunet.git] / contrib / services / shepherd / ng0_wip / 00001-gnu-services-Add-gnunet-service.patch
1 From 60a4c0f7c60ef705db17561fd3e930bbe11730c9 Mon Sep 17 00:00:00 2001
2 From: ng0 <ng0@we.make.ritual.n0.is>
3 Date: Mon, 12 Sep 2016 12:26:52 +0000
4 Subject: [PATCH] gnu: services: Add gnunet-service.
5
6 * gnu/services/networking.scm (gnunet): New service.
7
8 Signed-off-by: Nils Gillmann <ng0@n0.is>
9 ---
10  doc/guix.texi               | 36 ++++++++++++++
11  gnu/services/networking.scm | 93 ++++++++++++++++++++++++++++++++++++-
12  2 files changed, 128 insertions(+), 1 deletion(-)
13
14 diff --git a/doc/guix.texi b/doc/guix.texi
15 index d925b4eda..eb7b409d7 100644
16 --- a/doc/guix.texi
17 +++ b/doc/guix.texi
18 @@ -11016,6 +11016,42 @@ Package object of the Open vSwitch.
19  @end table
20  @end deftp
21  
22 +@cindex GNUnet
23 +@cindex gnunet
24 +@subsubheading GNUnet Service
25 +
26 +@deffn {Scheme Variable} gnunet-service-type
27 +This is the type of the @uref{https://gnunet.org, GNUnet}
28 +service, whose value should be an @code{gnunet-configuration} object
29 +as in this example:
30 +
31 +@example
32 +(service gnunet-service-type
33 +           (gnunet-configuration
34 +             (config-file (local-file "./gnunet.conf"))))
35 +@end example
36 +@end deffn
37 +
38 +@deftp {Data Type} gnunet-configuration
39 +Data type representing the configuration of GNUnet.
40 +
41 +@table @asis
42 +@item @code{package} (default: @var{gnunet})
43 +Package object of the GNUnet service.
44 +
45 +@item @code{config-file} (default: @var{%default-gnunet-file})
46 +File-like object of the GNUnet configuration file to use.  For NAT is
47 +assumes by default that you are behind a NAT (@var{BEHIND_NAT = YES})
48 +and enables UPNP (@var{ENABLE_UPNP = YES}).
49 +The hostlist is configured with the options @var{-b} (bootstrap using
50 +configured hostlist servers) and @var{-e} (enable learning advertised hostlists).
51 +Read the configuration files in @var{"~/.guix-profile/share/gnunet/config.d/"}
52 +for more information.  These files also set the defaults when you don't set
53 +any explicit values to override them.
54 +
55 +@end table
56 +@end deftp
57 +
58  @node X Window
59  @subsubsection X Window
60  
61 diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
62 index b0c23aafc..0ff20e707 100644
63 --- a/gnu/services/networking.scm
64 +++ b/gnu/services/networking.scm
65 @@ -5,6 +5,7 @@
66  ;;; Copyright © 2016 John Darrington <jmd@gnu.org>
67  ;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org>
68  ;;; Copyright © 2017 Thomas Danckaert <post@thomasdanckaert.be>
69 +;;; Copyright © 2017 ng0 <contact.ng0@cryptolab.net>
70  ;;;
71  ;;; This file is part of GNU Guix.
72  ;;;
73 @@ -29,6 +30,7 @@
74    #:use-module (gnu system pam)
75    #:use-module (gnu packages admin)
76    #:use-module (gnu packages connman)
77 +  #:use-module (gnu packages gnunet)
78    #:use-module (gnu packages linux)
79    #:use-module (gnu packages tor)
80    #:use-module (gnu packages messaging)
81 @@ -92,7 +94,12 @@
82              wpa-supplicant-service-type
83  
84              openvswitch-service-type
85 -            openvswitch-configuration))
86 +            openvswitch-configuration
87 +
88 +            gnunet-configuration
89 +            gnunet-configuration?
90 +            gnunet-service
91 +            gnunet-service-type))
92  
93  ;;; Commentary:
94  ;;;
95 @@ -1125,4 +1132,88 @@ a network connection manager."))))
96  switch designed to enable massive network automation through programmatic
97  extension.")))
98  
99 +;;;
100 +;;; GNUnet
101 +;;;
102 +
103 +(define-record-type* <gnunet-configuration>
104 +  gnunet-configuration make-gnunet-configuration
105 +  gnunet-configuration?
106 +  (package           gnunet-configuration-package
107 +                     (default gnunet))
108 +  (config-file       gnunet-configuration-config-file
109 +                     (default %default-gnunet-config-file)))
110 +
111 +(define %default-gnunet-config-file
112 +  (plain-file "gnunet.conf" "
113 +[PATHS]
114 +SERVICEHOME = /var/lib/gnunet
115 +GNUNET_CONFIG_HOME = /var/lib/gnunet
116 +
117 +[arm]
118 +SYSTEM_ONLY = YES
119 +USER_ONLY = NO
120 +
121 +[nat]
122 +BEHIND_NAT = YES
123 +ENABLE_UPNP = YES
124 +
125 +[hostlist]
126 +OPTIONS = -b -e
127 +"))
128 +
129 +(define gnunet-shepherd-service
130 +  (match-lambda
131 +    (($ <gnunet-configuration> package config-file)
132 +     (list (shepherd-service
133 +            (provision '(gnunet))
134 +            (requirement '(loopback))
135 +            (documentation "Run the GNUnet service.")
136 +            (start
137 +             (let ((gnunet
138 +                    (file-append package "/lib/gnunet/libexec/gnunet-service-arm")))
139 +               #~(make-forkexec-constructor
140 +                  (list #$gnunet "-c" #$config-file)
141 +                  #:log-file "/var/log/gnunet.log"
142 +                  #:pid-file "/var/run/gnunet.pid")))
143 +            (stop
144 +             #~(make-kill-destructor)))))))
145 +
146 +(define %gnunet-accounts
147 +  (list (user-group
148 +         (name "gnunetdns")
149 +         (system? #t))
150 +        (user-group
151 +         (name "gnunet")
152 +         (system? #t))
153 +        (user-account
154 +         (name "gnunet")
155 +         (group "gnunet")
156 +         (system? #t)
157 +         (comment "GNUnet system user")
158 +         (home-directory "/var/lib/gnunet")
159 +         (shell #~(string-append #$shadow "/sbin/nologin")))))
160 +
161 +(define gnunet-activation
162 +  (match-lambda
163 +    (($ <gnunet-configuration> package config-file)
164 +     (let ((gnunet
165 +            (file-append package "/lib/gnunet/libexec/gnunet-service-arm")))
166 +       #~(begin
167 +           ;; Create the .config + .cache for gnunet user
168 +           (mkdir-p "/var/lib/gnunet/.config/gnunet")
169 +           (mkdir-p "/var/lib/gnunet/.cache/gnunet"))))))
170 +
171 +(define gnunet-service-type
172 +  (service-type
173 +   (name 'gnunet)
174 +   (extensions (list (service-extension account-service-type
175 +                                        (const %gnunet-accounts))
176 +                     (service-extension activation-service-type
177 +                                        gnunet-activation)
178 +                     (service-extension profile-service-type
179 +                                        (compose list gnunet-configuration-package))
180 +                     (service-extension shepherd-root-service-type
181 +                                        gnunet-shepherd-service)))))
182 +
183  ;;; networking.scm ends here
184 -- 
185 2.17.0
186