~abcdw/rde

rde/rde/features/linux.scm -rw-r--r-- 6.7 KiB
e98d6a8eAndrew Tropin rde: gnupg: Add copyright preamble. 20 hours ago
                                                                                
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
(define-module (rde features linux)
  #:use-module (rde packages)
  #:use-module (rde features)
  #:use-module (rde features predicates)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu services)
  #:use-module (gnu services base)
  #:use-module (gnu services shepherd)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu home-services wm)
  #:use-module (guix gexp)

  #:export (feature-backlight
	    feature-pipewire))

(define* (feature-backlight
	  #:key
	  (default-brightness 100)
	  (step 10)
	  (brightnessctl brightnessctl))
  "Setup and configure brightness for various devices."
  (ensure-pred brightness? default-brightness)
  (ensure-pred any-package? brightnessctl)
  (ensure-pred brightness? step)

  (define (step->symbol op)
    (symbol-append (string->symbol (number->string step)) '% op))
  (define (backlight-home-services config)
    (list
     (simple-service
      'backlight-add-packages
      home-profile-service-type
      (list brightnessctl))
     (when (get-value 'sway config)
       (simple-service
        'backlight-add-brightness-control-to-sway
        home-sway-service-type
        `((bindsym --locked XF86MonBrightnessUp exec
		   ,(file-append brightnessctl "/bin/brightnessctl")
		   set ,(step->symbol '+))
	  (bindsym --locked XF86MonBrightnessDown exec
		   ,(file-append brightnessctl "/bin/brightnessctl")
		   set ,(step->symbol '-)))))))

  (define (backlight-system-services config)
    (list
     (simple-service
      'backlight-set-brightness-on-startup
      shepherd-root-service-type
      (list (shepherd-service
             (provision '(startup-brightness))
             (requirement '(virtual-terminal))
             (start
              #~(lambda ()
                  (invoke #$(file-append brightnessctl "/bin/brightnessctl")
			  "set" (string-append
				 (number->string #$default-brightness) "%"))))
             (one-shot? #t))))
     (udev-rules-service
      'backlight-add-udev-rules
      brightnessctl)))

  (feature
   (name 'backlight)
   (values `((backlight . #t)))
   (home-services-getter backlight-home-services)
   (system-services-getter backlight-system-services)))


(define* (feature-pipewire
          #:key
          (pipewire pipewire-0.3)
          (wireplumber wireplumber)
          (pulseaudio pulseaudio))
  ""
  (define (home-pipewire-services config)
    (list
     ;; TODO: Make home-alsa-service-type
     (simple-service
      'pipewire-add-asoundrc
      home-xdg-configuration-files-service-type
      `(("alsa/asoundrc"
         ,(mixed-text-file
           "asoundrc"
           #~(string-append
              "<"
	      #$(file-append
                 pipewire "/share/alsa/alsa.conf.d/50-pipewire.conf")
	      ">\n<"
	      #$(file-append
                 pipewire "/share/alsa/alsa.conf.d/99-pipewire-default.conf")
              ">\n"
              "
pcm_type.pipewire {
  lib " #$(file-append pipewire "/lib/alsa-lib/libasound_module_pcm_pipewire.so")
  "
}

ctl_type.pipewire {
  lib " #$(file-append pipewire "/lib/alsa-lib/libasound_module_ctl_pipewire.so")
  "
}
")))))


     (simple-service
      'pipewire-add-shepherd-daemons
      home-shepherd-service-type
      (list
       (shepherd-service
        (requirement '(dbus))
        (provision '(pipewire))
        (stop  #~(make-kill-destructor))
        (start #~(make-forkexec-constructor
                  (list #$(file-append pipewire "/bin/pipewire"))
                  #:log-file (string-append
                              (or (getenv "XDG_LOG_HOME")
                                  (format #f "~a/.local/var/log"
                                          (getenv "HOME")))
                              "/pipewire.log")
                  #:environment-variables
                  (append (list "DISABLE_RTKIT=1")
                          (default-environment-variables)))))
       (shepherd-service
        (requirement '(pipewire))
        (provision '(wireplumber))
        (stop  #~(make-kill-destructor))
        (start #~(make-forkexec-constructor
                  (list #$(file-append wireplumber "/bin/wireplumber"))
                  #:log-file (string-append
                              (or (getenv "XDG_LOG_HOME")
                                  (format #f "~a/.local/var/log"
                                          (getenv "HOME")))
                              "/wireplumber.log")
                  #:environment-variables
                  (append (list "DISABLE_RTKIT=1")
                          (default-environment-variables)))))
       (shepherd-service
        (requirement '(pipewire))
        (provision '(pipewire-pulse))
        (stop  #~(make-kill-destructor))
        (start #~(make-forkexec-constructor
                  (list #$(file-append pipewire "/bin/pipewire-pulse"))
                  #:log-file (string-append
                              (or (getenv "XDG_LOG_HOME")
                                  (format #f "~a/.local/var/log"
                                          (getenv "HOME")))
                              "/pipewire-pulse.log")
                  #:environment-variables
                  (append (list "DISABLE_RTKIT=1")
                          (default-environment-variables)))))))

     (when (get-value 'sway config)
       (simple-service
        'pipewire-add-volume-and-player-bindings-to-sway
        home-sway-service-type
        `((bindsym --locked XF86AudioRaiseVolume "\\\n"
                   exec ,(file-append pulseaudio "/bin/pactl")
                   set-sink-mute @DEFAULT_SINK@ "false; \\\n"
                   exec ,(file-append pulseaudio "/bin/pactl")
                   set-sink-volume @DEFAULT_SINK@ +5%)
          (bindsym --locked XF86AudioLowerVolume "\\\n"
                   exec ,(file-append pulseaudio "/bin/pactl")
                   set-sink-mute @DEFAULT_SINK@ "false; \\\n"
                   exec ,(file-append pulseaudio "/bin/pactl")
                   set-sink-volume @DEFAULT_SINK@ -5%)
          (bindsym --locked XF86AudioMute exec
                   ,(file-append pulseaudio "/bin/pactl")
                   set-sink-mute @DEFAULT_SINK@ toggle)
          (bindsym --locked XF86AudioMicMute exec
                   ,(file-append pulseaudio "/bin/pactl")
                   set-source-mute @DEFAULT_SOURCE@ toggle))))

     (simple-service
      'pipewire-add-packages
      home-profile-service-type
      (list pipewire wireplumber))))

  (define (system-pipewire-services _)
    (list
     (udev-rules-service
      'pipewire-add-udev-rules
      pipewire)))

  (feature
   (name 'pipewire)
   (values (make-feature-values pipewire wireplumber))
   (home-services-getter home-pipewire-services)
   (system-services-getter system-pipewire-services)))