|
8 | 8 | let |
9 | 9 | inherit (lib) types; |
10 | 10 |
|
11 | | - audioFiles = pkgs.fetchFromGitHub { |
12 | | - owner = "kekrby"; |
13 | | - repo = "t2-better-audio"; |
14 | | - rev = "e46839a28963e2f7d364020518b9dac98236bcae"; |
15 | | - hash = "sha256-x7K0qa++P1e1vuCGxnsFxL1d9+nwMtZUJ6Kd9e27TFs="; |
| 11 | + t2bce-alsa-ucm = pkgs.stdenvNoCC.mkDerivation (_: { |
| 12 | + name = "t2bce-alsa-ucm"; |
| 13 | + src = pkgs.fetchFromGitHub { |
| 14 | + owner = "deqrocks"; |
| 15 | + repo = "t2bce"; |
| 16 | + rev = "967465dc67d3a9b1e48dea620f7258baa526f4f2"; |
| 17 | + hash = "sha256-EVUvNg30bFhJCtcyPAGbWjGX0+CORs4nWG5Bpvbr590="; |
| 18 | + }; |
| 19 | + |
| 20 | + meta = { |
| 21 | + description = "ALSA Usage Configuration Manager configuration for T2 Macs"; |
| 22 | + license = lib.licenses.mit; |
| 23 | + }; |
| 24 | + |
| 25 | + dontBuild = true; |
| 26 | + |
| 27 | + installPhase = '' |
| 28 | + runHook preInstall |
| 29 | +
|
| 30 | + cd ./t2bce_audio-alsa-ucm-conf |
| 31 | + mkdir -p "$out/share/alsa/" |
| 32 | + cp -vR ./ucm2 "$out/share/alsa/" |
| 33 | +
|
| 34 | + runHook postInstall |
| 35 | + ''; |
| 36 | + }); |
| 37 | + |
| 38 | + patched-alsa-ucm = pkgs.symlinkJoin { |
| 39 | + inherit (t2bce-alsa-ucm) src meta ; |
| 40 | + name = "t2bce-alsa-ucm-patched"; |
| 41 | + paths = [ |
| 42 | + pkgs.alsa-ucm-conf |
| 43 | + t2bce-alsa-ucm |
| 44 | + ]; |
16 | 45 | }; |
17 | 46 |
|
18 | | - audioFilesUdevRules = pkgs.runCommand "audio-files-udev-rules" { } '' |
19 | | - mkdir -p $out/lib/udev/rules.d |
20 | | - cp ${audioFiles}/files/*.rules $out/lib/udev/rules.d |
21 | | - substituteInPlace $out/lib/udev/rules.d/*.rules --replace "/usr/bin/sed" "${pkgs.gnused}/bin/sed" |
22 | | - ''; |
23 | | - |
24 | | - overrideAudioFiles = |
25 | | - package: pluginsPath: |
26 | | - package.overrideAttrs ( |
27 | | - _new: old: { |
28 | | - preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ]; |
29 | | - postPatchPhase = '' |
30 | | - cp -r ${audioFiles}/files/{profile-sets,paths} ${pluginsPath}/alsa/mixer/ |
31 | | - ''; |
32 | | - } |
33 | | - ); |
34 | | - |
35 | | - pipewirePackage = overrideAudioFiles pkgs.pipewire "spa/plugins/"; |
| 47 | + patchedAudioAlsaEnv = lib.genAttrs ["pipewire" "wireplumber" "pulseaudio"] (_: {environment.ALSA_CONFIG_UCM2 = config.environment.variables.ALSA_CONFIG_UCM2;}); |
36 | 48 |
|
37 | 49 | t2Cfg = config.hardware.apple-t2; |
38 | | - |
39 | 50 | in |
40 | 51 | { |
41 | 52 | imports = [ |
|
87 | 98 | ); |
88 | 99 | boot.initrd.kernelModules = [ "t2bce-vhci" ]; |
89 | 100 |
|
90 | | - services.udev.packages = [ audioFilesUdevRules ]; |
91 | | - |
92 | 101 | # For audio and suspend |
93 | 102 | boot.kernelParams = [ |
94 | 103 | "intel_iommu=on" |
95 | 104 | "iommu=pt" |
96 | 105 | "pm_async=off" |
97 | 106 | ]; |
98 | 107 |
|
99 | | - services.pipewire.package = pipewirePackage; |
100 | | - services.pipewire.wireplumber.package = pkgs.wireplumber.override { |
101 | | - pipewire = pipewirePackage; |
| 108 | + # audio configuration |
| 109 | + # https://github.com/nix-community/nixos-apple-silicon/blob/66d8dd2c27f99bd5420c99938b60695aac1785c4/apple-silicon-support/modules/sound/default.nix#L46 |
| 110 | + environment.variables.ALSA_CONFIG_UCM2 = "${patched-alsa-ucm}/share/alsa/ucm2"; |
| 111 | + # setting systemd.globalEnvironment is likely going to have unexpected side effects |
| 112 | + systemd = { |
| 113 | + services = patchedAudioAlsaEnv; |
| 114 | + user.services = patchedAudioAlsaEnv; |
102 | 115 | }; |
103 | 116 |
|
104 | 117 | # Make sure post-resume.service exists |
105 | 118 | powerManagement.enable = true; |
106 | 119 | } |
107 | 120 |
|
108 | | - { |
109 | | - services.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; |
110 | | - } |
111 | | - |
112 | 121 | (lib.mkIf t2Cfg.enableIGPU { |
113 | 122 | # Enable the iGPU by default if present |
114 | 123 | environment.etc."modprobe.d/apple-gmux.conf".text = '' |
|
0 commit comments