lirc.scm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. (define-module (gnu services lirc)
  20. #:use-module (gnu services)
  21. #:use-module (gnu services shepherd)
  22. #:use-module (gnu packages lirc)
  23. #:use-module (guix gexp)
  24. #:use-module (guix records)
  25. #:use-module (ice-9 match)
  26. #:export (lirc-configuration
  27. lirc-configuation?
  28. lirc-service
  29. lirc-service-type))
  30. ;;; Commentary:
  31. ;;;
  32. ;;; LIRC service.
  33. ;;;
  34. ;;; Code:
  35. (define-record-type* <lirc-configuration>
  36. lirc-configuration make-lirc-configuration
  37. lirc-configuation?
  38. (lirc lirc-configuration-lirc ;file-like
  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. (define %lirc-activation
  46. #~(begin
  47. (use-modules (guix build utils))
  48. (mkdir-p "/var/run/lirc")))
  49. (define lirc-shepherd-service
  50. (match-lambda
  51. (($ <lirc-configuration> lirc device driver config-file options)
  52. (list (shepherd-service
  53. (provision '(lircd))
  54. (documentation "Run the LIRC daemon.")
  55. (requirement '(user-processes))
  56. (start #~(make-forkexec-constructor
  57. (list (string-append #$lirc "/sbin/lircd")
  58. "--nodaemon"
  59. #$@(if device
  60. #~("--device" #$device)
  61. #~())
  62. #$@(if driver
  63. #~("--driver" #$driver)
  64. #~())
  65. #$@(if config-file
  66. #~(#$config-file)
  67. #~())
  68. #$@options)))
  69. (stop #~(make-kill-destructor)))))))
  70. (define lirc-service-type
  71. (service-type (name 'lirc)
  72. (extensions
  73. (list (service-extension shepherd-root-service-type
  74. lirc-shepherd-service)
  75. (service-extension activation-service-type
  76. (const %lirc-activation))))))
  77. (define* (lirc-service #:key (lirc lirc)
  78. device driver config-file
  79. (extra-options '()))
  80. "Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
  81. decodes infrared signals from remote controls.
  82. The daemon will use specified @var{device}, @var{driver} and
  83. @var{config-file} (configuration file name).
  84. Finally, @var{extra-options} is a list of additional command-line options
  85. passed to @command{lircd}."
  86. (service lirc-service-type
  87. (lirc-configuration
  88. (lirc lirc)
  89. (device device) (driver driver)
  90. (config-file config-file)
  91. (extra-options extra-options))))
  92. ;;; lirc.scm ends here