Unverified Commit 01fe231d authored by K900's avatar K900 Committed by GitHub
Browse files

Merge pull request #326262 from K900/no-more-sound-enable

nixos/alsa: kill sound.enable and friends with fire
parents 44bce695 3eeff547
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -2,8 +2,7 @@

Common configuration for headless machines (e.g., Amazon EC2 instances).

Disables [sound](#opt-sound.enable),
[vesa](#opt-boot.vesa), serial consoles,
Disables [vesa](#opt-boot.vesa), serial consoles,
[emergency mode](#opt-systemd.enableEmergencyMode),
[grub splash images](#opt-boot.loader.grub.splashImage)
and configures the kernel to reboot automatically on panic.
+1 −2
Original line number Diff line number Diff line
@@ -5,5 +5,4 @@ graphical stuff. It's a very short file that enables
[noXlibs](#opt-environment.noXlibs), sets
[](#opt-i18n.supportedLocales) to
only support the user-selected locale,
[disables packages' documentation](#opt-documentation.enable),
and [disables sound](#opt-sound.enable).
and [disables packages' documentation](#opt-documentation.enable).
+45 −0
Original line number Diff line number Diff line
@@ -197,6 +197,8 @@

- `services.roundcube.maxAttachmentSize` will multiply the value set with `1.37` to offset overhead introduced by the base64 encoding applied to attachments.

- The `sound` options have been removed or renamed, as they had a lot of unintended side effects. See [below](#sec-release-24.11-migration-sound) for details.

- The `services.mxisd` module has been removed as both [mxisd](https://github.com/kamax-matrix/mxisd) and [ma1sd](https://github.com/ma1uta/ma1sd) are not maintained any longer.
  Consequently the package `pkgs.ma1sd` has also been removed.

@@ -233,3 +235,46 @@
  should be changed to using *runner authentication tokens* by configuring
  {option}`services.gitlab-runner.services.<name>.authenticationTokenConfigFile` instead of the former
  {option}`services.gitlab-runner.services.<name>.registrationConfigFile` option.

## Detailed migration information {#sec-release-24.11-migration}

### `sound` options removal {#sec-release-24.11-migration-sound}

The `sound` options have been largely removed, as they are unnecessary for most modern setups, and cause issues when enabled.

If you set `sound.enable` in your configuration:
  - If you are using Pulseaudio or PipeWire, simply remove that option
  - If you are not using an external sound server, and want volumes to be persisted across shutdowns, set `hardware.alsa.enablePersistence = true` instead

If you set `sound.enableOSSEmulation` in your configuration:
  - Make sure it is still necessary, as very few applications actually use OSS
  - If necessary, set `boot.kernelModules = [ "snd_pcm_oss" ]`

If you set `sound.extraConfig` in your configuration:
  - If you are using another sound server, like Pulseaudio, JACK or PipeWire, migrate your configuration to that
  - If you are not using an external sound server, set `environment.etc."asound.conf".text = yourExtraConfig` instead

If you set `sound.mediaKeys` in your configuration:
  - Preferably switch to handling media keys in your desktop environment/compositor
  - If you want to maintain the exact behavior of the option, use the following snippet

```nix
services.actkbd = let
  volumeStep = "1%";
in {
  enable = true;
  bindings = [
    # "Mute" media key
    { keys = [ 113 ]; events = [ "key" ];       command = "${alsa-utils}/bin/amixer -q set Master toggle"; }

    # "Lower Volume" media key
    { keys = [ 114 ]; events = [ "key" "rep" ]; command = "${alsa-utils}/bin/amixer -q set Master ${volumeStep}- unmute"; }

    # "Raise Volume" media key
    { keys = [ 115 ]; events = [ "key" "rep" ]; command = "${alsa-utils}/bin/amixer -q set Master ${volumeStep}+ unmute"; }

    # "Mic Mute" media key
    { keys = [ 190 ]; events = [ "key" ];       command = "${alsa-utils}/bin/amixer -q set Capture toggle"; }
  ];
};
```
+3 −7
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ with lib;
let

  cfg = config.hardware.pulseaudio;
  alsaCfg = config.sound;

  hasZeroconf = let z = cfg.zeroconf; in z.publish.enable || z.discovery.enable;

@@ -58,7 +57,7 @@ let
  # Write an /etc/asound.conf that causes all ALSA applications to
  # be re-routed to the PulseAudio server through ALSA's Pulse
  # plugin.
  alsaConf = writeText "asound.conf" (''
  alsaConf = ''
    pcm_type.pulse {
      libs.native = ${pkgs.alsa-plugins}/lib/alsa-lib/libasound_module_pcm_pulse.so ;
      ${lib.optionalString enable32BitAlsaPlugins
@@ -76,8 +75,7 @@ let
    ctl.!default {
      type pulse
    }
    ${alsaCfg.extraConfig}
  '');
  '';

in {

@@ -221,10 +219,8 @@ in {

      environment.systemPackages = [ overriddenPackage ];

      sound.enable = true;

      environment.etc = {
        "asound.conf".source = alsaConf;
        "alsa/conf.d/99-pulseaudio.conf".text = alsaConf;

        "pulse/daemon.conf".source = writeText "daemon.conf"
          (lib.generators.toKeyValue {} cfg.daemon.config);
+22 −116
Original line number Diff line number Diff line
@@ -3,106 +3,31 @@

with lib;

let

  inherit (pkgs) alsa-utils;

  pulseaudioEnabled = config.hardware.pulseaudio.enable;

in

{
  imports = [
    (mkRenamedOptionModule [ "sound" "enableMediaKeys" ] [ "sound" "mediaKeys" "enable" ])
    (mkRemovedOptionModule [ "sound" ] "The option was heavily overloaded and can be removed from most configurations.")
  ];

  ###### interface

  options = {

    sound = {

      enable = mkOption {
  options.hardware.alsa.enablePersistence = mkOption {
    type = types.bool;
    default = false;
    description = ''
          Whether to enable ALSA sound.
        '';
      };

      enableOSSEmulation = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Whether to enable ALSA OSS emulation (with certain cards sound mixing may not work!).
        '';
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        example = ''
          defaults.pcm.!card 3
        '';
        description = ''
          Set addition configuration for system-wide alsa.
        '';
      };

      mediaKeys = {

        enable = mkOption {
          type = types.bool;
          default = false;
          description = ''
            Whether to enable volume and capture control with keyboard media keys.

            You want to leave this disabled if you run a desktop environment
            like KDE, Gnome, Xfce, etc, as those handle such things themselves.
            You might want to enable this if you run a minimalistic desktop
            environment or work from bare linux ttys/framebuffers.

            Enabling this will turn on {option}`services.actkbd`.
      Whether to enable ALSA sound card state saving on shutdown.
      This is generally not necessary if you're using an external sound server.
    '';
  };

        volumeStep = mkOption {
          type = types.str;
          default = "1";
          example = "1%";
          description = ''
            The value by which to increment/decrement volume on media keys.

            See amixer(1) for allowed values.
          '';
        };

      };

    };

  };


  ###### implementation

  config = mkIf config.sound.enable {

    environment.systemPackages = [ alsa-utils ];

    environment.etc = mkIf (!pulseaudioEnabled && config.sound.extraConfig != "")
      { "asound.conf".text = config.sound.extraConfig; };

  config = mkIf config.hardware.alsa.enablePersistence {
    # ALSA provides a udev rule for restoring volume settings.
    services.udev.packages = [ alsa-utils ];

    boot.kernelModules = optional config.sound.enableOSSEmulation "snd_pcm_oss";

    systemd.services.alsa-store =
      { description = "Store Sound Card State";
    systemd.services.alsa-store = {
      description = "Store Sound Card State";
      wantedBy = [ "multi-user.target" ];
        unitConfig.RequiresMountsFor = "/var/lib/alsa";
        unitConfig.ConditionVirtualization = "!systemd-nspawn";
      unitConfig = {
        RequiresMountsFor = "/var/lib/alsa";
        ConditionVirtualization = "!systemd-nspawn";
      };
      serviceConfig = {
        Type = "oneshot";
        RemainAfterExit = true;
@@ -111,24 +36,5 @@ in
        ExecStop = "${alsa-utils}/sbin/alsactl store --ignore";
      };
    };

    services.actkbd = mkIf config.sound.mediaKeys.enable {
      enable = true;
      bindings = [
        # "Mute" media key
        { keys = [ 113 ]; events = [ "key" ];       command = "${alsa-utils}/bin/amixer -q set Master toggle"; }

        # "Lower Volume" media key
        { keys = [ 114 ]; events = [ "key" "rep" ]; command = "${alsa-utils}/bin/amixer -q set Master ${config.sound.mediaKeys.volumeStep}- unmute"; }

        # "Raise Volume" media key
        { keys = [ 115 ]; events = [ "key" "rep" ]; command = "${alsa-utils}/bin/amixer -q set Master ${config.sound.mediaKeys.volumeStep}+ unmute"; }

        # "Mic Mute" media key
        { keys = [ 190 ]; events = [ "key" ];       command = "${alsa-utils}/bin/amixer -q set Capture toggle"; }
      ];
  };

  };

}
Loading