summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorJanneke Nieuwenhuizen <janneke@gnu.org>2025-03-13 19:22:02 +0100
committerJanneke Nieuwenhuizen <janneke@gnu.org>2025-03-20 09:32:05 +0100
commit2f204a73036d3f78bb3a8a99833ac69a9efaab7b (patch)
tree298cf0536dabb606e526e4534ed82b070ed48163 /gnu
parent973e59e24e45e505baeddd99a54e77c57a9454e0 (diff)
services: Add snuik-service-type.
* gnu/services/messaging.scm (snuik-configuration): New type. (snuik-services): New procedure. (snuik-activation, %snuik-accounts, snuik-service-type): New variables. * doc/guix.texi (Messaging Services): Document it. Change-Id: I0c52b4804948876dc1b4d3b5ac660af848a13f25
Diffstat (limited to 'gnu')
-rw-r--r--gnu/services/messaging.scm114
1 files changed, 113 insertions, 1 deletions
diff --git a/gnu/services/messaging.scm b/gnu/services/messaging.scm
index a914d0f89ec..9bfeabacf45 100644
--- a/gnu/services/messaging.scm
+++ b/gnu/services/messaging.scm
@@ -59,7 +59,10 @@
59 bitlbee-service-type 59 bitlbee-service-type
60 60
61 quassel-configuration 61 quassel-configuration
62 quassel-service-type)) 62 quassel-service-type
63
64 snuik-configuration
65 snuik-service-type))
63 66
64;;; Commentary: 67;;; Commentary:
65;;; 68;;;
@@ -1002,3 +1005,112 @@ a gateway between IRC and chat networks.")))
1002 "Run @url{https://quassel-irc.org/,quasselcore}, the backend 1005 "Run @url{https://quassel-irc.org/,quasselcore}, the backend
1003for the distributed IRC client quassel, which allows you to connect from 1006for the distributed IRC client quassel, which allows you to connect from
1004multiple machines simultaneously."))) 1007multiple machines simultaneously.")))
1008
1009
1010;;;
1011;;; Snuik.
1012;;;
1013(define-maybe integer (no-serialization))
1014(define-configuration/no-serialization snuik-configuration
1015 (snuik (package snuik) "The snuik package to use.")
1016 (server maybe-string "The IRC server to connect to.")
1017 (port maybe-integer "The port used by the IRC server.")
1018 (nick maybe-string "The nickname for snuik to use.")
1019 (password maybe-string "The password to use when logging in.")
1020 (password-file maybe-string "The file to read the password from.")
1021 (channels (list-of-strings '()) "The channels for snuik to join.")
1022 (extra-options (list-of-strings '()) "Extra options to be passed to snuik.")
1023 (home-service? (boolean for-home?) "Running as home service?"))
1024
1025(define (snuik-services config)
1026 "Return a <shepherd-service> for snuik with CONFIG."
1027 (match-record config
1028 <snuik-configuration>
1029 (snuik server port nick password password-file channels extra-options
1030 home-service?)
1031 (let* ((password-file (snuik-configuration-password-file config))
1032 (mappings `(,@(if home-service?
1033 '()
1034 `(,(file-system-mapping
1035 (source "/var/run/snuik")
1036 (target source)
1037 (writable? #t))
1038 ,@(if password-file
1039 (list (file-system-mapping
1040 (source password-file)
1041 (target source)))
1042 '())))))
1043 (snuik (least-authority-wrapper
1044 (file-append snuik "/bin/snuik")
1045 #:name "snuik"
1046 #:mappings mappings
1047 #:namespaces (delq 'net %namespaces)))
1048 (command
1049 #~'(#$snuik
1050 #$@(if (and server (not (eq? server %unset-value)))
1051 (list (string-append "--server=" server))
1052 #~())
1053 #$@(if (and port (not (eq? port %unset-value)))
1054 (list (string-append "--port=" (number->string port)))
1055 #~())
1056 #$@(if (and nick (not (eq? nick %unset-value)))
1057 (list (string-append "--nick=" nick))
1058 #~())
1059 #$@(if (and password (not (eq? password %unset-value)))
1060 (list (string-append "--password=" password))
1061 #~())
1062 #$@(if (and password-file (not (eq? password-file %unset-value)))
1063 (list (string-append "--password-file=" password-file))
1064 #~())
1065 #$@(if (pair? channels)
1066 (list (string-append "--channels=" (string-join channels ",")))
1067 #~())
1068 #$@extra-options))
1069 (log-file #~(string-append
1070 #$(if home-service? #~%user-log-dir "/var/log")
1071 "/snuik.log")))
1072 (list (shepherd-service
1073 (documentation "Run the snuik IRC bot.")
1074 (provision '(snuik))
1075 (requirement (if home-service? '() '(user-processes networking)))
1076 (modules (if home-service?
1077 '((shepherd support)) ;for '%user-log-dir'
1078 '()))
1079 (start #~(make-forkexec-constructor
1080 #$command
1081 #:log-file #$log-file
1082 #:user #$(and (not home-service?) "snuik")
1083 #:group #$(and (not home-service?) "snuik")))
1084 (stop #~(make-kill-destructor)))))))
1085
1086(define snuik-activation
1087 (with-imported-modules '((guix build utils))
1088 #~(begin
1089 (use-modules (guix build utils))
1090 (let* ((user (getpw "snuik"))
1091 (directory "/var/run/snuik"))
1092 (mkdir-p directory)
1093 (chown directory (passwd:uid user) (passwd:gid user))))))
1094
1095(define %snuik-accounts
1096 (list (user-group (name "snuik") (system? #t))
1097 (user-account
1098 (name "snuik")
1099 (group "snuik")
1100 (system? #t)
1101 (comment "Snuik IRC bot user")
1102 (home-directory "/var/run/snuik")
1103 (shell (file-append shadow "/sbin/nologin")))))
1104
1105(define snuik-service-type
1106 (service-type
1107 (name 'home-snuik)
1108 (description "Run the Snuik IRC bot.")
1109 (default-value (snuik-configuration))
1110 (extensions
1111 (list (service-extension activation-service-type
1112 (const snuik-activation))
1113 (service-extension account-service-type
1114 (const %snuik-accounts))
1115 (service-extension shepherd-root-service-type
1116 snuik-services)))))