2008-11-22 20:29:05 -05:00
|
|
|
# ALSA sound support.
|
2014-04-14 10:26:48 -04:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 13:27:57 -04:00
|
|
|
|
2014-04-14 10:26:48 -04:00
|
|
|
with lib;
|
2007-02-28 19:36:00 -05:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-07-16 11:01:56 -04:00
|
|
|
inherit (pkgs) alsaUtils;
|
|
|
|
|
|
|
|
soundState = "/var/lib/alsa/asound.state";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 14:20:50 -04:00
|
|
|
|
2008-11-22 20:29:05 -05:00
|
|
|
options = {
|
2011-09-14 14:20:50 -04:00
|
|
|
|
2008-11-22 20:29:05 -05:00
|
|
|
sound = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2013-10-28 11:14:15 -04:00
|
|
|
type = types.bool;
|
2008-11-22 20:29:05 -05:00
|
|
|
default = true;
|
2009-07-16 11:01:56 -04:00
|
|
|
description = ''
|
2008-11-22 20:29:05 -05:00
|
|
|
Whether to enable ALSA sound.
|
2009-07-16 11:01:56 -04:00
|
|
|
'';
|
2008-11-22 20:29:05 -05:00
|
|
|
};
|
2011-09-14 14:20:50 -04:00
|
|
|
|
2010-03-03 09:01:13 -05:00
|
|
|
enableOSSEmulation = mkOption {
|
2013-10-28 11:14:15 -04:00
|
|
|
type = types.bool;
|
2010-03-03 09:01:13 -05:00
|
|
|
default = true;
|
2012-08-17 11:00:14 -04:00
|
|
|
description = ''
|
|
|
|
Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
|
|
|
|
'';
|
2010-03-03 09:01:13 -05:00
|
|
|
};
|
2007-02-28 19:36:00 -05:00
|
|
|
|
2008-11-22 20:29:05 -05:00
|
|
|
};
|
2011-09-14 14:20:50 -04:00
|
|
|
|
2008-11-22 20:29:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-16 11:01:56 -04:00
|
|
|
###### implementation
|
2011-09-14 14:20:50 -04:00
|
|
|
|
2009-07-16 11:01:56 -04:00
|
|
|
config = mkIf config.sound.enable {
|
2011-09-14 14:20:50 -04:00
|
|
|
|
2011-11-04 13:40:00 -04:00
|
|
|
environment.systemPackages = [ alsaUtils ];
|
2008-11-22 20:29:05 -05:00
|
|
|
|
2012-10-02 11:09:54 -04:00
|
|
|
# ALSA provides a udev rule for restoring volume settings.
|
|
|
|
services.udev.packages = [ alsaUtils ];
|
2008-11-22 20:29:05 -05:00
|
|
|
|
2012-10-02 11:09:54 -04:00
|
|
|
boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss";
|
2007-02-28 19:36:00 -05:00
|
|
|
|
2013-01-16 06:33:18 -05:00
|
|
|
systemd.services."alsa-store" =
|
2012-10-02 11:09:54 -04:00
|
|
|
{ description = "Store Sound Card State";
|
2013-09-22 15:31:38 -04:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
unitConfig.RequiresMountsFor = "/var/lib/alsa";
|
2013-11-26 12:17:12 -05:00
|
|
|
unitConfig.ConditionVirtualization = "!systemd-nspawn";
|
2013-09-22 15:31:38 -04:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStart = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa";
|
|
|
|
ExecStop = "${alsaUtils}/sbin/alsactl store --ignore";
|
|
|
|
};
|
2009-07-16 11:01:56 -04:00
|
|
|
};
|
2012-10-09 15:14:32 -04:00
|
|
|
|
2008-11-22 20:29:05 -05:00
|
|
|
};
|
2007-02-28 19:36:00 -05:00
|
|
|
|
|
|
|
}
|