diff options
| author | Janneke Nieuwenhuizen <janneke@gnu.org> | 2025-03-13 19:22:02 +0100 |
|---|---|---|
| committer | Janneke Nieuwenhuizen <janneke@gnu.org> | 2025-03-20 09:32:05 +0100 |
| commit | 2f204a73036d3f78bb3a8a99833ac69a9efaab7b (patch) | |
| tree | 298cf0536dabb606e526e4534ed82b070ed48163 | |
| parent | 973e59e24e45e505baeddd99a54e77c57a9454e0 (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
| -rw-r--r-- | doc/guix.texi | 59 | ||||
| -rw-r--r-- | gnu/services/messaging.scm | 114 |
2 files changed, 171 insertions, 2 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index fe43ed2504a..41211d461d0 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -36,7 +36,7 @@ Copyright @copyright{} 2016, 2017, 2018, 2021 Chris Marusich@* | |||
| 36 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Efraim Flashner@* | 36 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Efraim Flashner@* |
| 37 | Copyright @copyright{} 2016 John Darrington@* | 37 | Copyright @copyright{} 2016 John Darrington@* |
| 38 | Copyright @copyright{} 2016, 2017 Nikita Gillmann@* | 38 | Copyright @copyright{} 2016, 2017 Nikita Gillmann@* |
| 39 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Janneke Nieuwenhuizen@* | 39 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025 Janneke Nieuwenhuizen@* |
| 40 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021 Julien Lepiller@* | 40 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021 Julien Lepiller@* |
| 41 | Copyright @copyright{} 2016 Alex ter Weele@* | 41 | Copyright @copyright{} 2016 Alex ter Weele@* |
| 42 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021 Christopher Baines@* | 42 | Copyright @copyright{} 2016, 2017, 2018, 2019, 2020, 2021 Christopher Baines@* |
| @@ -30218,6 +30218,63 @@ and Error. | |||
| 30218 | @end table | 30218 | @end table |
| 30219 | @end deftp | 30219 | @end deftp |
| 30220 | 30220 | ||
| 30221 | @cindex irc-bot | ||
| 30222 | @cindex snuik | ||
| 30223 | The @uref{https://gitlab.com/janneke/snuik, Snuik IRC bot} can be run as | ||
| 30224 | a daemon to aid talking to users that are currently offline. With the | ||
| 30225 | @code{(gnu services messaging)} service, you can configure it by adding | ||
| 30226 | a @code{snuik-service-type} service to the @code{services} field of your | ||
| 30227 | operating system declaration. | ||
| 30228 | |||
| 30229 | @defvar snuik-service-type | ||
| 30230 | This is the type of the Snuik service, whose value is a | ||
| 30231 | @code{snuik-configuration} object. | ||
| 30232 | @end defvar | ||
| 30233 | |||
| 30234 | Here is an example of a service and its configuration: | ||
| 30235 | |||
| 30236 | @lisp | ||
| 30237 | (service snuik-service-type | ||
| 30238 | (snuik-configuration | ||
| 30239 | (password-file "/var/run/snuik/.password.snuik") | ||
| 30240 | (channels '("#bootstrappable" | ||
| 30241 | "#dezyne" | ||
| 30242 | "#guix-risc-v" | ||
| 30243 | "#lilypond")))) | ||
| 30244 | @end lisp | ||
| 30245 | |||
| 30246 | @deftp {Data Type} snuik-configuration | ||
| 30247 | Available @code{snuik-configuration} fields are: | ||
| 30248 | |||
| 30249 | @table @asis | ||
| 30250 | @item @code{snuik} (default: @code{snuik}) (type: package) | ||
| 30251 | The Snuik package to use. | ||
| 30252 | |||
| 30253 | @item @code{server} (default: @code{"irc.libera.chat"}) | ||
| 30254 | The IRC server to connect to. | ||
| 30255 | |||
| 30256 | @item @code{port} (default: @code{6665}) (type: integer) | ||
| 30257 | Port number used by the IRC server. | ||
| 30258 | |||
| 30259 | @item @code{nick} (default: @code{"snuik"}) (type: string) | ||
| 30260 | The nickname for snuik to use. | ||
| 30261 | |||
| 30262 | @item @code{password} (default: @code{#f}) (type: string) | ||
| 30263 | The password to use when logging in. | ||
| 30264 | |||
| 30265 | @item @code{password-file} (default: @code{".password.<nick>}) | ||
| 30266 | The file to read the password from to use when logging in. | ||
| 30267 | |||
| 30268 | @item @code{channels} (default: @code{'("##botchat")}) | ||
| 30269 | The channels for snuik to join, a list of strings. | ||
| 30270 | |||
| 30271 | @item @code{extra-options} (default: @code{'()}) | ||
| 30272 | Extra options will be passed to @command{snuik}, please run | ||
| 30273 | @command{snuik --help } for more information. | ||
| 30274 | |||
| 30275 | @end table | ||
| 30276 | @end deftp | ||
| 30277 | |||
| 30221 | @node Telephony Services | 30278 | @node Telephony Services |
| 30222 | @subsection Telephony Services | 30279 | @subsection Telephony Services |
| 30223 | 30280 | ||
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 |
| 1003 | for the distributed IRC client quassel, which allows you to connect from | 1006 | for the distributed IRC client quassel, which allows you to connect from |
| 1004 | multiple machines simultaneously."))) | 1007 | multiple 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))))) | ||
