aboutsummaryrefslogtreecommitdiff
path: root/contrib/services/shepherd/ng0_wip/0001-gnu-services-Add-gnunet-service.patch
blob: a494434e032bd08367a38071679680ceea84c3f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
From 434b05bc1a11b4865c0bd634281acd91dfce972c Mon Sep 17 00:00:00 2001
From: ng0 <ng0@we.make.ritual.n0.is>
Date: Mon, 12 Sep 2016 12:26:52 +0000
Subject: [PATCH] gnu: services: Add gnunet-service.

Signed-off-by: Nils Gillmann <ng0@n0.is>
---
 doc/guix.texi               |  36 ++++++++++
 gnu/services/networking.scm | 134 +++++++++++++++++++++++++++++++++++-
 2 files changed, 169 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 00bf24d3f..73589c88b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -10138,6 +10138,42 @@ Package object of the Open vSwitch.
 @end table
 @end deftp
 
+@cindex GNUnet
+@cindex gnunet
+@subsubheading GNUnet Service
+
+@deffn {Scheme Variable} gnunet-service-type
+This is the type of the @uref{https://gnunet.org, GNUnet}
+service, whose value should be an @code{gnunet-configuration} object
+as in this example:
+
+@example
+(service gnunet-service-type
+           (gnunet-configuration
+             (config-file (local-file "./gnunet.conf"))))
+@end example
+@end deffn
+
+@deftp {Data Type} gnunet-configuration
+Data type representing the configuration of GNUnet.
+
+@table @asis
+@item @code{package} (default: @var{gnunet})
+Package object of the GNUnet service.
+
+@item @code{config-file} (default: @var{%default-gnunet-file})
+File-like object of the GNUnet configuration file to use.  For NAT is
+assumes by default that you are behind a NAT (@var{BEHIND_NAT = YES})
+and enables UPNP (@var{ENABLE_UPNP = YES}).
+The hostlist is configured with the options @var{-b} (bootstrap using
+configured hostlist servers) and @var{-e} (enable learning advertised hostlists).
+Read the configuration files in @var{"~/.guix-profile/share/gnunet/config.d/"}
+for more information.  These files also set the defaults when you don't set
+any explicit values to override them.
+
+@end table
+@end deftp
+
 @node X Window
 @subsubsection X Window
 
diff --git a/gnu/services/networking.scm b/gnu/services/networking.scm
index 99a3d493c..fe682b267 100644
--- a/gnu/services/networking.scm
+++ b/gnu/services/networking.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2016 John Darrington <jmd@gnu.org>
 ;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org>
 ;;; Copyright © 2017 Thomas Danckaert <post@thomasdanckaert.be>
+;;; Copyright © 2017 ng0 <ng0@no-reply.pragmatique.xyt>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -29,6 +30,7 @@
   #:use-module (gnu system pam)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages connman)
+  #:use-module (gnu packages gnunet)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages tor)
   #:use-module (gnu packages messaging)
@@ -92,7 +94,12 @@
             wpa-supplicant-service-type
 
             openvswitch-service-type
-            openvswitch-configuration))
+            openvswitch-configuration
+
+            gnunet-configuration
+            gnunet-configuration?
+            gnunet-service-type
+            %default-gnunet-config-file))
 
 ;;; Commentary:
 ;;;
@@ -1069,4 +1076,129 @@ dns=" dns "
           (service-extension shepherd-root-service-type
                              openvswitch-shepherd-service)))))
 
