about summary refs log tree commit diff
path: root/modules/nixos-apple-silicon/apple-silicon-support
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2024-03-01 11:38:33 +0100
committerAlyssa Ross <hi@alyssa.is>2024-03-01 11:38:33 +0100
commit66f707d69f1e423db5a35c2fe43b32781125a9af (patch)
treedf143385065f8e2bfa232e2d7297193158d59892 /modules/nixos-apple-silicon/apple-silicon-support
parente05a4d9a87f3ff3bdf8114ac5a340ad0063f1c73 (diff)
parent9ccf1cb93bdaa96294598bef8a7ffaa72226b0fb (diff)
downloadnixlib-66f707d69f1e423db5a35c2fe43b32781125a9af.tar
nixlib-66f707d69f1e423db5a35c2fe43b32781125a9af.tar.gz
nixlib-66f707d69f1e423db5a35c2fe43b32781125a9af.tar.bz2
nixlib-66f707d69f1e423db5a35c2fe43b32781125a9af.tar.lz
nixlib-66f707d69f1e423db5a35c2fe43b32781125a9af.tar.xz
nixlib-66f707d69f1e423db5a35c2fe43b32781125a9af.tar.zst
nixlib-66f707d69f1e423db5a35c2fe43b32781125a9af.zip
Merge https://github.com/tpwrules/nixos-apple-silicon
Diffstat (limited to 'modules/nixos-apple-silicon/apple-silicon-support')
-rw-r--r--modules/nixos-apple-silicon/apple-silicon-support/modules/sound/default.nix73
-rw-r--r--modules/nixos-apple-silicon/apple-silicon-support/packages/asahi-audio/default.nix14
2 files changed, 62 insertions, 25 deletions
diff --git a/modules/nixos-apple-silicon/apple-silicon-support/modules/sound/default.nix b/modules/nixos-apple-silicon/apple-silicon-support/modules/sound/default.nix
index 98b111237d61..38e412b9e174 100644
--- a/modules/nixos-apple-silicon/apple-silicon-support/modules/sound/default.nix
+++ b/modules/nixos-apple-silicon/apple-silicon-support/modules/sound/default.nix
@@ -1,4 +1,4 @@
-{ config, pkgs, lib, ... }:
+{ config, options, pkgs, lib, ... }:
 
 {
   imports = [
@@ -32,34 +32,57 @@
     })).lsp-plugins-is-patched;
 
     lsp-plugins-is-safe = (pkgs.lib.versionAtLeast lsp-plugins.version "1.2.14") || lsp-plugins-is-patched;
