summaryrefslogtreecommitdiff
path: root/gnu/home/services
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/home/services')
-rw-r--r--gnu/home/services/desktop.scm109
-rw-r--r--gnu/home/services/fontutils.scm5
-rw-r--r--gnu/home/services/shells.scm8
-rw-r--r--gnu/home/services/shepherd.scm12
-rw-r--r--gnu/home/services/sound.scm102
-rw-r--r--gnu/home/services/ssh.scm8
6 files changed, 214 insertions, 30 deletions
diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
index c4da116100..91465bf168 100644
--- a/gnu/home/services/desktop.scm
+++ b/gnu/home/services/desktop.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022-2023 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2022 ( <paren@disroot.org>
;;; Copyright © 2023 conses <contact@conses.eu>
;;; Copyright © 2023 Janneke Nieuwenhuizen <janneke@gnu.org>
@@ -30,7 +30,9 @@
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
- #:export (home-redshift-configuration
+ #:export (home-x11-service-type
+
+ home-redshift-configuration
home-redshift-configuration?
home-redshift-service-type
@@ -45,6 +47,79 @@
;;;
+;;; Waiting for X11.
+;;;
+
+(define (x11-shepherd-service delay)
+ (list (shepherd-service
+ (provision '(x11-display))
+ (modules '((ice-9 ftw)
+ (ice-9 match)
+ (srfi srfi-1)))
+ (start
+ #~(lambda* (#:optional (display (getenv "DISPLAY")))
+ (define x11-directory
+ "/tmp/.X11-unix")
+
+ (define (find-display delay)
+ ;; Wait for an accessible socket to show up in X11-DIRECTORY,
+ ;; up to DELAY seconds.
+ (let loop ((attempts delay))
+ (define socket
+ (find (match-lambda
+ ((or "." "..") #f)
+ (name
+ (let ((name (in-vicinity x11-directory
+ name)))
+ (access? name O_RDWR))))
+ (or (scandir x11-directory) '())))
+
+ (if (and socket (string-prefix? "X" socket))
+ (let ((display (string-append
+ ":" (string-drop socket 1))))
+ (format #t "X11 display server found at ~s.~%"
+ display)
+ display)
+ (if (zero? attempts)
+ (begin
+ (format (current-error-port)
+ "X11 display server did not show up; \
+giving up.\n")
+ #f)
+ (begin
+ (sleep 1)
+ (loop (- attempts 1)))))))
+
+ (let ((display (or display (find-display #$delay))))
+ (when display
+ ;; Note: 'make-forkexec-constructor' calls take their
+ ;; default #:environment-variables value before this service
+ ;; is started and are thus unaffected by the 'setenv' call
+ ;; below. Users of this service have to explicitly query
+ ;; its value.
+ (setenv "DISPLAY" display))
+ display)))
+ (stop #~(lambda (_)
+ (unsetenv "DISPLAY")
+ #f))
+ (respawn? #f))))
+
+(define home-x11-service-type
+ (service-type
+ (name 'home-x11-display)
+ (extensions (list (service-extension home-shepherd-service-type
+ x11-shepherd-service)))
+ (default-value 10)
+ (description
+ "Create a @code{x11-display} Shepherd service that waits for the X
+Window (or ``X11'') graphical display server to be up and running, up to a
+configurable delay, and sets the @code{DISPLAY} environment variable of
+@command{shepherd} itself accordingly. If no accessible X11 server shows up
+during that time, the @code{x11-display} service is marked as failing to
+start.")))
+
+
+;;;
;;; Redshift.
;;;
@@ -169,11 +244,25 @@ format."))
(list (shepherd-service
(documentation "Redshift program.")
(provision '(redshift))
- ;; FIXME: This fails to start if Home is first activated from a
- ;; non-X11 session.
- (start #~(make-forkexec-constructor
- (list #$(file-append (home-redshift-configuration-redshift config) "/bin/redshift")
- "-c" #$config-file)))
+
+ ;; Depend on 'x11-display', which sets 'DISPLAY' if an X11 server is
+ ;; available, and fails to start otherwise.
+ (requirement '(x11-display))
+
+ (modules '((srfi srfi-1)
+ (srfi srfi-26)))
+ (start #~(lambda _
+ (fork+exec-command
+ (list #$(file-append
+ (home-redshift-configuration-redshift config)
+ "/bin/redshift")
+ "-c" #$config-file)
+
+ ;; Inherit the 'DISPLAY' variable set by 'x11-display'.
+ #:environment-variables
+ (cons (string-append "DISPLAY=" (getenv "DISPLAY"))
+ (remove (cut string-prefix? "DISPLAY=" <>)
+ (default-environment-variables))))))
(stop #~(make-kill-destructor))
(actions (list (shepherd-configuration-action config-file))))))
@@ -181,7 +270,11 @@ format."))
(service-type
(name 'home-redshift)
(extensions (list (service-extension home-shepherd-service-type
- redshift-shepherd-service)))
+ redshift-shepherd-service)
+ ;; Ensure 'home-x11-service-type' is instantiated so we
+ ;; can depend on the Shepherd 'x11-display' service.
+ (service-extension home-x11-service-type
+ (const #t))))
(default-value (home-redshift-configuration))
(description
"Run Redshift, a program that adjusts the color temperature of display
diff --git a/gnu/home/services/fontutils.scm b/gnu/home/services/fontutils.scm
index 0e60bc2035..0090d53985 100644
--- a/gnu/home/services/fontutils.scm
+++ b/gnu/home/services/fontutils.scm
@@ -81,10 +81,7 @@ of fontconfig's fonts.conf file."
add-fontconfig-config-file)
(service-extension
home-run-on-change-service-type
- regenerate-font-cache-gexp)
- (service-extension
- home-profile-service-type
- (const (list fontconfig)))))
+ regenerate-font-cache-gexp)))
(compose concatenate)
(extend append)
(default-value '("~/.guix-home/profile/share/fonts"))
diff --git a/gnu/home/services/shells.scm b/gnu/home/services/shells.scm
index 9dd56f634a..db82a7cff3 100644
--- a/gnu/home/services/shells.scm
+++ b/gnu/home/services/shells.scm
@@ -20,7 +20,7 @@
(define-module (gnu home services shells)
#:use-module (gnu services configuration)
- #:autoload (gnu system shadow) (%default-bashrc)
+ #:autoload (gnu system shadow) (%default-bashrc %default-zprofile)
#:use-module (gnu home services utils)
#:use-module (gnu home services)
#:use-module (gnu packages shells)
@@ -189,12 +189,8 @@ another process for example)."))
(define (zsh-file-zprofile config)
(mixed-text-file
"zprofile"
+ (plain-file-content %default-zprofile)
"\
-# Set up the system, user profile, and related variables.
-source /etc/profile
-# Set up the home environment profile.
-source ~/.profile
-
# It's only necessary if zsh is a login shell, otherwise profiles will
# be already sourced by bash
"
diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
index bd068c37fc..176f4575cb 100644
--- a/gnu/home/services/shepherd.scm
+++ b/gnu/home/services/shepherd.scm
@@ -1,6 +1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2021, 2023 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
+;;; Copyright © 2024 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -75,11 +76,8 @@ as shepherd package."
#~(begin
(use-modules (srfi srfi-34)
(system repl error-handling))
- (apply
- register-services
- (map
- (lambda (file) (load file))
- '#$files))
+
+ (register-services (map load '#$files))
#$@(if daemonize?
`((action 'root 'daemonize))
@@ -90,9 +88,7 @@ as shepherd package."
'#$(append-map shepherd-service-provision
(filter shepherd-service-auto-start?
services))))
- (if (defined? 'start-in-the-background)
- (start-in-the-background services-to-start)
- (for-each start services-to-start))
+ (start-in-the-background services-to-start)
(redirect-port (open-input-file "/dev/null")
(current-input-port)))))
diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm
index 22c1a99250..313a57305b 100644
--- a/gnu/home/services/sound.scm
+++ b/gnu/home/services/sound.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -19,13 +20,112 @@
(define-module (gnu home services sound)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
+ #:use-module (gnu home services xdg)
+ #:use-module (gnu packages linux)
+ #:use-module (gnu services configuration)
#:use-module (guix records)
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (home-pulseaudio-rtp-sink-service-type
home-pulseaudio-rtp-source-service-type
- %pulseaudio-rtp-multicast-address))
+ %pulseaudio-rtp-multicast-address
+
+ home-pipewire-configuration
+ home-pipewire-service-type))
+
+
+;;;
+;;; PipeWire support.
+;;;
+
+(define-configuration/no-serialization home-pipewire-configuration
+ (pipewire
+ (file-like pipewire)
+ "The PipeWire package to use.")
+ (wireplumber
+ (file-like wireplumber)
+ "The WirePlumber package to use.")
+ (enable-pulseaudio?
+ (boolean #t)
+ "When true, enable PipeWire's PulseAudio emulation support, allowing
+PulseAudio clients to use PipeWire transparently."))
+
+(define (home-pipewire-shepherd-service config)
+ (shepherd-service
+ (documentation "PipeWire media processing.")
+ (provision '(pipewire))
+ (requirement '(dbus))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-pulseaudio-shepherd-service config)
+ (shepherd-service
+ (documentation "Drop-in PulseAudio replacement service for PipeWire.")
+ (provision '(pipewire-pulseaudio))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-pipewire config)
+ "/bin/pipewire-pulse"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-wireplumber-shepherd-service config)
+ (shepherd-service
+ (documentation "WirePlumber session management for PipeWire.")
+ (provision '(wireplumber))
+ (requirement '(pipewire))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append
+ (home-pipewire-configuration-wireplumber config)
+ "/bin/wireplumber"))))
+ (stop #~(make-kill-destructor))))
+
+(define (home-pipewire-shepherd-services config)
+ (cons* (home-pipewire-shepherd-service config)
+ (home-wireplumber-shepherd-service config)
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ (list (home-pipewire-pulseaudio-shepherd-service config))
+ '())))
+
+(define (home-pipewire-asoundrc config)
+ (match-record config <home-pipewire-configuration>
+ (pipewire)
+ (mixed-text-file
+ "asoundrc"
+ "<" pipewire "/share/alsa/alsa.conf.d/50-pipewire.conf>\n"
+ "<" pipewire "/share/alsa/alsa.conf.d/99-pipewire-default.conf>\n"
+ "pcm_type.pipewire {\n"
+ " lib \"" pipewire "/lib/alsa-lib/libasound_module_pcm_pipewire.so\"\n"
+ "}\n"
+ "ctl_type.pipewire {\n"
+ " lib \"" pipewire "/lib/alsa-lib/libasound_module_ctl_pipewire.so\"\n"
+ "}\n")))
+
+(define home-pipewire-disable-pulseaudio-auto-start
+ (plain-file "client.conf" "autospawn = no"))
+
+(define (home-pipewire-xdg-configuration config)
+ (cons* `("alsa/asoundrc" ,(home-pipewire-asoundrc config))
+ (if (home-pipewire-configuration-enable-pulseaudio? config)
+ `(("pulse/client.conf"
+ ,home-pipewire-disable-pulseaudio-auto-start))
+ '())))
+
+(define home-pipewire-service-type
+ (service-type
+ (name 'pipewire)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-pipewire-shepherd-services)
+ (service-extension home-xdg-configuration-files-service-type
+ home-pipewire-xdg-configuration)))
+ (description
+ "Start essential PipeWire services.")
+ (default-value (home-pipewire-configuration))))
;;;
diff --git a/gnu/home/services/ssh.scm b/gnu/home/services/ssh.scm
index 34b1fe4658..295707d59f 100644
--- a/gnu/home/services/ssh.scm
+++ b/gnu/home/services/ssh.scm
@@ -25,6 +25,7 @@
#:use-module (guix deprecation)
#:use-module (guix diagnostics)
#:use-module (guix i18n)
+ #:use-module ((guix utils) #:select (%current-system))
#:use-module (gnu services)
#:use-module (gnu services configuration)
#:use-module (guix modules)
@@ -32,7 +33,7 @@
#:use-module (gnu home services shepherd)
#:use-module ((gnu home services utils)
#:select (object->camel-case-string))
- #:autoload (gnu packages base) (glibc-utf8-locales)
+ #:autoload (gnu packages base) (libc-utf8-locales-for-target)
#:use-module (gnu packages ssh)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
@@ -357,8 +358,9 @@ inserted after each of them."
;; Support non-ASCII file names.
(setenv "GUIX_LOCPATH"
- #+(file-append glibc-utf8-locales
- "/lib/locale"))
+ #+(file-append
+ (libc-utf8-locales-for-target (%current-system))
+ "/lib/locale"))
(setlocale LC_ALL "en_US.utf8")
(call-with-output-file #$output