+;;;
+;;; GNUnet
+;;;
+
+;; steps:
+;; 0. The service works!!!
+;; 1. We want a completely adjustable config.
+;; 2. We want to extend this service with functions like
+;;    vpn, comparable to tor-service
+;; Because of (1) we can't have a default. We can have
+;; default values which can be adjusted. A config is
+;; generated from these.
+
+(define-record-type* <gnunet-configuration>
+  gnunet-configuration make-gnunet-configuration
+  gnunet-configuration?
+  (gnunet            gnunet-configuration-package
+                     (default gnunet))
+  (config-file       gnunet-configuration-config-file
+                     (default (plain-file "empty" ""))))
+
+(define %default-gnunet-config-file
+  (plain-file "gnunet.conf" "
+[PATHS]
+SERVICEHOME = /var/lib/gnunet
+GNUNET_CONFIG_HOME = /var/lib/gnunet
+
+[arm]
+SYSTEM_ONLY = NO
+USER_ONLY = NO
+
+[nat]
+BEHIND_NAT = YES
+ENABLE_UPNP = YES
+
+[hostlist]
+OPTIONS = -b -e
+"))
+
+(define gnunet-shepherd-service
+  (match-lambda
+    (($ <gnunet-configuration> package config-file)
+     (list (shepherd-service
+            (provision '(gnunet))
+            (requirement '(user-processes loopback networking))
+            (documentation "Run the GNUnet service.")
+            (start
+             (let ((gnunet
+                    (file-append package "/lib/gnunet/libexec/gnunet-service-arm")))
+               #~(make-forkexec-constructor
+                  (list #$gnunet "-c" #$config-file "-d")
+                  #:pid-file "/var/run/gnunet/arm-service.pid"
+                  #:user "gnunet"
+                  #:group "gnunet"
+                  ;;#:log-file "/var/lib/gnunet/gnunet.log")))
+                  #:log-file "/var/log/gnunet.log")))
+            (stop #~(make-kill-destructor)))))))
+
+(define %gnunet-accounts
+  (list (user-group (name "gnunetdns") (system? #t))
+        (user-group (name "gnunet") (system? #t))
+        (user-account
+         (name "gnunet")
+         (group "gnunet")
+         (system? #t)
+         (comment "GNUnet system user")
+         (home-directory "/var/empty")
+         (shell (file-append shadow "/sbin/nologin")))))
+
+;; ${GNUNET_HOME}/.local/share/gnunet/gnunet.conf  -> chmod 600
+;; mkdir -p ${GNUNET_HOME}/.cache/gnunet
+
+(define gnunet-activation
+  (match-lambda
+    (($ <gnunet-configuration> package config-file)
+     (let ((gnunet
+            (file-append package "/lib/gnunet/libexec/gnunet-service-arm")))
+       #~(begin
+           (use-modules (guix build utils))
+           (define %user (getpw "gnunet"))
+           (mkdir-p "/var/lib/gnunet/")
+           (chown "/var/lib/gnunet" (passwd:uid %user) (passwd:gid %user))
+           ;;(chmod "/var/lib/gnunet/" #o755)
+           (mkdir-p "/var/lib/gnunet/.local/share/gnunet")
+           (mkdir-p "/var/lib/gnunet/.cache/gnunet")
+           (mkdir-p "/var/lib/gnunet/hostlist")
+           (mkdir-p "/var/lib/gnunet/.config/gnunet")
+           (chown "/var/lib/gnunet/.local/share/gnunet" (passwd:uid %user) (passwd:gid %user))
+           (chown "/var/lib/gnunet/.cache/gnunet" (passwd:uid %user) (passwd:gid %user))
+           (chown "/var/lib/gnunet/hostlist" (passwd:uid %user) (passwd:gid %user))
+           ;;(chown "/var/lib/gnunet/gnunet.conf" (passwd:uid %user) (passwd:gid %user))
+           (chown "/var/lib/gnunet/.config/gnunet" (passwd:uid %user) (passwd:gid %user)))))))
+           ;;(chmod "/var/lib/gnunet/.config/gnunet" #o755)
+           ;;(chmod "/var/lib/gnunet/.cache/gnunet" #o755)
+           ;;(chmod "/var/lib/gnunet/.local/share/gnunet" #o755))))))
+
+;; SUID_ROOT_HELPERS="exit nat-server nat-client transport-bluetooth transport-wlan vpn"
+;; set chmod u+s for those above.
+;; chmodown_execbin ${libexec}/gnunet-helper-dns 4750 root:gnunetdns
+;; chmodown_execbin ${libexec}/gnunet-service-dns 2750 gnunet:gnunetdns
+(define gnunet-setuid-programs
+  (match-lambda
+    (($ <gnunet-configuration> package)
+     (list (file-append package "/lib/gnunet/libexec/gnunet-helper-exit")
+           (file-append package "/lib/gnunet/libexec/gnunet-helper-nat-server")
+           (file-append package "/lib/gnunet/libexec/gnunet-helper-nat-client")
+           (file-append package "/lib/gnunet/libexec/gnunet-helper-transport-bluetooth")
+           (file-append package "/lib/gnunet/libexec/gnunet-helper-transport-wlan")
+           (file-append package "/lib/gnunet/libexec/gnunet-helper-vpn")))))
+
+(define gnunet-service-type
+  (service-type
+   (name 'gnunet)
+   (extensions (list (service-extension account-service-type
+                                        (const %gnunet-accounts))
+                     (service-extension activation-service-type
+                                        gnunet-activation)
+                     (service-extension profile-service-type
+                                        (compose list gnunet-configuration-package))
+                     (service-extension setuid-program-service-type
+                                        gnunet-setuid-programs)
+                     (service-extension shepherd-root-service-type
+                                        gnunet-shepherd-service)))))
+;;; --- here starts the rewrite.
+
 ;;; networking.scm ends here
-- 
2.17.0