-  in lib.mkIf config.hardware.asahi.setupAsahiSound {
-    # enable pipewire to run real-time and avoid audible glitches
-    security.rtkit.enable = true;
-    # set up pipewire with the supported capabilities (instead of pulseaudio)
-    # and asahi-audio configs and plugins
-    services.pipewire = {
-      enable = true;
-      configPackages = [ asahi-audio ];
-      extraLv2Packages = [ lsp-plugins pkgs.bankstown-lv2 ];
 
-      alsa.enable = true;
-      pulse.enable = true;
-      wireplumber = {
+    # https://github.com/NixOS/nixpkgs/pull/282377
+    # options is the set of all module option declarations, rather than their
+    # values, to prevent infinite recursion
+    newHotness = builtins.hasAttr "configPackages" options.services.pipewire;
+
+    lv2Path = lib.makeSearchPath "lib/lv2" [ lsp-plugins pkgs.bankstown-lv2 ];
+  in lib.mkIf config.hardware.asahi.setupAsahiSound (lib.mkMerge [
+    {
+      # enable pipewire to run real-time and avoid audible glitches
+      security.rtkit.enable = true;
+      # set up pipewire with the supported capabilities (instead of pulseaudio)
+      # and asahi-audio configs and plugins
+      services.pipewire = {
         enable = true;
+
+        alsa.enable = true;
+        pulse.enable = true;
+        wireplumber.enable = true;
+      };
+
+      # set up enivronment so that UCM configs are used as well
+      environment.variables.ALSA_CONFIG_UCM2 = "${pkgs.alsa-ucm-conf-asahi}/share/alsa/ucm2";
+      systemd.user.services.pipewire.environment.ALSA_CONFIG_UCM2 = config.environment.variables.ALSA_CONFIG_UCM2;
+      systemd.user.services.wireplumber.environment.ALSA_CONFIG_UCM2 = config.environment.variables.ALSA_CONFIG_UCM2;
+
+      # enable speakersafetyd to protect speakers
+      systemd.packages = lib.mkAssert lsp-plugins-is-safe
+        "lsp-plugins is unpatched/outdated and speakers cannot be safely enabled"
+        [ pkgs.speakersafetyd ];
+      services.udev.packages = [ pkgs.speakersafetyd ];
+    }
+    (lib.optionalAttrs newHotness {
+      # use configPackages and friends to install asahi-audio and plugins
+      services.pipewire = {
         configPackages = [ asahi-audio ];
         extraLv2Packages = [ lsp-plugins pkgs.bankstown-lv2 ];
+        wireplumber = {
+          configPackages = [ asahi-audio ];
+          extraLv2Packages = [ lsp-plugins pkgs.bankstown-lv2 ];
+        };
       };
-    };
+    })
+    (lib.optionalAttrs (!newHotness) {
+      # use environment.etc and environment variables to install asahi-audio and plugins
+      environment.etc = builtins.listToAttrs (builtins.map
+        (f: { name = f; value = { source = "${asahi-audio}/share/${f}"; }; })
+        asahi-audio.providedConfigFiles);
 
-    # set up enivronment so that UCM configs are used as well
-    environment.variables.ALSA_CONFIG_UCM2 = "${pkgs.alsa-ucm-conf-asahi}/share/alsa/ucm2";
-    systemd.user.services.pipewire.environment.ALSA_CONFIG_UCM2 = config.environment.variables.ALSA_CONFIG_UCM2;
-    systemd.user.services.wireplumber.environment.ALSA_CONFIG_UCM2 = config.environment.variables.ALSA_CONFIG_UCM2;
-
-    # enable speakersafetyd to protect speakers
-    systemd.packages = lib.mkAssert lsp-plugins-is-safe
-      "lsp-plugins is unpatched/outdated and speakers cannot be safely enabled"
-      [ pkgs.speakersafetyd ];
-    services.udev.packages = [ pkgs.speakersafetyd ];
-  };
+      systemd.user.services.pipewire.environment.LV2_PATH = lv2Path;
+      systemd.user.services.wireplumber.environment.LV2_PATH = lv2Path;
+    })
+  ]);
 }
diff --git a/modules/nixos-apple-silicon/apple-silicon-support/packages/asahi-audio/default.nix b/modules/nixos-apple-silicon/apple-silicon-support/packages/asahi-audio/default.nix
index d54c26cb299f..4ccbcc5d066c 100644
--- a/modules/nixos-apple-silicon/apple-silicon-support/packages/asahi-audio/default.nix
+++ b/modules/nixos-apple-silicon/apple-silicon-support/packages/asahi-audio/default.nix
@@ -6,6 +6,7 @@
 stdenv.mkDerivation rec {
   pname = "asahi-audio";
   # tracking: https://src.fedoraproject.org/rpms/asahi-audio
+  # note: ensure that the providedConfigFiles list below is current!
   version = "1.6";
 
   src = fetchFromGitHub {
@@ -34,4 +35,17 @@ stdenv.mkDerivation rec {
     # no need to link the asahi-audio dir globally
     mv $out/share/asahi-audio $out
   '';
+
+  # list of config files installed in $out/share/ and destined for
+  # /etc/, from the `install -pm0644 conf/` lines in the Makefile. note
+  # that the contents of asahi-audio/ stay in $out/ and the config files
+  # are modified to point to them.
+  passthru.providedConfigFiles = [
+    "wireplumber/wireplumber.conf.d/99-asahi.conf"
+    "wireplumber/policy.lua.d/85-asahi-policy.lua"
+    "wireplumber/main.lua.d/85-asahi.lua"
+    "wireplumber/scripts/policy-asahi.lua"
+    "pipewire/pipewire.conf.d/99-asahi.conf"
+    "pipewire/pipewire-pulse.conf.d/99-asahi.conf"
+  ];
 }