2023-08-09 19:36:53 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2022-08-25 15:17:01 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
audioFiles = pkgs.fetchFromGitHub {
|
|
|
|
owner = "kekrby";
|
|
|
|
repo = "t2-better-audio";
|
|
|
|
rev = "e46839a28963e2f7d364020518b9dac98236bcae";
|
|
|
|
hash = "sha256-x7K0qa++P1e1vuCGxnsFxL1d9+nwMtZUJ6Kd9e27TFs=";
|
|
|
|
};
|
|
|
|
|
2023-12-25 21:57:09 +00:00
|
|
|
audioFilesUdevRules = pkgs.runCommand "audio-files-udev-rules" {} ''
|
|
|
|
mkdir -p $out/lib/udev/rules.d
|
|
|
|
cp ${audioFiles}/files/*.rules $out/lib/udev/rules.d
|
|
|
|
substituteInPlace $out/lib/udev/rules.d/*.rules --replace "/usr/bin/sed" "${pkgs.gnused}/bin/sed"
|
|
|
|
'';
|
|
|
|
|
2022-08-25 15:17:01 +00:00
|
|
|
overrideAudioFiles = package: pluginsPath:
|
|
|
|
package.overrideAttrs (new: old: {
|
|
|
|
preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ];
|
|
|
|
postPatchPhase = ''
|
|
|
|
cp -r ${audioFiles}/files/{profile-sets,paths} ${pluginsPath}/alsa/mixer/
|
|
|
|
'';
|
|
|
|
});
|
2023-08-09 19:36:53 +00:00
|
|
|
|
|
|
|
pipewirePackage = overrideAudioFiles pkgs.pipewire "spa/plugins/";
|
|
|
|
|
2024-04-12 21:01:44 +00:00
|
|
|
tiny-dfrPackage = pkgs.callPackage ./pkgs/tiny-dfr.nix { };
|
|
|
|
|
2023-12-25 21:57:09 +00:00
|
|
|
apple-set-os-loader-installer = pkgs.stdenv.mkDerivation {
|
2023-08-09 19:36:53 +00:00
|
|
|
name = "apple-set-os-loader-installer-1.0";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "Redecorating";
|
|
|
|
repo = "apple_set_os-loader";
|
|
|
|
rev = "r33.9856dc4";
|
|
|
|
sha256 = "hvwqfoF989PfDRrwU0BMi69nFjPeOmSaD6vR6jIRK2Y=";
|
|
|
|
};
|
|
|
|
buildInputs = [ pkgs.gnu-efi ];
|
|
|
|
buildPhase = ''
|
|
|
|
substituteInPlace Makefile --replace "/usr" '$(GNU_EFI)'
|
|
|
|
export GNU_EFI=${pkgs.gnu-efi}
|
|
|
|
make
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
install -D bootx64_silent.efi $out/bootx64.efi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-09-11 20:45:11 +00:00
|
|
|
t2Cfg = config.hardware.apple-t2;
|
2023-08-09 19:36:53 +00:00
|
|
|
|
2022-08-25 15:17:01 +00:00
|
|
|
in
|
|
|
|
{
|
2023-08-09 19:36:53 +00:00
|
|
|
options = {
|
2023-09-11 20:45:11 +00:00
|
|
|
hardware.apple-t2.enableAppleSetOsLoader = lib.mkOption {
|
2023-08-09 19:36:53 +00:00
|
|
|
default = false;
|
|
|
|
type = lib.types.bool;
|
|
|
|
description = "Whether to enable the appleSetOsLoader activation script.";
|
|
|
|
};
|
|
|
|
};
|
2022-08-25 15:17:01 +00:00
|
|
|
|
2023-08-09 19:36:53 +00:00
|
|
|
config = {
|
|
|
|
# For keyboard and touchbar
|
2023-12-25 21:57:09 +00:00
|
|
|
boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { });
|
2023-08-09 19:36:53 +00:00
|
|
|
boot.initrd.kernelModules = [ "apple-bce" ];
|
2022-08-25 15:17:01 +00:00
|
|
|
|
2024-04-12 21:01:44 +00:00
|
|
|
services.udev.packages = [ audioFilesUdevRules tiny-dfrPackage ];
|
|
|
|
|
2023-08-09 19:36:53 +00:00
|
|
|
# For audio
|
|
|
|
boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ];
|
2022-08-25 15:17:01 +00:00
|
|
|
|
2023-08-09 19:36:53 +00:00
|
|
|
hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/";
|
2022-08-25 15:17:01 +00:00
|
|
|
|
2023-08-09 19:36:53 +00:00
|
|
|
services.pipewire.package = pipewirePackage;
|
|
|
|
services.pipewire.wireplumber.package = pkgs.wireplumber.override {
|
|
|
|
pipewire = pipewirePackage;
|
|
|
|
};
|
|
|
|
|
2024-04-12 21:01:44 +00:00
|
|
|
# For tiny-dfr
|
|
|
|
systemd.services.tiny-dfr = {
|
|
|
|
enable = true;
|
|
|
|
description = "Tiny Apple silicon touch bar daemon";
|
|
|
|
after = [ "systemd-user-sessions.service" "getty@tty1.service" "plymouth-quit.service" "systemd-logind.service" ];
|
|
|
|
bindsTo = [ "dev-tiny_dfr_display.device" "dev-tiny_dfr_backlight.device" ];
|
|
|
|
startLimitIntervalSec = 30;
|
|
|
|
startLimitBurst = 2;
|
|
|
|
script = "${tiny-dfrPackage}/bin/tiny-dfr";
|
|
|
|
restartTriggers = [ tiny-dfrPackage ];
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."tiny-dfr/config.toml" = {
|
|
|
|
source = "${tiny-dfrPackage}/share/tiny-dfr/config.toml";
|
|
|
|
};
|
|
|
|
|
2023-08-09 19:36:53 +00:00
|
|
|
# Make sure post-resume.service exists
|
|
|
|
powerManagement.enable = true;
|
|
|
|
|
2023-09-08 21:42:32 +00:00
|
|
|
# Activation script to install apple-set-os-loader in order to unlock the iGPU
|
2023-08-09 19:36:53 +00:00
|
|
|
system.activationScripts.appleSetOsLoader = lib.optionalString t2Cfg.enableAppleSetOsLoader ''
|
2023-09-08 21:42:32 +00:00
|
|
|
if [[ -e /boot/efi/efi/boot/bootx64_original.efi ]]; then
|
2023-08-09 19:36:53 +00:00
|
|
|
true # It's already installed, no action required
|
2023-09-08 21:42:32 +00:00
|
|
|
elif [[ -e /boot/efi/efi/boot/bootx64.efi ]]; then
|
|
|
|
# Copy the new bootloader to a temporary location
|
|
|
|
cp ${apple-set-os-loader-installer}/bootx64.efi /boot/efi/efi/boot/bootx64_temp.efi
|
|
|
|
|
|
|
|
# Rename the original bootloader
|
|
|
|
mv /boot/efi/efi/boot/bootx64.efi /boot/efi/efi/boot/bootx64_original.efi
|
|
|
|
|
|
|
|
# Move the new bootloader to the final destination
|
|
|
|
mv /boot/efi/efi/boot/bootx64_temp.efi /boot/efi/efi/boot/bootx64.efi
|
2023-08-09 19:36:53 +00:00
|
|
|
else
|
2023-09-08 21:42:32 +00:00
|
|
|
echo "Error: /boot/efi/efi/boot/bootx64.efi is missing" >&2
|
2023-08-09 19:36:53 +00:00
|
|
|
fi
|
|
|
|
'';
|
2023-09-08 23:37:04 +00:00
|
|
|
|
|
|
|
# Enable the iGPU by default if present
|
|
|
|
environment.etc."modprobe.d/apple-gmux.conf".text = lib.optionalString t2Cfg.enableAppleSetOsLoader ''
|
|
|
|
options apple-gmux force_igd=y
|
|
|
|
'';
|
2022-08-25 15:17:01 +00:00
|
|
|
};
|
|
|
|
}
|