aboutsummaryrefslogtreecommitdiff
path: root/mirenn/home/services/brightnessctl.scm
blob: b1eeb357b280beeecdc9a212757c30601fc28619 (plain) (blame)
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
(define-module (mirenn home services brightnessctl)
  #:use-module (guix gexp)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services configuration)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu packages linux)

  #:export (home-brightnessctl-configuration
            home-brightnessctl-service-type))

(define-configuration/no-serialization home-brightnessctl-configuration
  (state-file
    (string ".local/state/brightnessctl")
    "The file which the brightness state is stored."))

(define (home-brightnessctl-shepherd-service config)
  (list
    (shepherd-service
      (provision '(brightnessctl))
      (documentation "Save and restore brightness.")
      (start #~(make-system-constructor
                 #$(string-append "brightnessctl set $(cat \"$HOME/"
                                  (home-brightnessctl-configuration-state-file config)
                                  "\")")))
      (stop #~(make-system-destructor
                #$(string-append "brightnessctl get > \"$HOME/"
                                 (home-brightnessctl-configuration-state-file config)
                                 "\""))))))

(define home-brightnessctl-service-type
  (service-type
    (name 'home-brightnessctl)
    (extensions
      (list (service-extension home-shepherd-service-type home-brightnessctl-shepherd-service)))
    (description "Save and restore brightness.")
    (default-value (home-brightnessctl-configuration))))