sound.scm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu services sound)
  19. #:use-module (gnu services base)
  20. #:use-module (gnu services configuration)
  21. #:use-module (gnu services shepherd)
  22. #:use-module (gnu services)
  23. #:use-module (gnu system shadow)
  24. #:use-module (guix gexp)
  25. #:use-module (guix packages)
  26. #:use-module (guix records)
  27. #:use-module (guix store)
  28. #:use-module (gnu packages linux)
  29. #:use-module (gnu packages pulseaudio)
  30. #:use-module (ice-9 match)
  31. #:export (alsa-configuration
  32. alsa-service-type))
  33. ;;; Commentary:
  34. ;;;
  35. ;;; Sound services.
  36. ;;;
  37. ;;; Code:
  38. ;;;
  39. ;;; ALSA
  40. ;;;
  41. (define-record-type* <alsa-configuration>
  42. alsa-configuration make-alsa-configuration alsa-configuration?
  43. (alsa-plugins alsa-configuration-alsa-plugins ;<package>
  44. (default alsa-plugins))
  45. (pulseaudio? alsa-configuration-pulseaudio? ;boolean
  46. (default #t))
  47. (extra-options alsa-configuration-extra-options ;string
  48. (default "")))
  49. (define alsa-config-file
  50. ;; Return the ALSA configuration file.
  51. (match-lambda
  52. (($ <alsa-configuration> alsa-plugins pulseaudio? extra-options)
  53. (apply mixed-text-file "asound.conf"
  54. `("# Generated by 'alsa-service'.\n\n"
  55. ,@(if pulseaudio?
  56. `("# Use PulseAudio by default
  57. pcm_type.pulse {
  58. lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
  59. "/lib/alsa-lib/libasound_module_pcm_pulse.so") "\"
  60. }
  61. ctl_type.pulse {
  62. lib \"" ,#~(string-append #$alsa-plugins:pulseaudio
  63. "/lib/alsa-lib/libasound_module_ctl_pulse.so") "\"
  64. }
  65. pcm.!default {
  66. type pulse
  67. fallback \"sysdefault\"
  68. hint {
  69. show on
  70. description \"Default ALSA Output (currently PulseAudio Sound Server)\"
  71. }
  72. }
  73. ctl.!default {
  74. type pulse
  75. fallback \"sysdefault\"
  76. }\n\n")
  77. '())
  78. ,extra-options)))))
  79. (define (alsa-etc-service config)
  80. (list `("asound.conf" ,(alsa-config-file config))))
  81. (define alsa-service-type
  82. (service-type
  83. (name 'alsa)
  84. (extensions
  85. (list (service-extension etc-service-type alsa-etc-service)))
  86. (default-value (alsa-configuration))
  87. (description "Configure low-level Linux sound support, ALSA.")))
  88. ;;; sound.scm ends here