guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help! Having troubles testing my generalization of home-redshift-servic


From: Gabriel Wicki
Subject: Help! Having troubles testing my generalization of home-redshift-service
Date: Thu, 04 May 2023 01:05:56 +0200

Hi y'all!

I've been working on a patch on generalizing the
home-redshift-service-type to also work under wayland.  I've created the
following patch but am now running into difficulties testing it.

I've created two minimalist system configurations (one for i3 and one
for sway) and run them like so:
$ $(./pre-inst-env guix system vm sys-i3-minimal.scm)

In that VM i am unable to
$  guix home reconfigure my-config.scm
due to `home-night-time-service-type` allegedly being an "unbound
variable".  Investigating with `guix repl` and just importing the
patched module I find a home-redshift-service-type but not my
home-night-time-service-type.

Having never really hacked home services I am somewhat puzzled.  It
certainly feels like I'm missing something essential here.

Any ideas?
g



>From 0b4394582f84a56ded50d1a55f112d3fdf51f905 Mon Sep 17 00:00:00 2001
Message-Id: 
<0b4394582f84a56ded50d1a55f112d3fdf51f905.1683146786.git.gabriel@erlikon.ch>
From: Gabriel Wicki <gabriel@erlikon.ch>
Date: Wed, 22 Mar 2023 11:50:00 +0100
Subject: [PATCH] home: desktop:  Generalize night-time service type.

* gnu/home/services/deskotp.scm:  Generalize redshift-service type so that it
works with both Xorg and Wayland.
---
 gnu/home/services/desktop.scm | 110 ++++++++++++++++++++--------------
 1 file changed, 65 insertions(+), 45 deletions(-)

diff --git a/gnu/home/services/desktop.scm b/gnu/home/services/desktop.scm
index 661fe7d283..4b14cb6d6c 100644
--- a/gnu/home/services/desktop.scm
+++ b/gnu/home/services/desktop.scm
@@ -24,15 +24,15 @@ (define-module (gnu home services desktop)
   #:use-module (gnu home services shepherd)
   #:use-module (gnu services configuration)
   #:autoload   (gnu packages glib)    (dbus)
-  #:autoload   (gnu packages xdisorg) (redshift unclutter)
+  #:autoload   (gnu packages xdisorg) (gammastep redshift unclutter)
   #:autoload   (gnu packages xorg) (setxkbmap xmodmap)
   #:use-module (guix records)
   #:use-module (guix gexp)
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 match)
-  #:export (home-redshift-configuration
-            home-redshift-configuration?
-            home-redshift-service-type
+  #:export (home-night-time-configuration
+            home-night-time-configuration?
+            home-night-time-service-type
 
             home-dbus-configuration
             home-dbus-service-type
@@ -44,8 +44,8 @@ (define-module (gnu home services desktop)
             home-xmodmap-service-type))
 
 
