about summary refs log tree commit diff
path: root/whispers/services/proton.scm
diff options
context:
space:
mode:
Diffstat (limited to 'whispers/services/proton.scm')
-rw-r--r--whispers/services/proton.scm117
1 files changed, 117 insertions, 0 deletions
diff --git a/whispers/services/proton.scm b/whispers/services/proton.scm
new file mode 100644
index 0000000..41bf197
--- /dev/null
+++ b/whispers/services/proton.scm
@@ -0,0 +1,117 @@
+;;; Whispers --- Stealth VPN and ssh tunneler
+;;; Copyright © 2024 Runciter <runciter@whispers-vpn.org>
+;;;
+;;; This file is part of Whispers.
+;;;
+;;; Whispers 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.
+;;;
+;;; Whispers 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 Whispers.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (whispers services proton)
+  #:use-module (guix gexp)
+  #:use-module (guix records)
+  #:use-module (gnu services)
+  #:use-module (gnu services shepherd)
+  #:use-module (gnu services admin)
+  #:use-module (gnu packages mail)
+  #:export (hydroxide-configuration
+            hydroxide-service-type
+            hydroxide-configuration?
+            hydroxide-service-type))
+
+(define-record-type* <hydroxide-configuration>
+  hydroxide-configuration make-hydroxide-configuration
+  hydroxide-configuration?
+  this-hydroxide-configuration
+  ;; A file-like object
+  (hydroxide-package    hydroxide-configuration-hydroxide-package
+                        (default hydroxide))
+  ;; A string
+  (user                 hydroxide-configuration-user
+                        (default "johndoe"))
+  ;; A boolean value
+  (https-proxy?         hydroxide-configuration-https-proxy?
+                        (default #f))
+  ;; A string
+  (https-proxy          hydroxide-configuration-https-proxy
+                        (default "socks5://localhost:8971"))
+  ;; A boolean value
+  (imap?                hydroxide-configuration-imap?
+                        (default #t))
+  ;; A boolean value
+  (smtp?                hydroxide-configuration-smtp?
+                        (default #t))
+  ;; A boolean value
+  (carddav?             hydroxide-configuration-carddav?
+                        (default #t))
+  ;; A boolean value
+  (%auto-start?         hydroxide-configuration-auto-start?
+                        (default #t)))
+
+(define (hydroxide-constructor-gexp config)
+  "Returns a G-exp to a procedure starting an hydroxide server
+configurable by CONFIG, a record of the <hydroxide-configuration> type."
+  (let ((hydroxide-package (hydroxide-configuration-hydroxide-package
+                            config))
+        (user (hydroxide-configuration-user config))
+        (https-proxy? (hydroxide-configuration-https-proxy? config))
+        (https-proxy (hydroxide-configuration-https-proxy config))
+        (imap? (hydroxide-configuration-imap? config))
+        (carddav? (hydroxide-configuration-carddav? config))
+        (smtp? (hydroxide-configuration-smtp? config)))
+    #~(make-forkexec-constructor
+       (append (list #$(file-append hydroxide-package
+                                    "/bin/hydroxide"))
+               (if #$imap?
+                   (list)
+                   (list "--disable-imap"))
+               (if #$carddav?
+                   (list)
+                   (list "--disable-carddav"))
+               (if #$smtp?
+                   (list)
+                   (list "--disable-smtp"))
+                (list "serve"))
+       #:environment-variables
+       (append (list (string-append "XDG_CONFIG_HOME="
+                                    (passwd:dir (getpwnam #$user))
+                                    "/.config"))
+               #$(if https-proxy?
+                     #~(list (string-append "https_proxy="
+                                            #$https-proxy))
+                     #~(list))))))
+
+(define (hydroxide-shepherd-services config)
+  "Returns a list of shepherd services handling an hydroxide server
+configured by CONFIG, a record of the <hydroxide-configuration> type."
+  (let ((auto-start? (hydroxide-configuration-auto-start? config)))
+    (list
+     (shepherd-service
+      (documentation "Hydroxide service")
+      (provision '(hydroxide))
+      (requirement '())
+      (start (hydroxide-constructor-gexp config))
+      (stop #~(make-kill-destructor))
+      (auto-start? auto-start?)))))
+
+(define hydroxide-service-type
+  (service-type
+   (name 'hydroxide)
+   (description "Hydroxide node service")
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             hydroxide-shepherd-services)
+          (service-extension
+           profile-service-type
+           (lambda (config)
+             (list (hydroxide-configuration-hydroxide-package config))))))
+   (default-value (hydroxide-configuration))))