|
| 1 | +{ pkgs, ... }: |
| 2 | + |
| 3 | +let |
| 4 | + audioFiles = pkgs.fetchFromGitHub { |
| 5 | + owner = "kekrby"; |
| 6 | + repo = "t2-better-audio"; |
| 7 | + rev = "e46839a28963e2f7d364020518b9dac98236bcae"; |
| 8 | + hash = "sha256-x7K0qa++P1e1vuCGxnsFxL1d9+nwMtZUJ6Kd9e27TFs="; |
| 9 | + }; |
| 10 | + |
| 11 | + overrideAudioFiles = package: pluginsPath: |
| 12 | + package.overrideAttrs (new: old: { |
| 13 | + preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ]; |
| 14 | + |
| 15 | + postPatchPhase = '' |
| 16 | + cp -r ${audioFiles}/files/{profile-sets,paths} ${pluginsPath}/alsa/mixer/ |
| 17 | + ''; |
| 18 | + }); |
| 19 | +in |
| 20 | +{ |
| 21 | + # For keyboard and touchbar |
| 22 | + boot.kernelPackages = with pkgs; recurseIntoAttrs (linuxPackagesFor (callPackage ./pkgs/linux-t2.nix { })); |
| 23 | + boot.initrd.kernelModules = [ "apple-bce" ]; |
| 24 | + |
| 25 | + # For audio |
| 26 | + boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ]; |
| 27 | + services.udev.extraRules = builtins.readFile (pkgs.substitute { |
| 28 | + src = "${audioFiles}/files/91-audio-custom.rules"; |
| 29 | + replacements = [ "--replace" "/usr/bin/sed" "${pkgs.gnused}/bin/sed" ]; |
| 30 | + }); |
| 31 | + |
| 32 | + hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; |
| 33 | + |
| 34 | + services.pipewire = rec { |
| 35 | + package = overrideAudioFiles pkgs.pipewire "spa/plugins/"; |
| 36 | + |
| 37 | + wireplumber.package = pkgs.wireplumber.override { |
| 38 | + pipewire = package; |
| 39 | + }; |
| 40 | + }; |
| 41 | + |
| 42 | + # Make sure post-resume.service exists |
| 43 | + powerManagement.enable = true; |
| 44 | + |
| 45 | + systemd.services.fix-keyboard-backlight-and-touchbar = { |
| 46 | + path = [ pkgs.kmod ]; |
| 47 | + serviceConfig.ExecStart = ''${pkgs.systemd}/bin/systemd-inhibit --what=sleep --why="fixing keyboard backlight and touchbar must finish before sleep" --mode=delay ${./fix-keyboard-backlight-and-touchbar.sh}''; |
| 48 | + serviceConfig.Type = "oneshot"; |
| 49 | + description = "reload touchbar driver and restart upower"; |
| 50 | + # must run at boot (and not too early), and after suspend |
| 51 | + wantedBy = [ "display-manager.service" "post-resume.target" ]; |
| 52 | + # prevent running before suspend |
| 53 | + after = [ "post-resume.target" ]; |
| 54 | + }; |
| 55 | +} |
0 commit comments