| 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 | (define-module (gnu services xorg)
|
| 43 | #:autoload (gnu services sddm) (sddm-service-type)
|
| 44 | #:use-module (gnu artwork)
|
| 45 | #:use-module (gnu services)
|
| 46 | #:use-module (gnu services configuration)
|
| 47 | #:use-module (gnu services shepherd)
|
| 48 | #:use-module (gnu system keyboard)
|
| 49 | #:use-module (gnu system pam)
|
| 50 | #:use-module (gnu system privilege)
|
| 51 | #:use-module (gnu services base)
|
| 52 | #:use-module (gnu services dbus)
|
| 53 | #:use-module (gnu packages base)
|
| 54 | #:use-module (gnu packages guile)
|
| 55 | #:use-module (gnu packages xorg)
|
| 56 | #:use-module (gnu packages fonts)
|
| 57 | #:use-module (gnu packages gl)
|
| 58 | #:use-module (gnu packages glib)
|
| 59 | #:use-module (gnu packages display-managers)
|
| 60 | #:use-module (gnu packages freedesktop)
|
| 61 | #:use-module (gnu packages gnustep)
|
| 62 | #:use-module (gnu packages gnome)
|
| 63 | #:use-module (gnu packages admin)
|
| 64 | #:use-module (gnu packages bash)
|
| 65 | #:use-module (gnu packages linux)
|
| 66 | #:use-module (gnu system shadow)
|
| 67 | #:use-module (guix build-system glib-or-gtk)
|
| 68 | #:use-module (guix build-system trivial)
|
| 69 | #:use-module (guix diagnostics)
|
| 70 | #:use-module (guix gexp)
|
| 71 | #:use-module (guix store)
|
| 72 | #:use-module ((guix modules) #:select (source-module-closure))
|
| 73 | #:use-module (guix packages)
|
| 74 | #:use-module (guix derivations)
|
| 75 | #:use-module (guix platform)
|
| 76 | #:use-module (guix records)
|
| 77 | #:use-module (guix deprecation)
|
| 78 | #:use-module (guix utils)
|
| 79 | #:use-module (srfi srfi-1)
|
| 80 | #:use-module (srfi srfi-9)
|
| 81 | #:use-module (srfi srfi-26)
|
| 82 | #:use-module (ice-9 format)
|
| 83 | #:use-module (ice-9 match)
|
| 84 | #:export (xorg-configuration
|
| 85 | xorg-configuration?
|
| 86 | xorg-configuration-modules
|
| 87 | xorg-configuration-fonts
|
| 88 | xorg-configuration-drivers
|
| 89 | xorg-configuration-resolutions
|
| 90 | xorg-configuration-extra-config
|
| 91 | xorg-configuration-server
|
| 92 | xorg-configuration-server-arguments
|
| 93 | xorg-configuration-keyboard-layout
|
| 94 |
|
| 95 | %default-xorg-modules
|
| 96 | %default-xorg-fonts
|
| 97 | %default-xorg-server-arguments
|
| 98 |
|
| 99 | xorg-wrapper
|
| 100 | xorg-start-command
|
| 101 | xorg-start-command-xinit
|
| 102 | xinitrc
|
| 103 | xorg-server-service-type
|
| 104 | startx-command-service-type
|
| 105 |
|
| 106 | %default-slim-theme
|
| 107 | %default-slim-theme-name
|
| 108 |
|
| 109 | slim-configuration
|
| 110 | slim-configuration?
|
| 111 | slim-configuration-slim
|
| 112 | slim-configuration-allow-empty-passwords?
|
| 113 | slim-configuration-auto-login?
|
| 114 | slim-configuration-default-user
|
| 115 | slim-configuration-theme
|
| 116 | slim-configuration-theme-name
|
| 117 | slim-configuration-xauth
|
| 118 | slim-configuration-shepherd
|
| 119 | slim-configuration-auto-login-session
|
| 120 | slim-configuration-xorg
|
| 121 | slim-configuration-display
|
| 122 | slim-configuration-vt
|
| 123 | slim-configuration-sessreg
|
| 124 |
|
| 125 | slim-service-type
|
| 126 |
|
| 127 | screen-locker-configuration
|
| 128 | screen-locker-configuration?
|
| 129 | screen-locker-configuration-name
|
| 130 | screen-locker-configuration-program
|
| 131 | screen-locker-configuration-allow-empty-password?
|
| 132 | screen-locker-configuration-using-pam?
|
| 133 | screen-locker-configuration-using-setuid?
|
| 134 | screen-locker-service-type
|
| 135 | screen-locker-service |
| 136 |
|
| 137 | localed-configuration
|
| 138 | localed-configuration?
|
| 139 | localed-service-type
|
| 140 |
|
| 141 | dconf-keyfile
|
| 142 | dconf-profile
|
| 143 | dconf-profile-name
|
| 144 | dconf-profile-content
|
| 145 | dconf-profile-keyfile
|
| 146 | dconf-service-type
|
| 147 |
|
| 148 | gdm-configuration
|
| 149 | gdm-service-type
|
| 150 |
|
| 151 | handle-xorg-configuration
|
| 152 | set-xorg-configuration))
|
| 153 |
|
| 154 | (define* (default-xorg-modules
|
| 155 | #:optional
|
| 156 | (system (or (and=>
|
| 157 | (%current-target-system)
|
| 158 | platform-target->system)
|
| 159 | (%current-system))))
|
| 160 | "Default list of modules loaded by the server. When multiple drivers match,
|
| 161 | the first one in the list is loaded."
|
| 162 | |
| 163 | |
| 164 | (filter (cut supported-package? <> system)
|
| 165 | (list xf86-video-vesa
|
| 166 | xf86-video-fbdev
|
| 167 | xf86-video-amdgpu
|
| 168 | xf86-video-ati
|
| 169 | xf86-video-cirrus
|
| 170 | xf86-video-intel
|
| 171 | xf86-video-mach64
|
| 172 | xf86-video-nouveau
|
| 173 | xf86-video-nv
|
| 174 | xf86-video-sis
|
| 175 |
|
| 176 | |
| 177 | |
| 178 | xf86-input-libinput
|
| 179 | xf86-input-evdev
|
| 180 | xf86-input-mouse)))
|
| 181 |
|
| 182 | (define-syntax %default-xorg-modules
|
| 183 | (identifier-syntax (default-xorg-modules)))
|
| 184 |
|
| 185 | (define %default-xorg-fonts
|
| 186 | |
| 187 | (list (file-append font-alias "/share/fonts/X11/75dpi")
|
| 188 | (file-append font-alias "/share/fonts/X11/100dpi")
|
| 189 | (file-append font-alias "/share/fonts/X11/misc")
|
| 190 | (file-append font-alias "/share/fonts/X11/cyrillic")
|
| 191 | (file-append font-misc-misc |
| 192 | "/share/fonts/X11/misc")
|
| 193 | (file-append font-adobe75dpi "/share/fonts/X11/75dpi")))
|
| 194 |
|
| 195 | (define %default-xorg-server-arguments
|
| 196 | |
| 197 | '("-nolisten" "tcp"))
|
| 198 |
|
| 199 | (define %default-xorg-server xorg-server)
|
| 200 |
|
| 201 | |
| 202 | (define-record-type* <xorg-configuration>
|
| 203 | xorg-configuration make-xorg-configuration
|
| 204 | xorg-configuration?
|
| 205 | (modules xorg-configuration-modules |
| 206 | (thunked)
|
| 207 | |
| 208 | (default (filter
|
| 209 | (lambda (p)
|
| 210 | (member (%current-system)
|
| 211 | (package-supported-systems p)))
|
| 212 | %default-xorg-modules)))
|
| 213 | (fonts xorg-configuration-fonts |
| 214 | (default %default-xorg-fonts))
|
| 215 | (drivers xorg-configuration-drivers |
| 216 | (default '()))
|
| 217 | (resolutions xorg-configuration-resolutions |
| 218 | (default '()))
|
| 219 | (keyboard-layout xorg-configuration-keyboard-layout |
| 220 | (default #f))
|
| 221 | (extra-config xorg-configuration-extra-config |
| 222 | (default '()))
|
| 223 | (server xorg-configuration-server |
| 224 | (default %default-xorg-server))
|
| 225 | (server-arguments xorg-configuration-server-arguments |
| 226 | (default %default-xorg-server-arguments)))
|
| 227 |
|
| 228 | (define (merge-xorg-configurations configs)
|
| 229 | |
| 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 | |
| 255 | (server
|
| 256 | (xorg-configuration-server config-with-server))
|
| 257 | (server-arguments
|
| 258 | (xorg-configuration-server-arguments config-with-server)))))
|
| 259 |
|
| 260 | (define (xorg-configuration->file config)
|
| 261 | "Compute an Xorg configuration file corresponding to CONFIG, an
|
| 262 | <xorg-configuration> record."
|
| 263 | (let ((xorg-server (xorg-configuration-server config)))
|
| 264 | (define all-modules
|
| 265 | |
| 266 | (append (xorg-configuration-modules config)
|
| 267 | (list xorg-server)))
|
| 268 |
|
| 269 | (define build
|
| 270 | #~(begin
|
| 271 | (use-modules (ice-9 match)
|
| 272 | (srfi srfi-1)
|
| 273 | (srfi srfi-26))
|
| 274 |
|
| 275 | (call-with-output-file #$output
|
| 276 | (lambda (port)
|
| 277 | (define drivers
|
| 278 | '#$(xorg-configuration-drivers config))
|
| 279 |
|
| 280 | (define (device-section driver)
|
| 281 | (string-append "
|
| 282 | Section \"Device\"
|
| 283 | Identifier \"device-" driver "\"
|
| 284 | Driver \"" driver "\"
|
| 285 | EndSection"))
|
| 286 |
|
| 287 | (define (screen-section driver resolutions)
|
| 288 | (string-append "
|
| 289 | Section \"Screen\"
|
| 290 | Identifier \"screen-" driver "\"
|
| 291 | Device \"device-" driver "\"
|
| 292 | SubSection \"Display\"
|
| 293 | Modes "
|
| 294 | (string-join (map (match-lambda
|
| 295 | ((x y)
|
| 296 | (string-append "\"" (number->string x)
|
| 297 | "x" (number->string y) "\"")))
|
| 298 | resolutions)) "
|
| 299 | EndSubSection
|
| 300 | EndSection"))
|
| 301 |
|
| 302 | (define (input-class-section layout variant model options)
|
| 303 | (string-append "
|
| 304 | Section \"InputClass\"
|
| 305 | Identifier \"evdev keyboard catchall\"
|
| 306 | MatchIsKeyboard \"on\"
|
| 307 | Option \"XkbLayout\" " (object->string layout)
|
| 308 | (if variant
|
| 309 | (string-append " Option \"XkbVariant\" \""
|
| 310 | variant "\"")
|
| 311 | "")
|
| 312 | (if model
|
| 313 | (string-append " Option \"XkbModel\" \""
|
| 314 | model "\"")
|
| 315 | "")
|
| 316 | (match options
|
| 317 | (()
|
| 318 | "")
|
| 319 | (_
|
| 320 | (string-append " Option \"XkbOptions\" \""
|
| 321 | (string-join options ",") "\""))) "
|
| 322 |
|
| 323 | MatchDevicePath \"/dev/input/event*\"
|
| 324 | Driver \"evdev\"
|
| 325 | EndSection\n"))
|
| 326 |
|
| 327 | (define (expand modules)
|
| 328 | |
| 329 | |
| 330 | (append-map (lambda (module)
|
| 331 | (filter-map (lambda (directory)
|
| 332 | (let ((full (string-append module
|
| 333 | directory)))
|
| 334 | (and (file-exists? full)
|
| 335 | full)))
|
| 336 | '("/lib/xorg/modules/drivers"
|
| 337 | "/lib/xorg/modules/input"
|
| 338 | "/lib/xorg/modules/multimedia"
|
| 339 | "/lib/xorg/modules/extensions")))
|
| 340 | modules))
|
| 341 |
|
| 342 | (display "Section \"Files\"\n" port)
|
| 343 | (for-each (lambda (font)
|
| 344 | (format port " FontPath \"~a\"~%" font))
|
| 345 | '#$(xorg-configuration-fonts config))
|
| 346 | (for-each (lambda (module)
|
| 347 | (format port
|
| 348 | " ModulePath \"~a\"~%"
|
| 349 | module))
|
| 350 | (append (expand '#$all-modules)
|
| 351 |
|
| 352 | |
| 353 | (list #$(file-append xorg-server
|
| 354 | "/lib/xorg/modules"))))
|
| 355 | (display "EndSection\n" port)
|
| 356 | (display "
|
| 357 | Section \"ServerFlags\"
|
| 358 | Option \"AllowMouseOpenFail\" \"on\"
|
| 359 | EndSection\n" port)
|
| 360 |
|
| 361 | (display (string-join (map device-section drivers) "\n")
|
| 362 | port)
|
| 363 | (newline port)
|
| 364 | (display (string-join
|
| 365 | (map (cut screen-section <>
|
| 366 | '#$(xorg-configuration-resolutions config))
|
| 367 | drivers)
|
| 368 | "\n")
|
| 369 | port)
|
| 370 | (newline port)
|
| 371 |
|
| 372 | (let ((layout #$(and=> (xorg-configuration-keyboard-layout config)
|
| 373 | keyboard-layout-name))
|
| 374 | (variant #$(and=> (xorg-configuration-keyboard-layout config)
|
| 375 | keyboard-layout-variant))
|
| 376 | (model #$(and=> (xorg-configuration-keyboard-layout config)
|
| 377 | keyboard-layout-model))
|
| 378 | (options '#$(and=> (xorg-configuration-keyboard-layout config)
|
| 379 | keyboard-layout-options)))
|
| 380 | (when layout
|
| 381 | (display (input-class-section layout variant model options)
|
| 382 | port)
|
| 383 | (newline port)))
|
| 384 |
|
| 385 | (for-each (lambda (config)
|
| 386 | (display (string-append config "\n\n") port))
|
| 387 | '#$(xorg-configuration-extra-config config))))))
|
| 388 |
|
| 389 | (computed-file "xserver.conf" build)))
|
| 390 |
|
| 391 | (define (xorg-configuration-directory modules)
|
| 392 | "Return a directory that contains the @code{.conf} files for X.org that
|
| 393 | includes the @code{share/X11/xorg.conf.d} directories of each package listed
|
| 394 | in @var{modules}."
|
| 395 | (with-imported-modules '((guix build utils))
|
| 396 | (computed-file "xorg.conf.d"
|
| 397 | #~(begin
|
| 398 | (use-modules (guix build utils)
|
| 399 | (srfi srfi-1))
|
| 400 |
|
| 401 | (define files
|
| 402 | (append-map (lambda (module)
|
| 403 | (find-files (string-append
|
| 404 | module
|
| 405 | "/share/X11/xorg.conf.d")
|
| 406 | "\\.conf$"))
|
| 407 | (list #$@modules)))
|
| 408 |
|
| 409 | (mkdir #$output)
|
| 410 | (for-each (lambda (file)
|
| 411 | (symlink file
|
| 412 | (string-append #$output "/"
|
| 413 | (basename file))))
|
| 414 | files)
|
| 415 | #t))))
|
| 416 |
|
| 417 | (define (xorg-configuration-server-package-path config input path)
|
| 418 | "Lookup the direct @var{input} in the xorg server package of @var{config}
|
| 419 | and append @var{path} to it."
|
| 420 | (let* ((server (xorg-configuration-server config))
|
| 421 | (package (lookup-package-direct-input server input)))
|
| 422 | (when package (file-append package path))))
|
| 423 |
|
| 424 | (define (xorg-configuration-dri-driver-path config)
|
| 425 | (xorg-configuration-server-package-path config "mesa" "/lib/dri"))
|
| 426 |
|
| 427 | (define (xorg-configuration-xkb-bin-dir config)
|
| 428 | (xorg-configuration-server-package-path config "xkbcomp" "/bin"))
|
| 429 |
|
| 430 | (define (xorg-configuration-xkb-dir config)
|
| 431 | (xorg-configuration-server-package-path config "xkeyboard-config" "/share/X11/xkb"))
|
| 432 |
|
| 433 | (define* (xorg-wrapper #:optional (config (xorg-configuration)))
|
| 434 | "Return a derivation that builds a script to start the X server with the
|
| 435 | given @var{config}. The resulting script should be used in place of
|
| 436 | @code{/usr/bin/X}."
|
| 437 | (define exp
|
| 438 | |
| 439 | #~(begin
|
| 440 | (setenv "XORG_DRI_DRIVER_PATH"
|
| 441 | #$(xorg-configuration-dri-driver-path config))
|
| 442 | (setenv "XKB_BINDIR" #$(xorg-configuration-xkb-bin-dir config))
|
| 443 |
|
| 444 | (let ((X (string-append #$(xorg-configuration-server config) "/bin/X")))
|
| 445 | (apply execl X X
|
| 446 | "-xkbdir" #$(xorg-configuration-xkb-dir config)
|
| 447 | "-config" #$(xorg-configuration->file config)
|
| 448 | "-configdir" #$(xorg-configuration-directory
|
| 449 | (xorg-configuration-modules config))
|
| 450 | (cdr (command-line))))))
|
| 451 |
|
| 452 | (program-file "X-wrapper" exp))
|
| 453 |
|
| 454 | (define* (xorg-start-command #:optional (config (xorg-configuration)))
|
| 455 | "Return a @code{startx} script in which the modules, fonts, etc. specified
|
| 456 | in @var{config}, are available. The result should be used in place of
|
| 457 | @code{startx}."
|
| 458 | (define X
|
| 459 | (xorg-wrapper config))
|
| 460 |
|
| 461 | (define exp
|
| 462 | |
| 463 | #~(apply execl #$X #$X |
| 464 | "-logverbose" "-verbose" "-terminate"
|
| 465 | #$@(xorg-configuration-server-arguments config)
|
| 466 | (cdr (command-line))))
|
| 467 |
|
| 468 | (program-file "startx" exp))
|
| 469 |
|
| 470 | (define* (xorg-start-command-xinit #:optional (config (xorg-configuration)))
|
| 471 | "Return a @code{startx} script in which the modules, fonts, etc. specified
|
| 472 | in @var{config}, are available. The result should be used in place of
|
| 473 | @code{startx}. Compared to the @code{xorg-start-command} it calls xinit,
|
| 474 | therefore it works well when executed from tty."
|
| 475 | (define X
|
| 476 | (xorg-wrapper config))
|
| 477 |
|
| 478 | (define exp
|
| 479 | |
| 480 | |
| 481 | (with-imported-modules (source-module-closure '((guix build utils)))
|
| 482 | #~(begin
|
| 483 | (use-modules (guix build utils)
|
| 484 | (ice-9 popen)
|
| 485 | (ice-9 textual-ports))
|
| 486 |
|
| 487 | (define (capture-stdout . prog+args)
|
| 488 | (let* ((port (apply open-pipe* OPEN_READ prog+args))
|
| 489 | (data (get-string-all port)))
|
| 490 | (if (zero? (status:exit-val (close-pipe port)))
|
| 491 | (string-trim-right data #\newline)
|
| 492 | (error "Command failed: " prog+args))))
|
| 493 |
|
| 494 | (define (determine-unused-display n)
|
| 495 | (let ((lock-file (format #f "/tmp/.X~a-lock" n))
|
| 496 | (sock-file (format #f "/tmp/.X11-unix/X~a" n)))
|
| 497 | (if (or (file-exists? lock-file)
|
| 498 | (false-if-exception
|
| 499 | (eq? 'socket (stat:type (stat sock-file)))))
|
| 500 | (determine-unused-display (+ n 1))
|
| 501 | (format #f ":~a" n))))
|
| 502 |
|
| 503 | (define (vty-from-fd0)
|
| 504 | (let ((fd0 (readlink "/proc/self/fd/0"))
|
| 505 | (pref "/dev/tty"))
|
| 506 | (if (string-prefix? pref fd0)
|
| 507 | (substring fd0 (string-length pref))
|
| 508 | (error (format #f "Cannot determine VT from: ~a" fd0)))))
|
| 509 |
|
| 510 | (define (determine-vty)
|
| 511 | (string-append "vt" (or (getenv "XDG_VTNR") (vty-from-fd0))))
|
| 512 |
|
| 513 | (define (enable-xauth server-auth-file display)
|
| 514 | |
| 515 | (or (getenv "XAUTHORITY")
|
| 516 | (setenv "XAUTHORITY" (string-append (getenv "HOME") "/.Xauthority")))
|
| 517 |
|
| 518 | (let* ((bin/xauth #$(file-append xauth "/bin/xauth"))
|
| 519 | (bin/mcookie #$(file-append util-linux "/bin/mcookie"))
|
| 520 | (mcookie (capture-stdout bin/mcookie)))
|
| 521 | (invoke bin/xauth "-qf" server-auth-file
|
| 522 | "add" display "." mcookie)
|
| 523 | (invoke bin/xauth "-q"
|
| 524 | "add" display "." mcookie)))
|
| 525 |
|
| 526 | (let* ((xinit #$(file-append xinit "/bin/xinit"))
|
| 527 | (display (determine-unused-display 0))
|
| 528 | (vty (determine-vty))
|
| 529 | (server-auth-port (mkstemp "/tmp/serverauth.XXXXXX"))
|
| 530 | (server-auth-file (port-filename server-auth-port)))
|
| 531 | (close-port server-auth-port)
|
| 532 | (enable-xauth server-auth-file display)
|
| 533 | (apply execl
|
| 534 | xinit
|
| 535 | xinit
|
| 536 | "--"
|
| 537 | #$X
|
| 538 | display
|
| 539 | vty
|
| 540 | "-keeptty"
|
| 541 | "-auth" server-auth-file
|
| 542 | |
| 543 | |
| 544 | "-logverbose" "-verbose" "-terminate"
|
| 545 | #$@(xorg-configuration-server-arguments config)
|
| 546 | (cdr (command-line)))))))
|
| 547 |
|
| 548 | (program-file "startx" exp))
|
| 549 |
|
| 550 | (define (startx-command-profile-service config)
|
| 551 | |
| 552 | (package
|
| 553 | (name "startx-profile-package")
|
| 554 | (version "0")
|
| 555 | (source (xorg-start-command-xinit config))
|
| 556 | (build-system trivial-build-system)
|
| 557 | (arguments
|
| 558 | (list
|
| 559 | #:modules '((guix build utils))
|
| 560 | #:builder
|
| 561 | #~(begin
|
| 562 | (use-modules (guix build utils))
|
| 563 | (let ((bin (string-append #$output "/bin")))
|
| 564 | (mkdir-p bin)
|
| 565 | (symlink #$source (string-append bin "/startx"))))))
|
| 566 | (home-page #f)
|
| 567 | (synopsis #f)
|
| 568 | (description #f)
|
| 569 | (license #f)))
|
| 570 |
|
| 571 | (define startx-command-service-type
|
| 572 | (service-type
|
| 573 | (name 'startx-command)
|
| 574 | (extensions
|
| 575 | (list (service-extension profile-service-type
|
| 576 | (compose list startx-command-profile-service))))
|
| 577 | (default-value (xorg-configuration))
|
| 578 | (description "Add @command{startx} to the system profile.")))
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 | (define* (xinitrc #:key fallback-session)
|
| 583 | "Return a system-wide xinitrc script that starts the specified X session,
|
| 584 | which should be passed to this script as the first argument. If not, the
|
| 585 | @var{fallback-session} will be used or, if @var{fallback-session} is false, a
|
| 586 | desktop session from the system or user profile will be used."
|
| 587 | (define builder
|
| 588 | #~(begin
|
| 589 | (use-modules (ice-9 match)
|
| 590 | (ice-9 regex)
|
| 591 | (ice-9 ftw)
|
| 592 | (ice-9 rdelim)
|
| 593 | (srfi srfi-1)
|
| 594 | (srfi srfi-26))
|
| 595 |
|
| 596 | (define (close-all-fdes)
|
| 597 | |
| 598 | (let loop ((fd 3))
|
| 599 | (when (< fd 4096) |
| 600 | (false-if-exception (close-fdes fd))
|
| 601 | (loop (+ 1 fd)))))
|
| 602 |
|
| 603 | (define (exec-from-login-shell command . args)
|
| 604 | |
| 605 | |
| 606 | |
| 607 | (let* ((pw (getpw (getuid)))
|
| 608 | (shell (passwd:shell pw)))
|
| 609 | |
| 610 | |
| 611 | |
| 612 | (close-all-fdes)
|
| 613 |
|
| 614 | |
| 615 | (execl shell shell "--login" "-c"
|
| 616 | (string-join (cons command args)))))
|
| 617 |
|
| 618 | (define system-profile
|
| 619 | "/run/current-system/profile")
|
| 620 |
|
| 621 | (define user-profile
|
| 622 | (and=> (getpw (getuid))
|
| 623 | (lambda (pw)
|
| 624 | (string-append (passwd:dir pw) "/.guix-profile"))))
|
| 625 |
|
| 626 | (define (xsession-command desktop-file)
|
| 627 | |
| 628 | |
| 629 | (define exec-regexp
|
| 630 | (make-regexp "^[[:blank:]]*Exec=(.*)$"))
|
| 631 |
|
| 632 | (call-with-input-file desktop-file
|
| 633 | (lambda (port)
|
| 634 | (let loop ()
|
| 635 | (match (read-line port)
|
| 636 | ((? eof-object?) #f)
|
| 637 | ((= (cut regexp-exec exec-regexp <>) result)
|
| 638 | (if result
|
| 639 | (string-tokenize (match:substring result 1))
|
| 640 | (loop))))))))
|
| 641 |
|
| 642 | (define (find-session profile)
|
| 643 | |
| 644 | (let ((directory (string-append profile "/share/xsessions")))
|
| 645 | (match (scandir directory
|
| 646 | (cut string-suffix? ".desktop" <>))
|
| 647 | ((or () #f)
|
| 648 | #f)
|
| 649 | ((sessions ...)
|
| 650 | (any xsession-command
|
| 651 | (map (cut string-append directory "/" <>)
|
| 652 | sessions))))))
|
| 653 |
|
| 654 | (let* ((home (getenv "HOME"))
|
| 655 | (xsession-file (string-append home "/.xsession"))
|
| 656 | (session (match (command-line)
|
| 657 | ((_)
|
| 658 | #$(if fallback-session
|
| 659 | #~(list #$fallback-session)
|
| 660 | #f))
|
| 661 | ((_ x ..1)
|
| 662 | x))))
|
| 663 | (if (file-exists? xsession-file)
|
| 664 | |
| 665 | (apply exec-from-login-shell xsession-file
|
| 666 | (or session '()))
|
| 667 | |
| 668 | (apply exec-from-login-shell
|
| 669 | (or session
|
| 670 | (find-session user-profile)
|
| 671 | (find-session system-profile)))))))
|
| 672 |
|
| 673 | (program-file "xinitrc" builder))
|
| 674 |
|
| 675 | (define-syntax handle-xorg-configuration
|
| 676 | (syntax-rules ()
|
| 677 | "Generate the `compose' and `extend' entries of a login manager
|
| 678 | `service-type' to handle specifying the `xorg-configuration' through
|
| 679 | a `service-extension', as used by `set-xorg-configuration'."
|
| 680 | ((_ configuration-record service-type-definition)
|
| 681 | (service-type
|
| 682 | (inherit service-type-definition)
|
| 683 | (compose cons*)
|
| 684 | (extend (lambda (config xorg-configurations)
|
| 685 | (configuration-record
|
| 686 | (inherit config)
|
| 687 | (xorg-configuration
|
| 688 | (merge-xorg-configurations
|
| 689 | (cons ((record-accessor (record-type-descriptor config)
|
| 690 | 'xorg-configuration)
|
| 691 | config)
|
| 692 | xorg-configurations))))))))))
|
| 693 |
|
| 694 | (define (xorg-server-profile-service config)
|
| 695 | |
| 696 | (list
|
| 697 | (package
|
| 698 | (name "xorg-wrapper")
|
| 699 | (version (package-version xorg-server))
|
| 700 | (source (xorg-wrapper config))
|
| 701 | (build-system trivial-build-system)
|
| 702 | (arguments
|
| 703 | '(#:modules ((guix build utils))
|
| 704 | #:builder
|
| 705 | (begin
|
| 706 | (use-modules (guix build utils))
|
| 707 | (let* ((source (assoc-ref %build-inputs "source"))
|
| 708 | (out (assoc-ref %outputs "out"))
|
| 709 | (bin (string-append out "/bin")))
|
| 710 | (mkdir-p bin)
|
| 711 | (symlink source (string-append bin "/X"))
|
| 712 | (symlink source (string-append bin "/Xorg"))
|
| 713 | #t))))
|
| 714 | (home-page (package-home-page xorg-server))
|
| 715 | (synopsis (package-synopsis xorg-server))
|
| 716 | (description (package-description xorg-server))
|
| 717 | (license (package-license xorg-server)))))
|
| 718 |
|
| 719 | (define xorg-server-service-type
|
| 720 | (service-type
|
| 721 | (name 'xorg-server)
|
| 722 | (extensions
|
| 723 | (list (service-extension profile-service-type
|
| 724 | xorg-server-profile-service)))
|
| 725 | (default-value (xorg-configuration))
|
| 726 | (description "Add @command{X} to the system profile, to be used with
|
| 727 | @command{sx} or @command{xinit}.")))
|
| 728 |
|
| 729 |
|
| 730 | |
| 731 | |
| 732 | |
| 733 |
|
| 734 | (define %default-slim-theme
|
| 735 | |
| 736 | (file-append %artwork-repository "/slim"))
|
| 737 |
|
| 738 | (define %default-slim-theme-name
|
| 739 | |
| 740 | |
| 741 | "1.x")
|
| 742 |
|
| 743 | (define-record-type* <slim-configuration>
|
| 744 | slim-configuration make-slim-configuration
|
| 745 | slim-configuration?
|
| 746 | (slim slim-configuration-slim
|
| 747 | (default slim))
|
| 748 | (allow-empty-passwords? slim-configuration-allow-empty-passwords?
|
| 749 | (default #t))
|
| 750 | (gnupg? slim-configuration-gnupg?
|
| 751 | (default #f))
|
| 752 | (auto-login? slim-configuration-auto-login?
|
| 753 | (default #f))
|
| 754 | (default-user slim-configuration-default-user
|
| 755 | (default ""))
|
| 756 | (theme slim-configuration-theme
|
| 757 | (default %default-slim-theme))
|
| 758 | (theme-name slim-configuration-theme-name
|
| 759 | (default %default-slim-theme-name))
|
| 760 | (xauth slim-configuration-xauth
|
| 761 | (default xauth))
|
| 762 | (shepherd slim-configuration-shepherd
|
| 763 | (default shepherd))
|
| 764 | (auto-login-session slim-configuration-auto-login-session
|
| 765 | (default #f))
|
| 766 | (xorg-configuration slim-configuration-xorg
|
| 767 | (default (xorg-configuration)))
|
| 768 | (display slim-configuration-display
|
| 769 | (default ":0"))
|
| 770 | (vt slim-configuration-vt
|
| 771 | (default "vt7"))
|
| 772 | (sessreg slim-configuration-sessreg
|
| 773 | (default sessreg)))
|
| 774 |
|
| 775 | (define (slim-pam-service config)
|
| 776 | "Return a PAM service for @command{slim}."
|
| 777 | (list (unix-pam-service
|
| 778 | "slim"
|
| 779 | #:login-uid? #t
|
| 780 | #:allow-empty-passwords?
|
| 781 | (slim-configuration-allow-empty-passwords? config)
|
| 782 | #:gnupg?
|
| 783 | (slim-configuration-gnupg? config))))
|
| 784 |
|
| 785 | (define (slim-shepherd-service config)
|
| 786 | (let* ((xinitrc (xinitrc #:fallback-session
|
| 787 | (slim-configuration-auto-login-session config)))
|
| 788 | (xauth (slim-configuration-xauth config))
|
| 789 | (startx (xorg-start-command (slim-configuration-xorg config)))
|
| 790 | (display (slim-configuration-display config))
|
| 791 | (vt (slim-configuration-vt config))
|
| 792 | (shepherd (slim-configuration-shepherd config))
|
| 793 | (theme-name (slim-configuration-theme-name config))
|
| 794 | (sessreg (slim-configuration-sessreg config))
|
| 795 | (lockfile (string-append "/var/run/slim-" vt ".lock")))
|
| 796 | (define slim.cfg
|
| 797 | (mixed-text-file "slim.cfg" "
|
| 798 | default_path /run/current-system/profile/bin
|
| 799 | default_xserver " startx "
|
| 800 | display_name " display "
|
| 801 | xserver_arguments " vt "
|
| 802 | xauth_path " xauth "/bin/xauth
|
| 803 | authfile /var/run/slim-" vt ".auth
|
| 804 | lockfile " lockfile "
|
| 805 | logfile /var/log/slim-" vt ".log
|
| 806 |
|
| 807 | # The login command. '%session' is replaced by the chosen session name, one
|
| 808 | # of the names specified in the 'sessions' setting: 'wmaker', 'xfce', etc.
|
| 809 | login_cmd exec " xinitrc " %session
|
| 810 | sessiondir /run/current-system/profile/share/xsessions
|
| 811 | session_msg session (F1 to change):
|
| 812 | sessionstart_cmd " sessreg "/bin/sessreg -a -l $DISPLAY %user
|
| 813 | sessionstop_cmd " sessreg "/bin/sessreg -d -l $DISPLAY %user
|
| 814 |
|
| 815 | halt_cmd " shepherd "/sbin/halt
|
| 816 | reboot_cmd " shepherd "/sbin/reboot\n"
|
| 817 | (if (slim-configuration-auto-login? config)
|
| 818 | (string-append "auto_login yes\ndefault_user "
|
| 819 | (slim-configuration-default-user config) "\n")
|
| 820 | "")
|
| 821 | (if theme-name
|
| 822 | (string-append "current_theme " theme-name "\n")
|
| 823 | "")))
|
| 824 |
|
| 825 | (define theme
|
| 826 | (slim-configuration-theme config))
|
| 827 |
|
| 828 | (list (shepherd-service
|
| 829 | (documentation "Xorg display server")
|
| 830 | (provision (append
|
| 831 | |
| 832 | (if (string=? vt "vt7")
|
| 833 | '(xorg-server)
|
| 834 | '())
|
| 835 |
|
| 836 | (list (symbol-append 'xorg-server-
|
| 837 | (string->symbol vt)))))
|
| 838 | (requirement '(pam user-processes host-name udev))
|
| 839 | (start
|
| 840 | #~(lambda ()
|
| 841 | |
| 842 | |
| 843 | (false-if-exception (delete-file lockfile))
|
| 844 |
|
| 845 | (fork+exec-command
|
| 846 | (list (string-append #$(slim-configuration-slim config)
|
| 847 | "/bin/slim")
|
| 848 | "-nodaemon")
|
| 849 | #:environment-variables
|
| 850 | (list (string-append "SLIM_CFGFILE=" #$slim.cfg)
|
| 851 | #$@(if theme
|
| 852 | (list #~(string-append "SLIM_THEMESDIR=" #$theme))
|
| 853 | #~())))))
|
| 854 | (stop #~(make-kill-destructor))
|
| 855 | (respawn? #t)))))
|
| 856 |
|
| 857 | (define slim-service-type
|
| 858 | (handle-xorg-configuration slim-configuration
|
| 859 | (service-type (name 'slim)
|
| 860 | (extensions
|
| 861 | (list (service-extension shepherd-root-service-type
|
| 862 | slim-shepherd-service)
|
| 863 | (service-extension pam-root-service-type
|
| 864 | slim-pam-service)))
|
| 865 | (default-value (slim-configuration))
|
| 866 | (description
|
| 867 | "Run the SLiM graphical login manager for X11."))))
|
| 868 |
|
| 869 |
|
| 870 | |
| 871 | |
| 872 | |
| 873 |
|
| 874 | (define-configuration/no-serialization screen-locker-configuration
|
| 875 | (name
|
| 876 | string
|
| 877 | "Name of the screen locker.")
|
| 878 | (program
|
| 879 | file-like
|
| 880 | "Path to the executable for the screen locker as a G-Expression.")
|
| 881 | (allow-empty-password?
|
| 882 | (boolean #f)
|
| 883 | "Whether to allow empty passwords.")
|
| 884 | (using-pam?
|
| 885 | (boolean #t)
|
| 886 | "Whether to setup PAM entry.")
|
| 887 | (using-setuid?
|
| 888 | (boolean #t)
|
| 889 | "Whether to setup program as setuid binary."))
|
| 890 |
|
| 891 | (define (screen-locker-pam-services config)
|
| 892 | (match-record config <screen-locker-configuration>
|
| 893 | (name allow-empty-password? using-pam?)
|
| 894 | (if using-pam?
|
| 895 | (list (unix-pam-service name
|
| 896 | #:allow-empty-passwords?
|
| 897 | allow-empty-password?))
|
| 898 | '())))
|
| 899 |
|
| 900 | (define (screen-locker-privileged-programs config)
|
| 901 | (match-record config <screen-locker-configuration>
|
| 902 | (name program using-setuid?)
|
| 903 | (if using-setuid?
|
| 904 | (list (privileged-program
|
| 905 | (program program)
|
| 906 | (setuid? #t)))
|
| 907 | '())))
|
| 908 |
|
| 909 | (define screen-locker-service-type
|
| 910 | (service-type (name 'screen-locker)
|
| 911 | (extensions
|
| 912 | (list (service-extension pam-root-service-type
|
| 913 | screen-locker-pam-services)
|
| 914 | (service-extension privileged-program-service-type
|
| 915 | screen-locker-privileged-programs)))
|
| 916 | (description
|
| 917 | "Allow the given program to be used as a screen locker for
|
| 918 | the graphical server by making it setuid-root, so it can authenticate users,
|
| 919 | and by creating a PAM service for it.")))
|
| 920 |
|
| 921 | (define (screen-locker-generate-doc)
|
| 922 | (configuration->documentation 'screen-locker-configuration))
|
| 923 |
|
| 924 | (define-deprecated (screen-locker-service package
|
| 925 | #:optional
|
| 926 | (program (package-name package))
|
| 927 | #:key allow-empty-passwords?)
|
| 928 | screen-locker-service-type
|
| 929 | "Add @var{package}, a package for a screen locker or screen saver whose
|
| 930 | command is @var{program}, to the set of setuid programs and add a PAM entry
|
| 931 | for it. For example:
|
| 932 |
|
| 933 | @lisp
|
| 934 | (screen-locker-service xlockmore \"xlock\")
|
| 935 | @end lisp
|
| 936 |
|
| 937 | makes the good ol' XlockMore usable."
|
| 938 | (service screen-locker-service-type
|
| 939 | (screen-locker-configuration
|
| 940 | (name program)
|
| 941 | (program (file-append package "/bin/" program))
|
| 942 | (allow-empty-password? allow-empty-passwords?))))
|
| 943 |
|
| 944 |
|
| 945 | |
| 946 | |
| 947 | |
| 948 |
|
| 949 | (define-record-type* <localed-configuration>
|
| 950 | localed-configuration make-localed-configuration
|
| 951 | localed-configuration?
|
| 952 | (localed localed-configuration-localed
|
| 953 | (default localed))
|
| 954 | (keyboard-layout localed-configuration-keyboard-layout
|
| 955 | (default #f)))
|
| 956 |
|
| 957 | (define (localed-dbus-service config)
|
| 958 | "Return the 'localed' D-Bus service for @var{config}, a
|
| 959 | @code{<localed-configuration>} record."
|
| 960 | (define keyboard-layout
|
| 961 | (localed-configuration-keyboard-layout config))
|
| 962 |
|
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | |
| 968 |
|
| 969 | (if keyboard-layout
|
| 970 | (let* ((layout (keyboard-layout-name keyboard-layout))
|
| 971 | (variant (keyboard-layout-variant keyboard-layout))
|
| 972 | (model (keyboard-layout-model keyboard-layout))
|
| 973 | (options (keyboard-layout-options keyboard-layout)))
|
| 974 | (list (wrapped-dbus-service
|
| 975 | (localed-configuration-localed config)
|
| 976 | "libexec/localed/localed"
|
| 977 | `(("GUIX_XKB_LAYOUT" ,layout)
|
| 978 | ,@(if variant
|
| 979 | `(("GUIX_XKB_VARIANT" ,variant))
|
| 980 | '())
|
| 981 | ,@(if model
|
| 982 | `(("GUIX_XKB_MODEL" ,model))
|
| 983 | '())
|
| 984 | ,@(if (null? options)
|
| 985 | '()
|
| 986 | `(("GUIX_XKB_OPTIONS"
|
| 987 | ,(string-join options ","))))))))
|
| 988 | '()))
|
| 989 |
|
| 990 | (define localed-service-type
|
| 991 | (let ((package (lambda (config)
|
| 992 | |
| 993 | |
| 994 | (if (localed-configuration-keyboard-layout config)
|
| 995 | (list (localed-configuration-localed config))
|
| 996 | '()))))
|
| 997 | (service-type (name 'localed)
|
| 998 | (extensions
|
| 999 | (list (service-extension dbus-root-service-type
|
| 1000 | localed-dbus-service)
|
| 1001 | (service-extension udev-service-type package)
|
| 1002 | (service-extension polkit-service-type package)
|
| 1003 |
|
| 1004 | |
| 1005 | (service-extension profile-service-type package)))
|
| 1006 |
|
| 1007 | |
| 1008 | |
| 1009 | (compose (lambda (extensions)
|
| 1010 | (find keyboard-layout? extensions)))
|
| 1011 | (extend (lambda (config keyboard-layout)
|
| 1012 | (localed-configuration
|
| 1013 | (inherit config)
|
| 1014 | (keyboard-layout keyboard-layout))))
|
| 1015 | (description
|
| 1016 | "Run the locale daemon, @command{localed}, which can be used
|
| 1017 | to control the system locale and keyboard mapping from user programs such as
|
| 1018 | the GNOME desktop environment.")
|
| 1019 | (default-value (localed-configuration)))))
|
| 1020 |
|
| 1021 |
|
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 |
|
| 1026 | (define-maybe text-config)
|
| 1027 |
|
| 1028 | (define-configuration/no-serialization dconf-keyfile
|
| 1029 | (name string
|
| 1030 | "The file name of the associated keyfile, e.g. \"00-login-screen\".")
|
| 1031 | (content text-config "The content of the associated keyfile."))
|
| 1032 |
|
| 1033 | (define-configuration/no-serialization dconf-profile
|
| 1034 | (name string "The file name of the dconf system profile, which should match
|
| 1035 | the name of a user for which the profile is to be used with. To have the
|
| 1036 | profile used, the environment variable \"DCONF_PROFILE\" should be set to the
|
| 1037 | profile file, e.g.:
|
| 1038 | @example
|
| 1039 | export DCONF_PROFILE=/etc/dconf/profile/gdm
|
| 1040 | @end example")
|
| 1041 | (content maybe-text-config "The content of the Dconf profile. Unless
|
| 1042 | provided, it defaults to include the user database (\"user-db:NAME\") as well
|
| 1043 | as the system database (\"system-db:NAME\"), which corresponds to the
|
| 1044 | generated database, @file{/etc/dconf/db/NAME}.")
|
| 1045 | (keyfile dconf-keyfile "The keyfile associated with the profile"))
|
| 1046 |
|
| 1047 | (define dconf-profiles?
|
| 1048 | (list-of dconf-profile?))
|
| 1049 |
|
| 1050 | (define-configuration/no-serialization dconf-configuration
|
| 1051 | (profiles dconf-profiles "The list of <dconf-profile> objects to populate."))
|
| 1052 |
|
| 1053 | (define (dconf-profile->profile-file profile)
|
| 1054 | "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
|
| 1055 | (let ((name (dconf-profile-name profile))
|
| 1056 | (content (dconf-profile-content profile)))
|
| 1057 | (apply mixed-text-file
|
| 1058 | name
|
| 1059 | (if (maybe-value-set? content)
|
| 1060 | (interpose content "\n" 'suffix)
|
| 1061 | (interpose (list (string-append "user-db:" name)
|
| 1062 | (string-append "system-db:" name))
|
| 1063 | "\n" 'suffix)))))
|
| 1064 |
|
| 1065 | (define (dconf-profile->db-keyfile profile)
|
| 1066 | "Given PROFILE, a <dconf-profile> object, return a dconf profile file."
|
| 1067 | (let ((keyfile (dconf-profile-keyfile profile)))
|
| 1068 | (apply mixed-text-file (dconf-keyfile-name keyfile)
|
| 1069 | (interpose (dconf-keyfile-content keyfile) "\n" 'suffix))))
|
| 1070 |
|
| 1071 | (define (dconf-profile->db-keyfile-dir profile)
|
| 1072 | "Wrap the keyfile in a directory, to satisfy 'dconf compile'."
|
| 1073 | (let ((name (dconf-profile-name profile))
|
| 1074 | (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
|
| 1075 | (computed-file name
|
| 1076 | #~(begin
|
| 1077 | (mkdir #$output)
|
| 1078 | (symlink #$(dconf-profile->db-keyfile profile)
|
| 1079 | (string-append #$output "/" #$keyfile-name))))))
|
| 1080 |
|
| 1081 | (define (dconf-profile->db profile)
|
| 1082 | "Compile the a <dconf-profile> object into a GVariant Database file."
|
| 1083 | (let ((name (dconf-profile-name profile)))
|
| 1084 | (computed-file
|
| 1085 | name
|
| 1086 | (with-imported-modules '((guix build utils))
|
| 1087 | #~(begin
|
| 1088 | (use-modules (guix build utils))
|
| 1089 | (setenv "DCONF_PROFILE" #$(dconf-profile->profile-file profile))
|
| 1090 | (invoke #$(file-append dconf "/bin/dconf") "compile"
|
| 1091 | #$output #$(dconf-profile->db-keyfile-dir profile)))))))
|
| 1092 |
|
| 1093 | (define (dconf-profile->files profile)
|
| 1094 | "Given PROFILE, a <dconf-profile> object, return a dconf directory
|
| 1095 | containing the associated profile, keyfile and database files to be assembled
|
| 1096 | under /etc."
|
| 1097 | (let ((name (dconf-profile-name profile))
|
| 1098 | (keyfile-name (dconf-keyfile-name (dconf-profile-keyfile profile))))
|
| 1099 | (list (list (string-append "dconf/profile/" name)
|
| 1100 | (dconf-profile->profile-file profile))
|
| 1101 | (list (string-append "dconf/db/" name ".d/" keyfile-name)
|
| 1102 | (dconf-profile->db-keyfile profile))
|
| 1103 | (list (string-append "dconf/db/" name)
|
| 1104 | (dconf-profile->db profile)))))
|
| 1105 |
|
| 1106 | (define dconf-service-type
|
| 1107 | (service-type
|
| 1108 | (name 'dconf-profile)
|
| 1109 | (extensions
|
| 1110 | (list (service-extension etc-service-type
|
| 1111 | (lambda (dconf-profiles)
|
| 1112 | (append-map dconf-profile->files
|
| 1113 | dconf-profiles)))))
|
| 1114 | (compose concatenate)
|
| 1115 | (extend append)
|
| 1116 | (default-value '())
|
| 1117 | (description "Extend the @code{etc-service-type} to populate the file
|
| 1118 | hierarchy under @file{/etc/dconf} with the <dconf-profile> objects provided as
|
| 1119 | argument.")))
|
| 1120 |
|
| 1121 |
|
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 |
|
| 1126 | (define %gdm-accounts
|
| 1127 | (list (user-group (name "gdm") (system? #t))
|
| 1128 | (user-account
|
| 1129 | (name "gdm")
|
| 1130 | (group "gdm")
|
| 1131 | (supplementary-groups '("video"))
|
| 1132 | (system? #t)
|
| 1133 | (comment "GNOME Display Manager user")
|
| 1134 | (home-directory "/var/lib/gdm")
|
| 1135 | (shell (file-append shadow "/sbin/nologin")))
|
| 1136 | |
| 1137 | |
| 1138 | (user-account
|
| 1139 | (name "gdm-greeter")
|
| 1140 | (group "gdm")
|
| 1141 | (supplementary-groups '("video"))
|
| 1142 | (system? #t)
|
| 1143 | (comment "GNOME Display Manager greeter 1")
|
| 1144 | (home-directory "/var/lib/gdm-greeter"))))
|
| 1145 |
|
| 1146 | (define dbus-daemon-wrapper
|
| 1147 | (program-file
|
| 1148 | "gdm-dbus-wrapper"
|
| 1149 | #~(begin
|
| 1150 | (use-modules (srfi srfi-26))
|
| 1151 |
|
| 1152 | (define system-profile
|
| 1153 | "/run/current-system/profile")
|
| 1154 |
|
| 1155 | (define user-profile
|
| 1156 | (and=> (getpw (getuid))
|
| 1157 | (lambda (pw)
|
| 1158 | (string-append (passwd:dir pw) "/.guix-profile"))))
|
| 1159 |
|
| 1160 | (define home-profile
|
| 1161 | (and=> (getpw (getuid))
|
| 1162 | (lambda (pw)
|
| 1163 | (string-append (passwd:dir pw) "/.guix-home/profile"))))
|
| 1164 |
|
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | (define profiles
|
| 1172 | (append (if home-profile
|
| 1173 | (list home-profile)
|
| 1174 | '())
|
| 1175 | (if user-profile
|
| 1176 | (list user-profile)
|
| 1177 | '())
|
| 1178 | (list system-profile)))
|
| 1179 |
|
| 1180 | (setenv "XDG_CONFIG_DIRS"
|
| 1181 | (string-join (map (cut string-append <> "/etc/xdg") profiles)
|
| 1182 | ":"))
|
| 1183 | (setenv "XDG_DATA_DIRS"
|
| 1184 | (string-join (map (cut string-append <> "/share") profiles)
|
| 1185 | ":"))
|
| 1186 | (apply execl (string-append #$dbus "/bin/dbus-daemon")
|
| 1187 | (program-arguments)))))
|
| 1188 |
|
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | (define gdm-wayland-session-wrapper
|
| 1197 | (program-file
|
| 1198 | "gdm-wayland-session-wrapper"
|
| 1199 | #~((let* ((user (getpw (getuid)))
|
| 1200 | (name (passwd:name user))
|
| 1201 | (shell (passwd:shell user))
|
| 1202 | (args (cdr (command-line))))
|
| 1203 | (if (string=? name "gdm")
|
| 1204 | (apply execl (cons (car args) args))
|
| 1205 | (execl shell shell "--login" "-c" (string-join args)))))))
|
| 1206 |
|
| 1207 | (define-with-syntax-properties
|
| 1208 | (gdm-xdmcp-sanitizer (value properties))
|
| 1209 | (when value
|
| 1210 | (warning (source-properties->location properties)
|
| 1211 | (G_ "the `xdmcp?' field is deprecated and has no effect~%"))
|
| 1212 | (display-hint (G_ "Do not use the xdmcp? field."))
|
| 1213 | #f))
|
| 1214 |
|
| 1215 | (define-record-type* <gdm-configuration>
|
| 1216 | gdm-configuration make-gdm-configuration
|
| 1217 | gdm-configuration?
|
| 1218 | (gdm gdm-configuration-gdm (default gdm))
|
| 1219 | (allow-empty-passwords? gdm-configuration-allow-empty-passwords? (default #t))
|
| 1220 | (auto-login? gdm-configuration-auto-login? (default #f))
|
| 1221 | (auto-suspend? gdm-configuration-auto-suspend? (default #t))
|
| 1222 | (dbus-daemon gdm-configuration-dbus-daemon (default dbus-daemon-wrapper))
|
| 1223 | (debug? gdm-configuration-debug? (default #f))
|
| 1224 | (default-user gdm-configuration-default-user (default #f))
|
| 1225 | (gnome-shell-assets gdm-configuration-gnome-shell-assets
|
| 1226 | (default (list adwaita-icon-theme font-abattis-cantarell)))
|
| 1227 | (xorg-configuration gdm-configuration-xorg
|
| 1228 | (default (xorg-configuration)))
|
| 1229 | (x-session gdm-configuration-x-session
|
| 1230 | (default (xinitrc)))
|
| 1231 | |
| 1232 | (xdmcp? gdm-configuration-xdmcp?
|
| 1233 | (default #f)
|
| 1234 | (sanitizer gdm-xdmcp-sanitizer))
|
| 1235 | (wayland? gdm-configuration-wayland? (default #t))
|
| 1236 | (wayland-session gdm-configuration-wayland-session
|
| 1237 | (default gdm-wayland-session-wrapper)))
|
| 1238 |
|
| 1239 | (define (gdm-dconf-profiles config)
|
| 1240 | (if (gdm-configuration-auto-suspend? config)
|
| 1241 | '()
|
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | (list (dconf-profile
|
| 1246 | (name "gdm")
|
| 1247 | (content (list #~(begin
|
| 1248 | (use-modules (ice-9 textual-ports))
|
| 1249 | (string-trim
|
| 1250 | (call-with-input-file
|
| 1251 | #$(file-append gdm "/share/dconf/profile/gdm")
|
| 1252 | get-string-all)))
|
| 1253 | "system-db:gdm"))
|
| 1254 | (keyfile (dconf-keyfile
|
| 1255 | (name "00-disable-suspend")
|
| 1256 | (content
|
| 1257 | (list "[org/gnome/settings-daemon/plugins/power]"
|
| 1258 | "sleep-inactive-ac-type='nothing'"
|
| 1259 | "sleep-inactive-battery-type='nothing'"
|
| 1260 | "sleep-inactive-ac-timeout=0"
|
| 1261 | "sleep-inactive-battery-timeout=0"))))))))
|
| 1262 |
|
| 1263 | (define (gdm-configuration-file config)
|
| 1264 | (mixed-text-file "gdm-custom.conf"
|
| 1265 | "[daemon]\n"
|
| 1266 | "#User=gdm\n"
|
| 1267 | "#Group=gdm\n"
|
| 1268 | (if (gdm-configuration-auto-login? config)
|
| 1269 | (string-append
|
| 1270 | "AutomaticLoginEnable=true\n"
|
| 1271 | "AutomaticLogin="
|
| 1272 | (or (gdm-configuration-default-user config)
|
| 1273 | (error "missing default user for auto-login"))
|
| 1274 | "\n")
|
| 1275 | (string-append
|
| 1276 | "AutomaticLoginEnable=false\n"
|
| 1277 | "#AutomaticLogin=\n"))
|
| 1278 | "#TimedLoginEnable=false\n"
|
| 1279 | "#TimedLogin=\n"
|
| 1280 | "#TimedLoginDelay=0\n"
|
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | "InitialSetupEnable=false\n"
|
| 1287 | (format #f "WaylandEnable=~:[false~;true~]~%"
|
| 1288 | (gdm-configuration-wayland? config))
|
| 1289 | "\n"
|
| 1290 | "[debug]\n"
|
| 1291 | (format #f "Enable=~:[false~;true~]~%"
|
| 1292 | (gdm-configuration-debug? config))
|
| 1293 | "\n"
|
| 1294 | "[security]\n"
|
| 1295 | "#DisallowTCP=true\n"
|
| 1296 | "#AllowRemoteAutoLogin=false\n"))
|
| 1297 |
|
| 1298 | (define (gdm-pam-service config)
|
| 1299 | "Return a PAM service for @command{gdm}."
|
| 1300 | (list
|
| 1301 | (pam-service
|
| 1302 | (inherit (unix-pam-service "gdm-autologin"
|
| 1303 | #:login-uid? #t))
|
| 1304 | (auth (list (pam-entry
|
| 1305 | (control "optional")
|
| 1306 | (module (file-append (gdm-configuration-gdm config)
|
| 1307 | "/lib/security/pam_gdm.so")))
|
| 1308 | (pam-entry
|
| 1309 | (control "sufficient")
|
| 1310 | (module "pam_permit.so")))))
|
| 1311 | (pam-service
|
| 1312 | (inherit (unix-pam-service "gdm-launch-environment"))
|
| 1313 | (auth (list (pam-entry
|
| 1314 | (control "required")
|
| 1315 | (module "pam_permit.so")))))
|
| 1316 | (unix-pam-service "gdm-password"
|
| 1317 | #:login-uid? #t
|
| 1318 | #:allow-empty-passwords?
|
| 1319 | (gdm-configuration-allow-empty-passwords? config))))
|
| 1320 |
|
| 1321 | (define (gdm-shepherd-service config)
|
| 1322 | (define config-file
|
| 1323 | (gdm-configuration-file config))
|
| 1324 |
|
| 1325 | (list (shepherd-service
|
| 1326 | (documentation "Xorg display server (GDM)")
|
| 1327 | (provision '(xorg-server))
|
| 1328 | (requirement '(dbus-system pam user-processes host-name udev elogind))
|
| 1329 | (start #~(make-forkexec-constructor
|
| 1330 | '(#$(file-append (gdm-configuration-gdm config) "/bin/gdm"))
|
| 1331 | #:environment-variables
|
| 1332 | (list #$@(if (gdm-configuration-auto-suspend? config)
|
| 1333 | #~()
|
| 1334 | #~("DCONF_PROFILE=/etc/dconf/profile/gdm"))
|
| 1335 | (string-append "GDM_CUSTOM_CONF=" #$config-file)
|
| 1336 | (string-append
|
| 1337 | "GDM_DBUS_DAEMON="
|
| 1338 | #$(gdm-configuration-dbus-daemon config))
|
| 1339 | (string-append
|
| 1340 | "GDM_X_SERVER="
|
| 1341 | #$(xorg-wrapper
|
| 1342 | (gdm-configuration-xorg config)))
|
| 1343 | (string-append
|
| 1344 | "GDM_X_SESSION="
|
| 1345 | #$(gdm-configuration-x-session config))
|
| 1346 | (string-append
|
| 1347 | "XDG_DATA_DIRS="
|
| 1348 | ((lambda (ls) (string-join ls ":"))
|
| 1349 | (map (lambda (path)
|
| 1350 | (string-append path "/share"))
|
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | (cons* "/run/current-system/profile"
|
| 1356 | #$gnome-shell
|
| 1357 | '#$(gdm-configuration-gnome-shell-assets
|
| 1358 | config)))))
|
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | "XCURSOR_PATH=/run/current-system/profile/share/icons"
|
| 1363 | (string-append
|
| 1364 | "GUIX_GDK_PIXBUF_MODULE_FILES="
|
| 1365 | #$gnome-shell "/" #$%gdk-pixbuf-loaders-cache-file)
|
| 1366 | (string-append
|
| 1367 | "GDM_WAYLAND_SESSION="
|
| 1368 | #$(gdm-configuration-wayland-session config)))))
|
| 1369 | (stop #~(make-kill-destructor))
|
| 1370 | (actions (list (shepherd-configuration-action config-file)))
|
| 1371 | (respawn? #t))))
|
| 1372 |
|
| 1373 | (define gdm-polkit-rules
|
| 1374 | (lambda (config)
|
| 1375 | (if (gdm-configuration-xdmcp? config)
|
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | (list (computed-file
|
| 1381 | "02-allow-colord.rules"
|
| 1382 | (with-imported-modules '((guix build utils))
|
| 1383 | #~(begin
|
| 1384 | (use-modules (guix build utils))
|
| 1385 |
|
| 1386 | (let* ((rules.d
|
| 1387 | (string-append #$output
|
| 1388 | "/share/polkit-1"
|
| 1389 | "/rules.d"))
|
| 1390 | (allow-colord.rules (string-append
|
| 1391 | rules.d
|
| 1392 | "/02-allow-colord.rules")))
|
| 1393 | (mkdir-p rules.d)
|
| 1394 | (call-with-output-file allow-colord.rules
|
| 1395 | (lambda (port)
|
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | (format port "\
|
| 1400 | polkit.addRule(function(action, subject) {
|
| 1401 | if (action.id.match(\"org.freedesktop.color-manager\")) {
|
| 1402 | polkit.log(\"POLKIT DEBUG returning YES for action: \" + action);
|
| 1403 | return polkit.Result.YES;
|
| 1404 | }
|
| 1405 | });~%"))))))))
|
| 1406 | '())))
|
| 1407 |
|
| 1408 | (define (gdm-profile config)
|
| 1409 | (cons gnome-shell
|
| 1410 | (gdm-configuration-gnome-shell-assets config)))
|
| 1411 |
|
| 1412 | (define gdm-service-type
|
| 1413 | (handle-xorg-configuration gdm-configuration
|
| 1414 | (service-type (name 'gdm)
|
| 1415 | (extensions
|
| 1416 | (list (service-extension shepherd-root-service-type
|
| 1417 | gdm-shepherd-service)
|
| 1418 | (service-extension account-service-type
|
| 1419 | (const %gdm-accounts))
|
| 1420 | (service-extension dconf-service-type
|
| 1421 | gdm-dconf-profiles)
|
| 1422 | (service-extension pam-root-service-type
|
| 1423 | gdm-pam-service)
|
| 1424 | (service-extension polkit-service-type
|
| 1425 | gdm-polkit-rules)
|
| 1426 | (service-extension profile-service-type
|
| 1427 | gdm-profile)
|
| 1428 | (service-extension dbus-root-service-type
|
| 1429 | (compose list
|
| 1430 | gdm-configuration-gdm))
|
| 1431 | (service-extension localed-service-type
|
| 1432 | (compose
|
| 1433 | xorg-configuration-keyboard-layout
|
| 1434 | gdm-configuration-xorg))))
|
| 1435 | (default-value (gdm-configuration))
|
| 1436 | (description
|
| 1437 | "Run the GNOME Desktop Manager (GDM), a program that allows
|
| 1438 | you to log in in a graphical session, whether or not you use GNOME."))))
|
| 1439 |
|
| 1440 |
|
| 1441 | |
| 1442 | |
| 1443 | |
| 1444 | (define* (set-xorg-configuration config
|
| 1445 | #:optional
|
| 1446 | (login-manager-service-type
|
| 1447 | (if (target-64bit?)
|
| 1448 | gdm-service-type
|
| 1449 | sddm-service-type)))
|
| 1450 | "Tell the log-in manager (of type @var{login-manager-service-type}) to use
|
| 1451 | @var{config}, an <xorg-configuration> record."
|
| 1452 | (simple-service 'set-xorg-configuration
|
| 1453 | login-manager-service-type
|
| 1454 | config))
|
| 1455 |
|
| 1456 | |