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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
| | ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu home services desktop)
#:use-module (gnu home services)
#:use-module (gnu home services shepherd)
#:use-module (gnu services configuration)
#:autoload (gnu packages xdisorg) (redshift)
#: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))
\f
;;;
;;; Redshift.
;;;
(define (serialize-integer field value)
(string-append (match field
('daytime-temperature "temp-day")
('nighttime-temperature "temp-night")
('daytime-brightness "brightness-day")
('nighttime-brightness "brightness-night")
('latitude "lat")
('longitude "lon")
(_ (symbol->string field)))
"=" (number->string value) "\n"))
(define (serialize-symbol field value)
(string-append (symbol->string field)
"=" (symbol->string value) "\n"))
(define serialize-inexact-number serialize-integer)
(define (inexact-number? n)
(and (number? n) (inexact? n)))
(define-maybe inexact-number)
(define-configuration home-redshift-configuration
(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.")
(adjustment-method
(symbol 'randr)
"Color adjustment method.")
;; Default values from redshift(1).
(daytime-temperature
(integer 6500)
"Daytime color temperature (kelvins).")
(nighttime-temperature
(integer 4500)
"Nighttime color temperature (kelvins).")
(daytime-brightness
(maybe-inexact-number 'disabled)
"Daytime screen brightness, between 0.1 and 1.0.")
(nighttime-brightness
(maybe-inexact-number 'disabled)
"Nighttime screen brightness, between 0.1 and 1.0.")
(latitude
(maybe-inexact-number 'disabled)
"Latitude, when @code{location-provider} is @code{'manual}.")
(longitude
(maybe-inexact-number 'disabled)
"Longitude, when @code{location-provider} is @code{'manual}."))
(define (serialize-redshift-configuration config)
(define location-fields
'(latitude longitude))
(define (location-field? field)
(memq (configuration-field-name field) location-fields))
#~(string-append
"[redshift]\n"
#$(serialize-configuration config
(remove location-field?
home-redshift-configuration-fields))
"\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))
(start #~(make-forkexec-constructor
(list #$(file-append redshift "/bin/redshift")
"-c" #$config-file)))
(stop #~(make-kill-destructor)))))
(define home-redshift-service-type
(service-type
(name 'home-redshift)
(extensions (list (service-extension home-shepherd-service-type
redshift-shepherd-service)))
(default-value (home-redshift-configuration))
(description
"Run Redshift, a program that adjust the color temperature of display
according to time of day.")))
|