A home/modules/ruther/home/services/wayland.scm => home/modules/ruther/home/services/wayland.scm +82 -0
@@ 0,0 1,82 @@
+(define-module (ruther home services wayland)
+ #:use-module (guix gexp)
+ #:use-module (gnu packages wm)
+ #:use-module (gnu services)
+ #:use-module (gnu services configuration)
+ #:use-module (gnu services shepherd)
+ #:use-module (srfi srfi-26)
+ #:use-module (srfi srfi-1)
+ #:use-module (gnu home services)
+ #:use-module (gnu home services shepherd))
+
+(define (wayland-display-shepherd-service config)
+ (list
+ (shepherd-service
+ (documentation "Sets WAYLAND_DISPLAY to argument passed in.
+This should be called from a wayland compositor like this: `herd start wayland-display $WAYLAND_DISPLAY`")
+ (provision '(wayland-display))
+ (auto-start? #f)
+ (start #~(lambda (wayland-display)
+ (setenv "WAYLAND_DISPLAY" wayland-display)
+ wayland-display))
+ (stop #~(lambda (_)
+ (unsetenv "WAYLAND_DISPLAY")
+ #f)))))
+
+(define-public home-wayland-display-service-type
+ (service-type
+ (name 'home-wayland-display)
+ (description "A service to set WAYLAND_DISPLAY environment variable inside of the shepherd process.")
+ (default-value #f)
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ wayland-display-shepherd-service)))))
+
+
+(define (wlr-services-shepherd-service services)
+ (list
+ (shepherd-service
+ (documentation "Service for starting WLR services.")
+ (provision '(wlr-services))
+ (auto-start? #f)
+ (start
+ #~(lambda* (#:optional (wayland-display #f))
+ (use-modules (shepherd service)
+ (shepherd support))
+
+ (let ((display-service (lookup-service 'wayland-display)))
+ (when (and wayland-display
+ (service-stopped? display-service))
+ (start-service display-service
+ wayland-display))
+
+ (if (service-running? display-service)
+ (for-each (lambda (service)
+ (start-service (lookup-service service)))
+ '#$services)
+ (begin
+ ((@ (shepherd support) local-output)
+ ((@ (shepherd support) l10n)
+ "Cannot start wlr-services, because wayland-display is not running and WAYLAND_DISPLAY argument has not been supplied."))
+ #f)))))
+ (stop #~(lambda* (running-value #:optional (stop-display "yes"))
+ (use-modules (shepherd service)
+ (shepherd support))
+
+ (for-each (lambda (service)
+ (stop-service (lookup-service service)))
+ '#$services)
+
+ (when (equal? stop-display "yes")
+ ((@ (shepherd support) local-output) ((@ (shepherd support) l10n) "Stopping wayland-display as well."))
+ (stop-service (lookup-service 'wayland-display)))
+ #f)))))
+
+(define-public home-wlr-services-service-type
+ (service-type
+ (name 'home-wayland-display)
+ (description "A service to start a list of services, meant for wlr.")
+ (default-value '())
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ wlr-services-shepherd-service)))))