Skip to content

Commit ade1858

Browse files
committed
apple/t2: replace t2-better-audio with alsa ucm config
Signed-off-by: Sophie Cheung <git@soopy.moe>
1 parent e5f1910 commit ade1858

1 file changed

Lines changed: 42 additions & 33 deletions

File tree

apple/t2/default.nix

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,45 @@
88
let
99
inherit (lib) types;
1010

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+
];
1645
};
1746

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;});
3648

3749
t2Cfg = config.hardware.apple-t2;
38-
3950
in
4051
{
4152
imports = [
@@ -87,28 +98,26 @@ in
8798
);
8899
boot.initrd.kernelModules = [ "t2bce-vhci" ];
89100

90-
services.udev.packages = [ audioFilesUdevRules ];
91-
92101
# For audio and suspend
93102
boot.kernelParams = [
94103
"intel_iommu=on"
95104
"iommu=pt"
96105
"pm_async=off"
97106
];
98107

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;
102115
};
103116

104117
# Make sure post-resume.service exists
105118
powerManagement.enable = true;
106119
}
107120

108-
{
109-
services.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/";
110-
}
111-
112121
(lib.mkIf t2Cfg.enableIGPU {
113122
# Enable the iGPU by default if present
114123
environment.etc."modprobe.d/apple-gmux.conf".text = ''

0 commit comments

Comments
 (0)