-;;;
-;;; Redshift.
+;;
+;;; Night-time aka Redshift and Gammastep.
 ;;;
 
 (define (serialize-integer field value)
@@ -78,24 +78,35 @@ (define (serialize-raw-configuration-string field value)
   value)
 (define raw-configuration-string? string?)
 
-(define-configuration home-redshift-configuration
+(define-configuration home-night-time-backends
   (redshift
    (file-like redshift)
    "Redshift package to use.")
 
+  (gammstep
+   (file-like gammstep)
+   "Gammstep package to use."))
+
+(define-configuration home-night-time-configuration
+  (wayland?
+   (boolean #f)
+   "Indicates which tool (Redshift for Xorg, Gammastep for Wayland will be
+used)"
+   empty-serializer)
+
   (location-provider
    (symbol 'geoclue2)
    "Geolocation provider---@code{'manual} or @code{'geoclue2}.
 
 In the former case, you must also specify the @code{latitude} and
-@code{longitude} fields so Redshift can determine daytime at your place.  In
-the latter case, the Geoclue system service must be running; it will be
-queried for location information.")
+@code{longitude} fields so Night-time-service can determine daytime at your
+place.  In the latter case, the Geoclue system service must be running; it
+will be queried for location information.")
   (adjustment-method
    (symbol 'randr)
    "Color adjustment method.")
 
-  ;; Default values from redshift(1).
+  ;; Default values from redshift(1) and gammastep(1).
   (daytime-temperature
    (integer 6500)
    "Daytime color temperature (kelvins).")
@@ -129,11 +140,11 @@ (define-configuration home-redshift-configuration
 
   (extra-content
    (raw-configuration-string "")
-   "Extra content appended as-is to the Redshift configuration file.  Run
-@command{man redshift} for more information about the configuration file
-format."))
+   "Extra content appended as-is to the Redshift or Gammastep configuration
+file.  Run @command{man redshift} or @command{man gammastep} respectively for
+more information about the configuration file format."))
 
-(define (serialize-redshift-configuration config)
+(define (serialize-night-time-configuration config)
   (define location-fields
     '(latitude longitude))
 
@@ -146,46 +157,55 @@ (define (serialize-redshift-configuration config)
               '(redshift extra-content))))
 
   #~(string-append
-     "[redshift]\n"
+     #$(if (home-night-time-configuration-wayland? config) "[general]" 
"[redshift]")
+     "\n"
      #$(serialize-configuration config
                                 (remove secondary-field?
-                                        home-redshift-configuration-fields))
+                                        home-night-time-configuration-fields))
 
-     #$(home-redshift-configuration-extra-content config)
+     #$(home-night-time-configuration-extra-content config)
 
      "\n[manual]\n"
      #$(serialize-configuration config
                                 (filter location-field?
-                                        home-redshift-configuration-fields))))
-
-(define (redshift-shepherd-service config)
-  (define config-file
-    (computed-file "redshift.conf"
-                   #~(call-with-output-file #$output
-                       (lambda (port)
-                         (display #$(serialize-redshift-configuration config)
-                                  port)))))
-
-  (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 redshift "/bin/redshift")
-                         "-c" #$config-file)))
-         (stop #~(make-kill-destructor))
-         (actions (list (shepherd-configuration-action config-file))))))
-
-(define home-redshift-service-type
+                                        
home-night-time-configuration-fields))))
+
+(define (night-time-shepherd-service config)
+  (match-record config <home-night-time-configuration>
+    (wayland?)
+    (let* ((config-file-name (if wayland? "gammastep.conf" "redshift.conf"))
+           (config-file
+            (computed-file config-file-name
+              #~(call-with-output-file #$output
+                  (lambda (port)
+                    (display #$(serialize-night-time-configuration config)
+                             port))))))
+
+      (list (shepherd-service
+             (documentation
+              "Night-time screen color adjustments (Redshift for Xorg, 
Gammastep
+for Wayland/wlroots) program.")
+             (provision '(night-time))
+             ;; FIXME: This fails to start if Home is first activated from a
+             ;; non-X11 session.
+             (start #~(make-forkexec-constructor
+                       (list
+                        #$(if wayland?
+                              (file-append gammastep "/bin/gammastep")
+                              (file-append redshift "/bin/redshift"))
+                        "-c" #$config-file)))
+             (stop #~(make-kill-destructor))
+             (actions (list (shepherd-configuration-action config-file))))))))
+
+(define home-night-time-service-type
   (service-type
-   (name 'home-redshift)
+   (name 'home-night-time)
    (extensions (list (service-extension home-shepherd-service-type
-                                        redshift-shepherd-service)))
-   (default-value (home-redshift-configuration))
+                                        night-time-shepherd-service)))
+   (default-value (home-night-time-configuration))
    (description
-    "Run Redshift, a program that adjusts the color temperature of display
-according to time of day.")))
+    "Run Redshift (or Gammastep), a program that adjusts the color temperature
+of display according to time of day.")))
 
 
 ;;;

base-commit: 91bfd30ee3f35dfb7048bf42aea92f939cffbf17
-- 
2.39.2



reply via email to

[Prev in Thread] Current Thread [Next in Thread]