<commit_before># ALSA sound support.
{ config, pkgs, ... }:

with pkgs.lib;

let

  inherit (pkgs) alsaUtils;

  soundState = "/var/lib/alsa/asound.state";

in

{

  ###### interface
  
  options = {
  
    sound = {

      enable = mkOption {
        default = true;
        description = ''
          Whether to enable ALSA sound.
        '';
        merge = mergeEnableOption;
      };
      
      enableOSSEmulation = mkOption {
        default = true;
	description = ''
	  Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
	'';
      };

    };
    
  };


  ###### implementation
  
  config = mkIf config.sound.enable {
  
    environment.systemPackages = [alsaUtils];

    users.extraGroups = singleton
      { # Alsalib seems to require the existence of this group, even
        # if it's not used (e.g., doesn't own any devices).
        name = "audio";
        gid = config.ids.gids.audio;
      };

    jobs.alsa =
      { startOn = "started udev";

        preStart =
          ''
            mkdir -m 0755 -p $(dirname ${soundState})

            # Load some additional modules.
	    
	    ${optionalString config.sound.enableOSSEmulation
	      ''
                for mod in snd_pcm_oss; do
                  ${config.system.sbin.modprobe}/sbin/modprobe $mod || true
                done
	      ''
	    }

            # Restore the sound state.
            ${alsaUtils}/sbin/alsactl -f ${soundState} restore
          '';

        postStop =
          ''
            # Save the sound state.
            ${alsaUtils}/sbin/alsactl -f ${soundState} store
          '';
      };
      
  };

}<commit_msg>* The ALSA job shouldn't be started until udevtrigger has finished.   Otherwise the sound card drivers may not have been loaded yet, and   restoring the mixer settings will fail.  Also, since the ALSA job   itself will fail, it won't save the mixer settings on shutdown.<commit_after># ALSA sound support.
{ config, pkgs, ... }:

with pkgs.lib;

let

  inherit (pkgs) alsaUtils;

  soundState = "/var/lib/alsa/asound.state";

in

{

  ###### interface
  
  options = {
  
    sound = {

      enable = mkOption {
        default = true;
        description = ''
          Whether to enable ALSA sound.
        '';
        merge = mergeEnableOption;
      };
      
      enableOSSEmulation = mkOption {
        default = true;
	description = ''
	  Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
	'';
      };

    };
    
  };


  ###### implementation
  
  config = mkIf config.sound.enable {
  
    environment.systemPackages = [alsaUtils];

    users.extraGroups = singleton
      { # Alsalib seems to require the existence of this group, even
        # if it's not used (e.g., doesn't own any devices).
        name = "audio";
        gid = config.ids.gids.audio;
      };

    jobs.alsa =
      { startOn = "stopped udevtrigger";

        preStart =
          ''
            mkdir -m 0755 -p $(dirname ${soundState})

            # Load some additional modules.
	    ${optionalString config.sound.enableOSSEmulation
	      ''
                for mod in snd_pcm_oss; do
                  ${config.system.sbin.modprobe}/sbin/modprobe $mod || true
                done
	      ''
	    }

            # Restore the sound state.
            ${alsaUtils}/sbin/alsactl -f ${soundState} restore || true
          '';

        postStop =
          ''
            # Save the sound state.
            ${alsaUtils}/sbin/alsactl -f ${soundState} store
          '';
      };
      
  };

}
{'fraction_non_alphanumeric': 0.10946248600223964, 'fraction_numerical': 0.0022396416573348264, 'mean_word_length': 1.6844477836213374, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5154765', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1022, 'n_words': 291}