aboutsummaryrefslogtreecommitdiff
path: root/whispers/services/console.scm
blob: bb72a22ffe65e88c7f3df6f44cb12d0c095446ac (about) (plain)
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
;;; Whispers --- Stealth VPN and ssh tunneler
;;; Copyright © 2024 Runciter <runciter@whispers-vpn.org>
;;;
;;; This file is part of Whispers.
;;;
;;; Whispers 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.
;;;
;;; Whispers 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 Whispers.  If not, see <http://www.gnu.org/licenses/>.

(define-module (whispers services console)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (gnu services)
  #:use-module (gnu services shepherd)
  #:use-module (gnu packages linux)
  #:export (console-blank-configuration
            console-blank-configuration?
            make-console-blank-configuration
            this-console-blank-configuration
            console-blank-service-type))

(define-record-type* <console-blank-configuration>
  console-blank-configuration make-console-blank-configuration
  console-blank-configuration?
  this-console-blank-configuration
  ;; A file-like object
  (util-linux-package  console-blank-configuration-util-linux-package
                        (default util-linux))
  ;; An integer
  (blank-time           console-blank-configuration-blank-time
                        (default 10))
  ;; An integer
  (powerdown-time       console-blank-configuration-powerdown-time
                        (default 10)))

(define (console-blank-shepherd-services config)
  "Return a list of one shepherd services setting up Linux console screen
blanking and powerdown times, configurable by CONFIG, a record of the
<console-blank-configuration> type."
  (let ((util-linux (console-blank-configuration-util-linux-package config))
        (blank (number->string
                (console-blank-configuration-blank-time config)))
        (powerdown (number->string
                    (console-blank-configuration-powerdown-time config))))
    (list
     (shepherd-service
      (documentation "Setup Linux console screen blanking and powerdown.")
      (provision (list 'console-blank))

      ;; Start after mingetty has been started on tty1
      (requirement (list 'term-tty1 'console-font-tty1))

      (start #~(lambda _
                 (case (status:exit-val
                        (system
                         (string-append #$(file-append util-linux
                                                       "/bin/setterm")
                                        " --blank="
                                        #$blank
                                        " --powerdown="
                                        #$powerdown
                                        " </dev/tty1 >/dev/tty1")))
                   ((0) #t)
                   (else #f))))
      (stop #~(const #f))
      (respawn? #f)))))

(define console-blank-service-type
  (service-type
   (name 'console-blank)
   (description "Setup screen blanking and powerdown on the Linux console")
   (extensions
    (list (service-extension shepherd-root-service-type
                             console-blank-shepherd-services)
          (service-extension
           profile-service-type
           (lambda (config)
             (list
              (console-blank-configuration-util-linux-package config))))))
   (default-value (console-blank-configuration))))