gnu: waybar: Fix build.
[jackhill/guix/guix.git] / gnu / services / lirc.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Alex Kost <alezost@gmail.com>
3 ;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (gnu services lirc)
21 #:use-module (gnu services)
22 #:use-module (gnu services shepherd)
23 #:use-module (gnu packages lirc)
24 #:use-module (guix gexp)
25 #:use-module (guix records)
26 #:use-module (ice-9 match)
27 #:export (lirc-configuration
28 lirc-configuation?
29 lirc-service
30 lirc-service-type))
31
32 ;;; Commentary:
33 ;;;
34 ;;; LIRC service.
35 ;;;
36 ;;; Code:
37
38 (define-record-type* <lirc-configuration>
39 lirc-configuration make-lirc-configuration
40 lirc-configuation?
41 (lirc lirc-configuration-lirc ;<package>
42 (default lirc))
43 (device lirc-configuration-device) ;string
44 (driver lirc-configuration-driver) ;string
45 (config-file lirc-configuration-file) ;string | file-like object
46 (extra-options lirc-configuration-options ;list of strings
47 (default '())))
48
49 (define %lirc-activation
50 #~(begin
51 (use-modules (guix build utils))
52 (mkdir-p "/var/run/lirc")))
53
54 (define lirc-shepherd-service
55 (match-lambda
56 (($ <lirc-configuration> lirc device driver config-file options)
57 (list (shepherd-service
58 (provision '(lircd))
59 (documentation "Run the LIRC daemon.")
60 (requirement '(user-processes))
61 (start #~(make-forkexec-constructor
62 (list (string-append #$lirc "/sbin/lircd")
63 "--nodaemon"
64 #$@(if device
65 #~("--device" #$device)
66 #~())
67 #$@(if driver
68 #~("--driver" #$driver)
69 #~())
70 #$@(if config-file
71 #~(#$config-file)
72 #~())
73 #$@options)))
74 (stop #~(make-kill-destructor)))))))
75
76 (define lirc-service-type
77 (service-type (name 'lirc)
78 (extensions
79 (list (service-extension shepherd-root-service-type
80 lirc-shepherd-service)
81 (service-extension activation-service-type
82 (const %lirc-activation))))))
83
84 (define* (lirc-service #:key (lirc lirc)
85 device driver config-file
86 (extra-options '()))
87 "Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
88 decodes infrared signals from remote controls.
89
90 The daemon will use specified @var{device}, @var{driver} and
91 @var{config-file} (configuration file name).
92
93 Finally, @var{extra-options} is a list of additional command-line options
94 passed to @command{lircd}."
95 (service lirc-service-type
96 (lirc-configuration
97 (lirc lirc)
98 (device device) (driver driver)
99 (config-file config-file)
100 (extra-options extra-options))))
101
102 ;;; lirc.scm ends here