diff options
| author | Ian Eure <ian@retrospec.tv> | 2025-03-25 15:17:03 -0700 |
|---|---|---|
| committer | Liliana Marie Prikler <liliana.prikler@gmail.com> | 2025-12-26 13:15:41 +0100 |
| commit | a9462997d743e4cb4edd557d7ffeeb98048bb4de (patch) | |
| tree | db25b0bfd34b27c27711862c948cca9e8796825a /tests | |
| parent | 5ef86f97e23bb6bc1bb16ece959a597b306916b3 (diff) | |
gnu: Merge xorg configurations when extending.
Configuration for xorg is embedded in the various display-manager
configuration records, and extension support is factored out into the
`handle-xorg-configuration' macro. However, the extension mechanism replaces
the existing xorg-configuration with the supplied one, making it impossible to
compose configuration from multiple sources. This patch adds a procedure to
merge two xorg-configuration records, and calls it within
handle-xorg-configuration, allowing the config to be built piecemeal.
* gnu/services/xorg.scm (merge-xorg-configurations): New variable.
(handle-xorg-configuration): Merge xorg configs.
Change-Id: I20e9db911eef5d4efe98fdf382f3084e4defc1ba
Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/services/xorg.scm | 232 |
1 files changed, 232 insertions, 0 deletions
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") | ||
