~ruther/guix-local

ref: a9462997d743e4cb4edd557d7ffeeb98048bb4de guix-local/tests/services/xorg.scm -rw-r--r-- 7.4 KiB
a9462997 — Ian Eure gnu: Merge xorg configurations when extending. 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2025 Ian Eure <ian@retrospec.tv>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (tests services xorg)
  #:use-module (guix diagnostics)
  #:use-module (guix packages)
  #:use-module (gnu packages xorg)
  #:use-module (gnu bootloader)
  #:use-module (gnu bootloader grub)
  #:use-module (gnu services)
  #:use-module (gnu services base)
  #:use-module (gnu services xorg)
  #:use-module (gnu system)
  #:use-module (gnu system keyboard)
  #:use-module (gnu system file-systems)
  #:use-module ((srfi srfi-1) #:select (find))
  #:use-module (srfi srfi-64))

;;; Tests for the (gnu services xorg) module.

(define %config-empty (xorg-configuration))

(define %default-server (xorg-configuration-server %config-empty))



(test-begin "merge-xorg-configurations")

(define merge-xorg-configurations
  (@@ (gnu services xorg) merge-xorg-configurations))

(define gdm-configuration-xorg
  (@@ (gnu services xorg) gdm-configuration-xorg))

;; keyboard-layout tests.

(define %config-xorg-keyboard-layout-1
  (xorg-configuration
    (keyboard-layout (keyboard-layout "us" #:options '("ctrl:nocaps")))))

(define %config-xorg-keyboard-layout-2
  (xorg-configuration
    (keyboard-layout (keyboard-layout "us" #:options '("ctrl:esc")))))

;; Later keyboard layouts replace earlier defaults
(test-equal
    (keyboard-layout "us" #:options '("ctrl:nocaps"))
  (xorg-configuration-keyboard-layout
   (merge-xorg-configurations
    (list %config-empty %config-xorg-keyboard-layout-1))))

;; Later keyboard layouts replace earlier customizations.
(test-equal
    (keyboard-layout "us" #:options '("ctrl:esc"))
  (xorg-configuration-keyboard-layout
   (merge-xorg-configurations (list %config-empty
                                    %config-xorg-keyboard-layout-1
                                    %config-xorg-keyboard-layout-2))))

;; server, server-arguments tests.

(define %custom-server-1
  (package
    (inherit xorg-server)
    (name "fake-xorg-server")))

(define %custom-server-2
  (package
    (inherit xorg-server)
    (name "another-fake-xorg-server")))

(define %custom-server-1-arguments
  (cons "-nosilk" %default-xorg-server-arguments))

(define %custom-server-2-arguments
  (cons* "-logverbose" "9" %default-xorg-server-arguments))

(define %config-custom-server-1
  (xorg-configuration
    (server %custom-server-1)))

(define %config-custom-server-2
  (xorg-configuration
    (server %custom-server-2)))

(define %config-custom-server-1-and-arguments
  (xorg-configuration
    (inherit %config-custom-server-1)
    (server-arguments %custom-server-1-arguments)))

(define %config-custom-server-2-and-arguments
  (xorg-configuration
    (inherit %config-custom-server-2)
    (server-arguments %custom-server-2-arguments)))

;; Custom server is prioritized over earlier default.
(test-equal
    %custom-server-1
  (xorg-configuration-server
   (merge-xorg-configurations (list %config-empty
                                    %config-custom-server-1))))

;; Custom server preserves arguments.
(test-equal
    (list %custom-server-1 %custom-server-1-arguments)
  (let ((cfg (merge-xorg-configurations
              (list
               %config-empty
               %config-custom-server-1-and-arguments))))
    (list (xorg-configuration-server cfg)
          (xorg-configuration-server-arguments cfg))))

;; Later custom arguments replace earlier.
(test-equal
    (list %custom-server-2 %custom-server-2-arguments)
  (let ((cfg (merge-xorg-configurations
              (list
               %config-empty
               %config-custom-server-1-and-arguments
               %config-custom-server-2-and-arguments))))
    (list (xorg-configuration-server cfg)
          (xorg-configuration-server-arguments cfg))))

;; Custom server is prioritized over later default.
(test-equal
    %custom-server-1
  (xorg-configuration-server
   (merge-xorg-configurations (list %config-custom-server-1
                                    %config-empty))))

;; Custom arguments are prioritized over earlier custom server.
(test-equal
    %custom-server-2-arguments
  (xorg-configuration-server-arguments
   (merge-xorg-configurations
    (list
     (xorg-configuration (server %custom-server-1))
     (xorg-configuration (server-arguments %custom-server-2-arguments))))))

;; Later custom servers are prioritized over earlier.
(test-equal
    %custom-server-2
  (xorg-configuration-server
   (merge-xorg-configurations (list %config-custom-server-1
                                    %config-empty
                                    %config-custom-server-2))))

(test-equal
    %custom-server-2
  (xorg-configuration-server
   (merge-xorg-configurations (list %config-empty
                                    %config-custom-server-1
                                    %config-custom-server-2))))

(test-equal
    %custom-server-1
  (xorg-configuration-server
   (merge-xorg-configurations (list %config-empty
                                    %config-custom-server-1))))

;; Make sure it works in the context of an operating-system.
(test-equal
    %custom-server-2
  (let ((os (operating-system
              (host-name "test")
              (bootloader
                (bootloader-configuration
                  (bootloader grub-bootloader)
                  (targets '("/dev/sdX"))))
              (file-systems
               (cons
                (file-system
                  (device (file-system-label "my-root"))
                  (mount-point "/")
                  (type "ext4"))
                %base-file-systems))
              (services
               (cons*
                (simple-service 'server-2 gdm-service-type
                                %config-custom-server-2)
                (simple-service 'server-1 gdm-service-type
                                %config-custom-server-1)
                (service gdm-service-type)
                %base-services)))))
    (xorg-configuration-server
     (gdm-configuration-xorg
      (service-value
       (fold-services
        (operating-system-services os)
        #:target-type gdm-service-type))))))

;; extra-config tests.

;; Extra configurations append.
(let ((snippet-one "# First")
      (snippet-two "# Second"))
  (test-equal
      (list snippet-one snippet-two)
    (xorg-configuration-extra-config
     (merge-xorg-configurations
      (list (xorg-configuration (extra-config (list snippet-one)))
            (xorg-configuration (extra-config (list snippet-two))))))))

;; drivers tests.

(define %drivers-custom-1 '("done"))
(define %drivers-custom-2 '("dtwo"))

(test-equal
    (append %drivers-custom-1 %drivers-custom-2)
  (xorg-configuration-drivers
   (merge-xorg-configurations
    (list
     (xorg-configuration (drivers %drivers-custom-1))
     (xorg-configuration (drivers %drivers-custom-2))))))

(test-end "merge-xorg-configurations")