1
0
Fork 0
mirror of https://github.com/NixOS/nixos-hardware synced 2024-11-23 03:19:42 +01:00

apple/t2: add tiny-dfr option

This commit is contained in:
Reid "reidlab 2024-10-10 17:30:57 -07:00 committed by mergify[bot]
parent ca0662edb0
commit 6f71da566f

View file

@ -49,71 +49,82 @@ let
in in
{ {
options = { options.hardware.apple-t2 = {
hardware.apple-t2.enableAppleSetOsLoader = lib.mkOption { enableAppleSetOsLoader = lib.mkOption {
default = false; default = false;
type = lib.types.bool; type = lib.types.bool;
description = "Whether to enable the appleSetOsLoader activation script."; description = "Whether to enable the appleSetOsLoader activation script.";
}; };
enableTinyDfr = lib.mkOption {
default = true;
type = lib.types.bool;
description = "Whether to enable the tiny-dfr touchbar service.";
};
}; };
config = { config = lib.mkMerge [
# For keyboard and touchbar {
boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { }); # For keyboard and touchbar
boot.initrd.kernelModules = [ "apple-bce" ]; boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { });
boot.initrd.kernelModules = [ "apple-bce" ];
services.udev.packages = [ audioFilesUdevRules tiny-dfrPackage ]; services.udev.packages = [ audioFilesUdevRules ];
# For audio # For audio
boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ]; boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ];
hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/";
services.pipewire.package = pipewirePackage; services.pipewire.package = pipewirePackage;
services.pipewire.wireplumber.package = pkgs.wireplumber.override { services.pipewire.wireplumber.package = pkgs.wireplumber.override {
pipewire = pipewirePackage; pipewire = pipewirePackage;
}; };
# For tiny-dfr # Make sure post-resume.service exists
systemd.services.tiny-dfr = { powerManagement.enable = true;
enable = true; }
description = "Tiny Apple silicon touch bar daemon"; (lib.mkIf t2Cfg.enableAppleSetOsLoader {
after = [ "systemd-user-sessions.service" "getty@tty1.service" "plymouth-quit.service" "systemd-logind.service" ]; # Activation script to install apple-set-os-loader in order to unlock the iGPU
bindsTo = [ "dev-tiny_dfr_display.device" "dev-tiny_dfr_backlight.device" ]; system.activationScripts.appleSetOsLoader = ''
startLimitIntervalSec = 30; if [[ -e /boot/efi/efi/boot/bootx64_original.efi ]]; then
startLimitBurst = 2; true # It's already installed, no action required
script = "${tiny-dfrPackage}/bin/tiny-dfr"; elif [[ -e /boot/efi/efi/boot/bootx64.efi ]]; then
restartTriggers = [ tiny-dfrPackage ]; # Copy the new bootloader to a temporary location
}; cp ${apple-set-os-loader-installer}/bootx64.efi /boot/efi/efi/boot/bootx64_temp.efi
environment.etc."tiny-dfr/config.toml" = { # Rename the original bootloader
source = "${tiny-dfrPackage}/share/tiny-dfr/config.toml"; mv /boot/efi/efi/boot/bootx64.efi /boot/efi/efi/boot/bootx64_original.efi
};
# Make sure post-resume.service exists # Move the new bootloader to the final destination
powerManagement.enable = true; mv /boot/efi/efi/boot/bootx64_temp.efi /boot/efi/efi/boot/bootx64.efi
else
echo "Error: /boot/efi/efi/boot/bootx64.efi is missing" >&2
fi
'';
# Activation script to install apple-set-os-loader in order to unlock the iGPU # Enable the iGPU by default if present
system.activationScripts.appleSetOsLoader = lib.optionalString t2Cfg.enableAppleSetOsLoader '' environment.etc."modprobe.d/apple-gmux.conf".text = ''
if [[ -e /boot/efi/efi/boot/bootx64_original.efi ]]; then options apple-gmux force_igd=y
true # It's already installed, no action required '';
elif [[ -e /boot/efi/efi/boot/bootx64.efi ]]; then })
# Copy the new bootloader to a temporary location (lib.mkIf t2Cfg.enableTinyDfr {
cp ${apple-set-os-loader-installer}/bootx64.efi /boot/efi/efi/boot/bootx64_temp.efi services.udev.packages = [ tiny-dfrPackage ];
# Rename the original bootloader systemd.services.tiny-dfr = {
mv /boot/efi/efi/boot/bootx64.efi /boot/efi/efi/boot/bootx64_original.efi 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 ];
};
# Move the new bootloader to the final destination environment.etc."tiny-dfr/config.toml" = {
mv /boot/efi/efi/boot/bootx64_temp.efi /boot/efi/efi/boot/bootx64.efi source = "${tiny-dfrPackage}/share/tiny-dfr/config.toml";
else };
echo "Error: /boot/efi/efi/boot/bootx64.efi is missing" >&2 })
fi ];
'';
# 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
'';
};
} }