Merge branch 'core-updates'
[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 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 dmd)
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-service))
28
29 ;;; Commentary:
30 ;;;
31 ;;; LIRC service.
32 ;;;
33 ;;; Code:
34
35 (define-record-type* <lirc-configuration>
36 lirc-configuration make-lirc-configuration
37 lirc-configuation?
38 (lirc lirc-configuration-lirc ;<package>
39 (default lirc))
40 (device lirc-configuration-device) ;string
41 (driver lirc-configuration-driver) ;string
42 (config-file lirc-configuration-file) ;string | file-like object
43 (extra-options lirc-configuration-options ;list of strings
44 (default '())))
45
46 (define %lirc-activation
47 #~(begin
48 (use-modules (guix build utils))
49 (mkdir-p "/var/run/lirc")))
50
51 (define lirc-dmd-service
52 (match-lambda
53 (($ <lirc-configuration> lirc device driver config-file options)
54 (list (dmd-service
55 (provision '(lircd))
56 (documentation "Run the LIRC daemon.")
57 (requirement '(user-processes))
58 (start #~(make-forkexec-constructor
59 (list (string-append #$lirc "/sbin/lircd")
60 "--nodaemon"
61 #$@(if device
62 #~("--device" #$device)
63 #~())
64 #$@(if driver
65 #~("--driver" #$driver)
66 #~())
67 #$@(if config-file
68 #~(#$config-file)
69 #~())
70 #$@options)))
71 (stop #~(make-kill-destructor)))))))
72
73 (define lirc-service-type
74 (service-type (name 'lirc)
75 (extensions
76 (list (service-extension dmd-root-service-type
77 lirc-dmd-service)
78 (service-extension activation-service-type
79 (const %lirc-activation))))))
80
81 (define* (lirc-service #:key (lirc lirc)
82 device driver config-file
83 (extra-options '()))
84 "Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
85 decodes infrared signals from remote controls.
86
87 The daemon will use specified @var{device}, @var{driver} and
88 @var{config-file} (configuration file name).
89
90 Finally, @var{extra-options} is a list of additional command-line options
91 passed to @command{lircd}."
92 (service lirc-service-type
93 (lirc-configuration
94 (lirc lirc)
95 (device device) (driver driver)
96 (config-file config-file)
97 (extra-options extra-options))))
98
99 ;;; lirc.scm ends here