summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnu/services/xorg.scm56
-rw-r--r--tests/services/xorg.scm232
2 files changed, 276 insertions, 12 deletions
diff --git a/gnu/services/xorg.scm b/gnu/services/xorg.scm
index 25f44566beb..313023f38a0 100644
--- a/gnu/services/xorg.scm
+++ b/gnu/services/xorg.scm
@@ -16,6 +16,7 @@
16;;; Copyright © 2023 muradm <mail@muradm.net> 16;;; Copyright © 2023 muradm <mail@muradm.net>
17;;; Copyright © 2024 Zheng Junjie <873216071@qq.com> 17;;; Copyright © 2024 Zheng Junjie <873216071@qq.com>
18;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz> 18;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz>
19;;; Copyright © 2025 Ian Eure <ian@retrospec.tv>
19;;; 20;;;
20;;; This file is part of GNU Guix. 21;;; This file is part of GNU Guix.
21;;; 22;;;
@@ -43,6 +44,7 @@
43 #:use-module (gnu system privilege) 44 #:use-module (gnu system privilege)
44 #:use-module (gnu services base) 45 #:use-module (gnu services base)
45 #:use-module (gnu services dbus) 46 #:use-module (gnu services dbus)
47 #:use-module (gnu services desktop)
46 #:use-module (gnu packages base) 48 #:use-module (gnu packages base)
47 #:use-module (gnu packages guile) 49 #:use-module (gnu packages guile)
48 #:use-module (gnu packages xorg) 50 #:use-module (gnu packages xorg)
@@ -194,6 +196,8 @@ the first one in the list is loaded."
194 ;; Default command-line arguments for X. 196 ;; Default command-line arguments for X.
195 '("-nolisten" "tcp")) 197 '("-nolisten" "tcp"))
196 198
199(define %default-xorg-server xorg-server)
200
197;; Configuration of an Xorg server. 201;; Configuration of an Xorg server.
198(define-record-type* <xorg-configuration> 202(define-record-type* <xorg-configuration>
199 xorg-configuration make-xorg-configuration 203 xorg-configuration make-xorg-configuration
@@ -217,10 +221,42 @@ the first one in the list is loaded."
217 (extra-config xorg-configuration-extra-config ;list of strings 221 (extra-config xorg-configuration-extra-config ;list of strings
218 (default '())) 222 (default '()))
219 (server xorg-configuration-server ;file-like 223 (server xorg-configuration-server ;file-like
220 (default xorg-server)) 224 (default %default-xorg-server))
221 (server-arguments xorg-configuration-server-arguments ;list of strings 225 (server-arguments xorg-configuration-server-arguments ;list of strings
222 (default %default-xorg-server-arguments))) 226 (default %default-xorg-server-arguments)))
223 227
228(define (merge-xorg-configurations configs)
229 ;; Find whichever config has a non-default Xorg server.
230 (let ((config-with-server
231 (or
232 (find
233 (lambda (config)
234 (or (not (eq? %default-xorg-server
235 (xorg-configuration-server config)))
236 (not (eq? %default-xorg-server-arguments
237 (xorg-configuration-server-arguments config)))))
238 (reverse configs))
239 (xorg-configuration))))
240
241 (xorg-configuration
242 (modules
243 (delete-duplicates (append-map xorg-configuration-modules configs)))
244 (fonts
245 (delete-duplicates (append-map xorg-configuration-fonts configs)))
246 (drivers
247 (delete-duplicates (append-map xorg-configuration-drivers configs)))
248 (resolutions
249 (delete-duplicates (append-map xorg-configuration-resolutions configs)))
250 (extra-config
251 (append-map xorg-configuration-extra-config configs))
252 (keyboard-layout
253 (any xorg-configuration-keyboard-layout (reverse configs)))
254 ;; Use the later config with non-default server for both these fields.
255 (server
256 (xorg-configuration-server config-with-server))
257 (server-arguments
258 (xorg-configuration-server-arguments config-with-server)))))
259
224(define (xorg-configuration->file config) 260(define (xorg-configuration->file config)
225 "Compute an Xorg configuration file corresponding to CONFIG, an 261 "Compute an Xorg configuration file corresponding to CONFIG, an
226<xorg-configuration> record." 262<xorg-configuration> record."
@@ -347,7 +383,7 @@ EndSection\n" port)
347 (newline port))) 383 (newline port)))
348 384
349 (for-each (lambda (config) 385 (for-each (lambda (config)
350 (display config port)) 386 (display (string-append config "\n\n") port))
351 '#$(xorg-configuration-extra-config config)))))) 387 '#$(xorg-configuration-extra-config config))))))
352 388
353 (computed-file "xserver.conf" build))) 389 (computed-file "xserver.conf" build)))
@@ -644,16 +680,12 @@ a `service-extension', as used by `set-xorg-configuration'."
644 ((_ configuration-record service-type-definition) 680 ((_ configuration-record service-type-definition)
645 (service-type 681 (service-type
646 (inherit service-type-definition) 682 (inherit service-type-definition)
647 (compose (lambda (extensions) 683 (compose cons*)
648 (match extensions 684 (extend (lambda (config xorg-configurations)
649 (() #f) 685 (configuration-record
650 ((config . _) config)))) 686 (inherit config)
651 (extend (lambda (config xorg-configuration) 687 (xorg-configuration
652 (if xorg-configuration 688 (merge-xorg-configurations xorg-configurations)))))))))
653 (configuration-record
654 (inherit config)
655 (xorg-configuration xorg-configuration))
656 config)))))))
657 689
658(define (xorg-server-profile-service config) 690(define (xorg-server-profile-service config)
659 ;; XXX: profile-service-type only accepts <package> objects. 691 ;; XXX: profile-service-type only accepts <package> objects.
diff --git a/tests/services/xorg.scm b/tests/services/xorg.scm
new file mode 100644
index 00000000000..0bb4a3e14cf
--- /dev/null
+++ b/tests/services/xorg.scm
@@ -0,0 +1,232 @@
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2025 Ian Eure <ian@retrospec.tv>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (tests services xorg)
20 #:use-module (guix diagnostics)
21 #:use-module (guix packages)
22 #:use-module (gnu packages xorg)
23 #:use-module (gnu bootloader)
24 #:use-module (gnu bootloader grub)
25 #:use-module (gnu services)
26 #:use-module (gnu services base)
27 #:use-module (gnu services xorg)
28 #:use-module (gnu system)
29 #:use-module (gnu system keyboard)
30 #:use-module (gnu system file-systems)
31 #:use-module ((srfi srfi-1) #:select (find))
32 #:use-module (srfi srfi-64))
33
34;;; Tests for the (gnu services xorg) module.
35
36(define %config-empty (xorg-configuration))
37
38(define %default-server (xorg-configuration-server %config-empty))
39
40
41
42(test-begin "merge-xorg-configurations")
43
44(define merge-xorg-configurations
45 (@@ (gnu services xorg) merge-xorg-configurations))
46
47(define gdm-configuration-xorg
48 (@@ (gnu services xorg) gdm-configuration-xorg))
49
50;; keyboard-layout tests.
51
52(define %config-xorg-keyboard-layout-1
53 (xorg-configuration
54 (keyboard-layout (keyboard-layout "us" #:options '("ctrl:nocaps")))))
55
56(define %config-xorg-keyboard-layout-2
57 (xorg-configuration
58 (keyboard-layout (keyboard-layout "us" #:options '("ctrl:esc")))))
59
60;; Later keyboard layouts replace earlier defaults
61(test-equal
62 (keyboard-layout "us" #:options '("ctrl:nocaps"))
63 (xorg-configuration-keyboard-layout
64 (merge-xorg-configurations
65 (list %config-empty %config-xorg-keyboard-layout-1))))
66
67;; Later keyboard layouts replace earlier customizations.
68(test-equal
69 (keyboard-layout "us" #:options '("ctrl:esc"))
70 (xorg-configuration-keyboard-layout
71 (merge-xorg-configurations (list %config-empty
72 %config-xorg-keyboard-layout-1
73 %config-xorg-keyboard-layout-2))))
74
75;; server, server-arguments tests.
76
77(define %custom-server-1
78 (package
79 (inherit xorg-server)
80 (name "fake-xorg-server")))
81
82(define %custom-server-2
83 (package
84 (inherit xorg-server)
85 (name "another-fake-xorg-server")))
86
87(define %custom-server-1-arguments
88 (cons "-nosilk" %default-xorg-server-arguments))
89
90(define %custom-server-2-arguments
91 (cons* "-logverbose" "9" %default-xorg-server-arguments))
92
93(define %config-custom-server-1
94 (xorg-configuration
95 (server %custom-server-1)))
96
97(define %config-custom-server-2
98 (xorg-configuration
99 (server %custom-server-2)))
100
101(define %config-custom-server-1-and-arguments
102 (xorg-configuration
103 (inherit %config-custom-server-1)
104 (server-arguments %custom-server-1-arguments)))
105
106(define %config-custom-server-2-and-arguments
107 (xorg-configuration
108 (inherit %config-custom-server-2)
109 (server-arguments %custom-server-2-arguments)))
110
111;; Custom server is prioritized over earlier default.
112(test-equal
113 %custom-server-1
114 (xorg-configuration-server
115 (merge-xorg-configurations (list %config-empty
116 %config-custom-server-1))))
117
118;; Custom server preserves arguments.
119(test-equal
120 (list %custom-server-1 %custom-server-1-arguments)
121 (let ((cfg (merge-xorg-configurations
122 (list
123 %config-empty
124 %config-custom-server-1-and-arguments))))
125 (list (xorg-configuration-server cfg)
126 (xorg-configuration-server-arguments cfg))))
127
128;; Later custom arguments replace earlier.
129(test-equal
130 (list %custom-server-2 %custom-server-2-arguments)
131 (let ((cfg (merge-xorg-configurations
132 (list
133 %config-empty
134 %config-custom-server-1-and-arguments
135 %config-custom-server-2-and-arguments))))
136 (list (xorg-configuration-server cfg)
137 (xorg-configuration-server-arguments cfg))))
138
139;; Custom server is prioritized over later default.
140(test-equal
141 %custom-server-1
142 (xorg-configuration-server
143 (merge-xorg-configurations (list %config-custom-server-1
144 %config-empty))))
145
146;; Custom arguments are prioritized over earlier custom server.
147(test-equal
148 %custom-server-2-arguments
149 (xorg-configuration-server-arguments
150 (merge-xorg-configurations
151 (list
152 (xorg-configuration (server %custom-server-1))
153 (xorg-configuration (server-arguments %custom-server-2-arguments))))))
154
155;; Later custom servers are prioritized over earlier.
156(test-equal
157 %custom-server-2
158 (xorg-configuration-server
159 (merge-xorg-configurations (list %config-custom-server-1
160 %config-empty
161 %config-custom-server-2))))
162
163(test-equal
164 %custom-server-2
165 (xorg-configuration-server
166 (merge-xorg-configurations (list %config-empty
167 %config-custom-server-1
168 %config-custom-server-2))))
169
170(test-equal
171 %custom-server-1
172 (xorg-configuration-server
173 (merge-xorg-configurations (list %config-empty
174 %config-custom-server-1))))
175
176;; Make sure it works in the context of an operating-system.
177(test-equal
178 %custom-server-2
179 (let ((os (operating-system
180 (host-name "test")
181 (bootloader
182 (bootloader-configuration
183 (bootloader grub-bootloader)
184 (targets '("/dev/sdX"))))
185 (file-systems
186 (cons
187 (file-system
188 (device (file-system-label "my-root"))
189 (mount-point "/")
190 (type "ext4"))
191 %base-file-systems))
192 (services
193 (cons*
194 (simple-service 'server-2 gdm-service-type
195 %config-custom-server-2)
196 (simple-service 'server-1 gdm-service-type
197 %config-custom-server-1)
198 (service gdm-service-type)
199 %base-services)))))
200 (xorg-configuration-server
201 (gdm-configuration-xorg
202 (service-value
203 (fold-services
204 (operating-system-services os)
205 #:target-type gdm-service-type))))))
206
207;; extra-config tests.
208
209;; Extra configurations append.
210(let ((snippet-one "# First")
211 (snippet-two "# Second"))
212 (test-equal
213 (list snippet-one snippet-two)
214 (xorg-configuration-extra-config
215 (merge-xorg-configurations
216 (list (xorg-configuration (extra-config (list snippet-one)))
217 (xorg-configuration (extra-config (list snippet-two))))))))
218
219;; drivers tests.
220
221(define %drivers-custom-1 '("done"))
222(define %drivers-custom-2 '("dtwo"))
223
224(test-equal
225 (append %drivers-custom-1 %drivers-custom-2)
226 (xorg-configuration-drivers
227 (merge-xorg-configurations
228 (list
229 (xorg-configuration (drivers %drivers-custom-1))
230 (xorg-configuration (drivers %drivers-custom-2))))))
231
232(test-end "merge-xorg-configurations")