From 3eeff54780a1a8c73c82ca51987962b62bd4219e Mon Sep 17 00:00:00 2001 From: K900 Date: Sat, 13 Jul 2024 13:56:18 +0300 Subject: [PATCH] nixos/alsa: kill sound.enable and friends with fire --- .../profiles/headless.section.md | 3 +- .../configuration/profiles/minimal.section.md | 3 +- .../manual/release-notes/rl-2411.section.md | 45 ++++++ nixos/modules/config/pulseaudio.nix | 10 +- nixos/modules/services/audio/alsa.nix | 138 +++--------------- nixos/modules/services/audio/jack.nix | 4 +- .../vagrant-virtualbox-image.nix | 1 - nixos/tests/domination.nix | 1 - nixos/tests/firefox.nix | 3 +- nixos/tests/ft2-clone.nix | 2 - nixos/tests/login.nix | 1 - nixos/tests/mpd.nix | 1 - nixos/tests/pt2-clone.nix | 1 - nixos/tests/sfxr-qt.nix | 1 - nixos/tests/shattered-pixel-dungeon.nix | 1 - nixos/tests/slimserver.nix | 3 +- nixos/tests/systemd-analyze.nix | 1 - .../nix/nixos-option/src/nixos-option.cc | 2 +- 18 files changed, 77 insertions(+), 144 deletions(-) diff --git a/nixos/doc/manual/configuration/profiles/headless.section.md b/nixos/doc/manual/configuration/profiles/headless.section.md index d185a9a774b7..6b84bb7d5cc9 100644 --- a/nixos/doc/manual/configuration/profiles/headless.section.md +++ b/nixos/doc/manual/configuration/profiles/headless.section.md @@ -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. diff --git a/nixos/doc/manual/configuration/profiles/minimal.section.md b/nixos/doc/manual/configuration/profiles/minimal.section.md index 02a3b65ae422..76d9585a0bd3 100644 --- a/nixos/doc/manual/configuration/profiles/minimal.section.md +++ b/nixos/doc/manual/configuration/profiles/minimal.section.md @@ -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). diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index 7799d94004ab..dd8bf4b4695d 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -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..authenticationTokenConfigFile` instead of the former {option}`services.gitlab-runner.services..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"; } + ]; +}; +``` diff --git a/nixos/modules/config/pulseaudio.nix b/nixos/modules/config/pulseaudio.nix index 7c3a284e8780..27c164a9a6dc 100644 --- a/nixos/modules/config/pulseaudio.nix +++ b/nixos/modules/config/pulseaudio.nix @@ -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); diff --git a/nixos/modules/services/audio/alsa.nix b/nixos/modules/services/audio/alsa.nix index b002cb1274ac..47cf094d8c74 100644 --- a/nixos/modules/services/audio/alsa.nix +++ b/nixos/modules/services/audio/alsa.nix @@ -3,132 +3,38 @@ 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 { - 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`. - ''; - }; - - 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. - ''; - }; - - }; - - }; - + options.hardware.alsa.enablePersistence = mkOption { + type = types.bool; + default = false; + description = '' + Whether to enable ALSA sound card state saving on shutdown. + This is generally not necessary if you're using an external sound server. + ''; }; - - ###### 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"; - wantedBy = [ "multi-user.target" ]; - unitConfig.RequiresMountsFor = "/var/lib/alsa"; - unitConfig.ConditionVirtualization = "!systemd-nspawn"; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa"; - ExecStart = "${alsa-utils}/sbin/alsactl restore --ignore"; - ExecStop = "${alsa-utils}/sbin/alsactl store --ignore"; - }; + systemd.services.alsa-store = { + description = "Store Sound Card State"; + wantedBy = [ "multi-user.target" ]; + unitConfig = { + RequiresMountsFor = "/var/lib/alsa"; + ConditionVirtualization = "!systemd-nspawn"; + }; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib/alsa"; + ExecStart = "${alsa-utils}/sbin/alsactl restore --ignore"; + 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"; } - ]; }; - }; - } diff --git a/nixos/modules/services/audio/jack.nix b/nixos/modules/services/audio/jack.nix index 20ba091542fe..a5cb0da29592 100644 --- a/nixos/modules/services/audio/jack.nix +++ b/nixos/modules/services/audio/jack.nix @@ -122,7 +122,7 @@ in { config = mkMerge [ (mkIf pcmPlugin { - sound.extraConfig = '' + environment.etc."alsa/conf.d/98-jack.conf".text = '' pcm_type.jack { libs.native = ${pkgs.alsa-plugins}/lib/alsa-lib/libasound_module_pcm_jack.so ; ${lib.optionalString enable32BitAlsaPlugins @@ -139,7 +139,7 @@ in { (mkIf loopback { boot.kernelModules = [ "snd-aloop" ]; boot.kernelParams = [ "snd-aloop.index=${toString cfg.loopback.index}" ]; - sound.extraConfig = cfg.loopback.config; + environment.etc."alsa/conf.d/99-jack-loopback.conf".text = cfg.loopback.config; }) (mkIf cfg.jackd.enable { diff --git a/nixos/modules/virtualisation/vagrant-virtualbox-image.nix b/nixos/modules/virtualisation/vagrant-virtualbox-image.nix index 2a921894ab61..556228436b99 100644 --- a/nixos/modules/virtualisation/vagrant-virtualbox-image.nix +++ b/nixos/modules/virtualisation/vagrant-virtualbox-image.nix @@ -15,7 +15,6 @@ usb = "off"; usbehci = "off"; }; - sound.enable = false; documentation.man.enable = false; documentation.nixos.enable = false; diff --git a/nixos/tests/domination.nix b/nixos/tests/domination.nix index 9e4badd2e369..04899c506531 100644 --- a/nixos/tests/domination.nix +++ b/nixos/tests/domination.nix @@ -10,7 +10,6 @@ import ./make-test-python.nix ({ pkgs, ... }: { ]; services.xserver.enable = true; - sound.enable = true; environment.systemPackages = [ pkgs.domination ]; }; diff --git a/nixos/tests/firefox.nix b/nixos/tests/firefox.nix index 6418e029f80d..8243defbb9f2 100644 --- a/nixos/tests/firefox.nix +++ b/nixos/tests/firefox.nix @@ -21,8 +21,7 @@ import ./make-test-python.nix ({ lib, pkgs, firefoxPackage, ... }: # Create a virtual sound device, with mixing # and all, for recording audio. boot.kernelModules = [ "snd-aloop" ]; - sound.enable = true; - sound.extraConfig = '' + environment.etc."asound.conf".text = '' pcm.!default { type plug slave.pcm pcm.dmixer diff --git a/nixos/tests/ft2-clone.nix b/nixos/tests/ft2-clone.nix index 5476b38c00bd..813e258cd2be 100644 --- a/nixos/tests/ft2-clone.nix +++ b/nixos/tests/ft2-clone.nix @@ -8,8 +8,6 @@ import ./make-test-python.nix ({ pkgs, ... }: { imports = [ ./common/x11.nix ]; - - sound.enable = true; environment.systemPackages = [ pkgs.ft2-clone ]; }; diff --git a/nixos/tests/login.nix b/nixos/tests/login.nix index bcaee03175ad..e3b1b877940a 100644 --- a/nixos/tests/login.nix +++ b/nixos/tests/login.nix @@ -9,7 +9,6 @@ import ./make-test-python.nix ({ pkgs, latestKernel ? false, ... }: nodes.machine = { pkgs, lib, ... }: { boot.kernelPackages = lib.mkIf latestKernel pkgs.linuxPackages_latest; - sound.enable = true; # needed for the factl test, /dev/snd/* exists without them but udev doesn't care then }; testScript = '' diff --git a/nixos/tests/mpd.nix b/nixos/tests/mpd.nix index 52d9c7fd33a1..0772c05d12ac 100644 --- a/nixos/tests/mpd.nix +++ b/nixos/tests/mpd.nix @@ -37,7 +37,6 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: mkServer = { mpd, musicService, }: { boot.kernelModules = [ "snd-dummy" ]; - sound.enable = true; services.mpd = mpd; systemd.services.musicService = musicService; }; diff --git a/nixos/tests/pt2-clone.nix b/nixos/tests/pt2-clone.nix index ea4329c4a980..57a8495a3296 100644 --- a/nixos/tests/pt2-clone.nix +++ b/nixos/tests/pt2-clone.nix @@ -10,7 +10,6 @@ import ./make-test-python.nix ({ pkgs, ... }: { ]; services.xserver.enable = true; - sound.enable = true; environment.systemPackages = [ pkgs.pt2-clone ]; }; diff --git a/nixos/tests/sfxr-qt.nix b/nixos/tests/sfxr-qt.nix index 976b9b11fc66..cca3e5f3ea76 100644 --- a/nixos/tests/sfxr-qt.nix +++ b/nixos/tests/sfxr-qt.nix @@ -10,7 +10,6 @@ import ./make-test-python.nix ({ pkgs, ... }: { ]; services.xserver.enable = true; - sound.enable = true; environment.systemPackages = [ pkgs.sfxr-qt ]; }; diff --git a/nixos/tests/shattered-pixel-dungeon.nix b/nixos/tests/shattered-pixel-dungeon.nix index b4ac1670b5ca..cabf192c6002 100644 --- a/nixos/tests/shattered-pixel-dungeon.nix +++ b/nixos/tests/shattered-pixel-dungeon.nix @@ -10,7 +10,6 @@ import ./make-test-python.nix ({ pkgs, ... }: { ]; services.xserver.enable = true; - sound.enable = true; environment.systemPackages = [ pkgs.shattered-pixel-dungeon ]; }; diff --git a/nixos/tests/slimserver.nix b/nixos/tests/slimserver.nix index 95cbdcf4a2a1..abc0cd2ef181 100644 --- a/nixos/tests/slimserver.nix +++ b/nixos/tests/slimserver.nix @@ -8,8 +8,7 @@ import ./make-test-python.nix ({ pkgs, ...} : { enable = true; extraArguments = "-s 127.0.0.1 -d slimproto=info"; }; - sound.enable = true; - boot.initrd.kernelModules = ["snd-dummy"]; + boot.kernelModules = ["snd-dummy"]; }; testScript = diff --git a/nixos/tests/systemd-analyze.nix b/nixos/tests/systemd-analyze.nix index 31588e2b41aa..37c20d5fe5b6 100644 --- a/nixos/tests/systemd-analyze.nix +++ b/nixos/tests/systemd-analyze.nix @@ -9,7 +9,6 @@ import ./make-test-python.nix ({ pkgs, latestKernel ? false, ... }: nodes.machine = { pkgs, lib, ... }: { boot.kernelPackages = lib.mkIf latestKernel pkgs.linuxPackages_latest; - sound.enable = true; # needed for the factl test, /dev/snd/* exists without them but udev doesn't care then }; testScript = '' diff --git a/pkgs/tools/nix/nixos-option/src/nixos-option.cc b/pkgs/tools/nix/nixos-option/src/nixos-option.cc index d8c3d46c4fa1..eab727bc1db5 100644 --- a/pkgs/tools/nix/nixos-option/src/nixos-option.cc +++ b/pkgs/tools/nix/nixos-option/src/nixos-option.cc @@ -319,7 +319,7 @@ void mapOptions(const std::function & f, Context } // Calls f on all the config values inside one option. -// Simple options have one config value inside, like sound.enable = true. +// Simple options have one config value inside, like services.foo.enable = true. // Compound options have multiple config values. For example, the option // "users.users" has about 1000 config values inside it: // users.users.avahi.createHome = false;