summaryrefslogtreecommitdiff
path: root/gnu/services/base.scm
diff options
context:
space:
mode:
authorSughosha <sughosha@disroot.org>2026-04-14 23:50:30 +0530
committerSharlatan Hellseher <sharlatanus@gmail.com>2026-06-24 21:30:45 +0100
commitc64bf4fe738b5e0232cc942c70e27002fb61a480 (patch)
tree930e201c0dc892820b584b71ca08576ac9a36e95 /gnu/services/base.scm
parent552ab52b17ec3deda49c9795f6b4743dad3e3864 (diff)
services: Add nwg-hello greeter for greetd.
* gnu/services/base.scm (nwg-hello-configuration): New configuration. (nwg-hello-configuration-file): New variable. (nwg-hello-style): New configuration. (nwg-hello-stylesheet): New variable. (greetd-nwg-hello-sway-session): New configuration. (make-greetd-nwg-hello-sway-session-sway-config): New variable. (greetd-nwg-hello-sway-session-compiler): New gexp compiler. * doc/guix.texi (Base Services): Document the new greeter. Merges: guix/guix!7644 Reviewed-by: Maxim Cournoyer <maxim@guixotic.coop> Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
Diffstat (limited to 'gnu/services/base.scm')
-rw-r--r--gnu/services/base.scm246
1 files changed, 246 insertions, 0 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 6d514237314..af9dcc1bf60 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -23,6 +23,7 @@
23;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu> 23;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
24;;; Copyright © 2024 Zheng Junjie <873216071@qq.com> 24;;; Copyright © 2024 Zheng Junjie <873216071@qq.com>
25;;; Copyright © 2024 Andreas Enge <andreas@enge.fr> 25;;; Copyright © 2024 Andreas Enge <andreas@enge.fr>
26;;; Copyright © 2026 Sughosha <sughosha@disroot.org>
26;;; 27;;;
27;;; This file is part of GNU Guix. 28;;; This file is part of GNU Guix.
28;;; 29;;;
@@ -45,9 +46,11 @@
45 #:autoload (guix diagnostics) (warning formatted-message &fix-hint) 46 #:autoload (guix diagnostics) (warning formatted-message &fix-hint)
46 #:autoload (guix i18n) (G_) 47 #:autoload (guix i18n) (G_)
47 #:use-module (guix combinators) 48 #:use-module (guix combinators)
49 #:use-module (guix packages)
48 #:use-module (guix utils) 50 #:use-module (guix utils)
49 #:use-module (gnu services) 51 #:use-module (gnu services)
50 #:use-module (gnu services admin) 52 #:use-module (gnu services admin)
53 #:use-module (gnu services configuration)
51 #:use-module (gnu services shepherd) 54 #:use-module (gnu services shepherd)
52 #:use-module (gnu services sysctl) 55 #:use-module (gnu services sysctl)
53 #:use-module (gnu system pam) 56 #:use-module (gnu system pam)
@@ -83,6 +86,7 @@
83 #:use-module ((gnu packages file-systems) 86 #:use-module ((gnu packages file-systems)
84 #:select (bcachefs-tools exfat-utils jfsutils zfs)) 87 #:select (bcachefs-tools exfat-utils jfsutils zfs))
85 #:use-module (gnu packages fonts) 88 #:use-module (gnu packages fonts)
89 #:use-module ((gnu packages nwg-shell) #:select (nwg-hello))
86 #:use-module (gnu packages terminals) 90 #:use-module (gnu packages terminals)
87 #:use-module ((gnu packages wm) #:select (sway)) 91 #:use-module ((gnu packages wm) #:select (sway))
88 #:use-module ((gnu build file-systems) 92 #:use-module ((gnu build file-systems)
@@ -289,6 +293,31 @@
289 greetd-wlgreet-configuration 293 greetd-wlgreet-configuration
290 greetd-wlgreet-sway-session 294 greetd-wlgreet-sway-session
291 greetd-gtkgreet-sway-session 295 greetd-gtkgreet-sway-session
296 nwg-hello-configuration
297 nwg-hello-configuration?
298 nwg-hello-configuration-session-dirs
299 nwg-hello-configuration-custom-sessions
300 nwg-hello-configuration-environment-variables
301 nwg-hello-configuration-halt-command
302 nwg-hello-configuration-reboot-command
303 nwg-hello-configuration-shutdown-command
304 nwg-hello-configuration-gtk-theme
305 nwg-hello-configuration-icon-theme
306 nwg-hello-configuration-cursor-theme
307 nwg-hello-configuration-prefer-dark-theme?
308 nwg-hello-configuration-extra-config
309 nwg-hello-style
310 nwg-hello-style?
311 nwg-hello-style-background-image
312 nwg-hello-style-background-size
313 nwg-hello-style-extra-style
314 greetd-nwg-hello-sway-session
315 greetd-nwg-hello-sway-session?
316 greetd-nwg-hello-sway-session-sway
317 greetd-nwg-hello-sway-session-sway-configuration
318 greetd-nwg-hello-sway-session-nwg-hello
319 greetd-nwg-hello-sway-session-nwg-hello-config
320 greetd-nwg-hello-sway-session-nwg-hello-style
292 321
293 %base-services)) 322 %base-services))
294 323
@@ -4039,6 +4068,223 @@ to handle."
4039 sway 4068 sway
4040 (make-greetd-gtkgreet-sway-session-sway-config session))))) 4069 (make-greetd-gtkgreet-sway-session-sway-config session)))))
4041 4070
4071(define (alist-of pred?)
4072 "Return a procedure that takes an association list and check if all the
4073elements of the list result in @code{#t} when applying PRED? on them."
4074 (lambda (x)
4075 (if (alist? x)
4076 (every pred? x)
4077 #f)))
4078
4079(define alist-of-strings-to-greetd-user-sessions?
4080 (alist-of (match-lambda
4081 ((key . value)
4082 (if (and (string? key)
4083 (greetd-user-session? value))
4084 #t
4085 #f)))))
4086
4087(define alist-of-strings-to-strings?
4088 (alist-of (match-lambda
4089 ((key . value)
4090 (if (and (string? key)
4091 (string? value))
4092 #t
4093 #f)))))
4094
4095(define-maybe/no-serialization alist-of-strings-to-strings)
4096
4097(define-configuration/no-serialization nwg-hello-configuration
4098 (session-dirs
4099 (list-of-strings
4100 '("/run/current-system/profile/share/wayland-sessions"
4101 "/run/current-system/profile/share/xsessions"))
4102 "List of directories containing Wayland or X session desktop files.")
4103 (custom-sessions
4104 (alist-of-strings-to-greetd-user-sessions
4105 `(("Shell" . ,(greetd-user-session))))
4106 "Session names and the commands.")
4107 (environment-variables
4108 (alist-of-strings-to-strings '())
4109 "Environment variables associated to their values to pass to user sessions.")
4110 (halt-command
4111 (string "loginctl suspend")
4112 "Command to run when halting the device.")
4113 (reboot-command
4114 (string "loginctl reboot")
4115 "Command to run when rebooting the device.")
4116 (shutdown-command
4117 (string "loginctl poweroff")
4118 "Command to run when shutting down the device.")
4119 (gtk-theme
4120 (string "Advaita")
4121 "GTK theme to use.")
4122 (icon-theme
4123 (string "Advaita")
4124 "Icon theme to use.")
4125 (cursor-theme
4126 (string "Adwaita")
4127 "Cursor theme to use.")
4128 (prefer-dark-theme?
4129 (boolean #t)
4130 "Flag to prefer dark mode for the theme.")
4131 (extra-config
4132 (maybe-alist-of-strings-to-strings)
4133 "Extra configuration of keys and values."))
4134
4135(define nwg-hello-configuration-file
4136 (match-record-lambda <nwg-hello-configuration>
4137 (session-dirs custom-sessions environment-variables halt-command
4138 reboot-command shutdown-command gtk-theme icon-theme cursor-theme
4139 prefer-dark-theme? extra-config)
4140 (apply mixed-text-file "nwg-hello.json"
4141 (append '("{")
4142
4143 `("\n \"session_dirs\": [\n "
4144 ,(string-join (map (lambda (dir)
4145 (string-append "\"" dir "\""))
4146 session-dirs)
4147 ",\n ")
4148 "\n ]")
4149 `(",\n \"custom_sessions\": [\n "
4150 ,@(append-map (lambda (custom-session)
4151 `("{\n "
4152 "\"name\": \"" ,(car custom-session)
4153 "\",\n "
4154 "\"exec\": \"" ,(cdr custom-session)
4155 "\"\n }"
4156 ,(if (eq? custom-session
4157 (list-ref custom-sessions
4158 (- (length
4159 custom-sessions)
4160 1)))
4161 ""
4162 ",\"\n ")))
4163 custom-sessions)
4164 "\n ]")
4165 `(",\n \"cmd-sleep\": \"" ,halt-command "\"")
4166 `(",\n \"cmd-reboot\": \"" ,reboot-command "\"")
4167 `(",\n \"cmd-poweroff\": \"" ,shutdown-command "\"")
4168 `(",\n \"gtk-theme\": \"" ,gtk-theme "\"")
4169 `(",\n \"gtk-icon-theme\": \"" ,icon-theme "\"")
4170 `(",\n \"gtk-cursor-theme\": \"" ,cursor-theme "\"")
4171 `(",\n \"prefer-dark-theme\": "
4172 ,(if prefer-dark-theme? "true" "false"))
4173 `(",\n \"env-vars\": [\n "
4174 ,(string-join (map (match-lambda
4175 ((key . value)
4176 (string-append "\"" key "="
4177 value "\"")))
4178 environment-variables)
4179 ",\n ")
4180 "\n ]")
4181 (if (maybe-value-set? extra-config)
4182 (map (match-lambda
4183 ((key . value)
4184 (string-append ",\n \"" key "\": " value)))
4185 extra-config)
4186 '())
4187 '("\n}\n")))))
4188
4189(define (file-like-or-#f? value)
4190 (or (file-like? value)
4191 (not value)))
4192
4193(define alist-of-strings-to-alists-of-strings-to-strings?
4194 (alist-of (match-lambda
4195 ((key . value)
4196 (if (and (string? key)
4197 (alist-of-strings-to-strings? value))
4198 #t
4199 #f)))))
4200
4201(define-maybe/no-serialization alist-of-strings-to-alists-of-strings-to-strings)
4202
4203(define-configuration/no-serialization nwg-hello-style
4204 (background-image
4205 (file-like-or-#f (file-append nwg-hello "/share/nwg-hello/nwg.jpg"))
4206 "Image file to be set as the background. Setting this to @code{#f} respects
4207the background color.")
4208 (background-size
4209 (string "auto 100%")
4210 "Size of the background image. It can be @code{\"auto\"} (for preserving the
4211original size), @code{\"cover\"} (for resizing to fill while allowing to cut or
4212to stretch), @code{\"contain\"} (for resizing to fit assuring the full
4213visibility of the image), or a string of a number suffixed with with @code{px}
4214(to represent in pixels) or @code{%} (to represent in percentage). It can also
4215be a string of two such values separated by a whitespace, representing width and
4216height respectively.")
4217 (extra-style
4218 (maybe-alist-of-strings-to-alists-of-strings-to-strings)
4219 "List of CSS selectors associated to their lists of CSS properties
4220associated to their values."))
4221
4222(define nwg-hello-stylesheet
4223 (match-record-lambda <nwg-hello-style>
4224 (background-image background-size extra-style)
4225 (apply mixed-text-file "nwg-hello.css"
4226 "window {\n\tbackground-image: "
4227 #~(if #$background-image
4228 (string-append "url(\"" #$background-image "\")")
4229 "none")
4230 "; background-size: " background-size ";\n}"
4231 (append-map (match-lambda
4232 ((selector . declaration)
4233 `(,(string-append "\n" selector " {")
4234 ,@(map (match-lambda
4235 ((property . value)
4236 (string-append "\n\t" property ": " value
4237 ";")))
4238 declaration)
4239 "\n}")))
4240 (if (maybe-value-set? extra-style) extra-style '())))))
4241
4242(define-maybe/no-serialization file-like)
4243
4244(define-configuration/no-serialization greetd-nwg-hello-sway-session
4245 (sway
4246 (package sway)
4247 "Package providing the @command{sway} and @command{swaymsg} commands.")
4248 (sway-configuration
4249 (maybe-file-like)
4250 "Extra configuration for @command{sway} to be included before executing the
4251greeter.")
4252 (nwg-hello
4253 (package nwg-hello)
4254 "Package providing the @command{nwg-hello} command.")
4255 (nwg-hello-config
4256 (nwg-hello-configuration (nwg-hello-configuration))
4257 "Configuration of @command{nwg-hello}.")
4258 (nwg-hello-style
4259 (nwg-hello-style (nwg-hello-style))
4260 "CSS style rules for @command{nwg-hello}."))
4261
4262(define make-greetd-nwg-hello-sway-session-sway-config
4263 (match-record-lambda <greetd-nwg-hello-sway-session>
4264 (sway sway-configuration nwg-hello nwg-hello-config nwg-hello-style)
4265 (let ((nwg-hello-bin (file-append nwg-hello "/bin/nwg-hello"))
4266 (nwg-hello-configuration-file
4267 (nwg-hello-configuration-file nwg-hello-config))
4268 (nwg-hello-stylesheet (nwg-hello-stylesheet nwg-hello-style))
4269 (swaymsg-bin (file-append sway "/bin/swaymsg")))
4270 (mixed-text-file "nwg-hello-sway-config"
4271 (if (maybe-value-set? sway-configuration)
4272 #~(string-append "include " #$sway-configuration "\n")
4273 "")
4274 "xwayland disable\n"
4275 "exec \"" nwg-hello-bin " -l"
4276 " -c " nwg-hello-configuration-file " -s " nwg-hello-stylesheet
4277 "\""))))
4278
4279(define-gexp-compiler (greetd-nwg-hello-sway-session-compiler
4280 (session <greetd-nwg-hello-sway-session>)
4281 system target)
4282 (match-record session <greetd-nwg-hello-sway-session> (sway)
4283 (lower-object
4284 (make-greetd-sway-greeter-command
4285 sway
4286 (make-greetd-nwg-hello-sway-session-sway-config session)))))
4287
4042(define-record-type* <greetd-terminal-configuration> 4288(define-record-type* <greetd-terminal-configuration>
4043 greetd-terminal-configuration make-greetd-terminal-configuration 4289 greetd-terminal-configuration make-greetd-terminal-configuration
4044 greetd-terminal-configuration? 4290 greetd-terminal-configuration?