feat: integrate into t2 module

This commit is contained in:
Olof Sandell 2023-08-09 21:36:53 +02:00 committed by Jörg Thalheim
parent bb215e68e5
commit c8cd4f7ef4
3 changed files with 74 additions and 78 deletions

View file

@ -10,7 +10,7 @@ You can consult the [wiki](https://wiki.t2linux.org/) for information specific t
## Unlocking Internal iGPU ## Unlocking Internal iGPU
The `apple-set-os-loader-installer.nix` module serves as an installer for the [`apple-set-os-loader`](https://github.com/Redecorating/apple_set_os-loader). This tool is designed to unlock the internal integrated GPU (iGPU) on certain MacBooks. See https://wiki.t2linux.org/guides/hybrid-graphics/ for more details. The `apple-set-os-loader-installer` module serves as an installer for the [`apple-set-os-loader`](https://github.com/Redecorating/apple_set_os-loader). This tool is designed to unlock the internal integrated GPU (iGPU) on certain MacBooks. See https://wiki.t2linux.org/guides/hybrid-graphics/ for more details.
### What it Does: ### What it Does:
@ -22,12 +22,9 @@ Upon activation, this module performs the following:
### How to Implement: ### How to Implement:
1. **Integrate the apple-set-os-loader installer** into your `configuration.nix`: 1. Add this into your `configuration.nix`:
``` ```
imports = [ appleT2Config.enableAppleSetOsLoader = true;
...
"${builtins.fetchGit { url = "https://github.com/NixOS/nixos-hardware.git"; }}/apple/t2/apple-set-os-loader-installer.nix"
];
``` ```
2. **Rebuild your system**: 2. **Rebuild your system**:

View file

@ -1,41 +0,0 @@
{ config, pkgs, ... }:
let
apple-set-os-loader-installer = pkgs.stdenv.mkDerivation rec {
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
'';
};
in
{
system.activationScripts.hybrid-graphics = {
text = ''
if [[ -e /boot/efi/EFI/BOOT/bootx64_original.efi ]]; then
# We interpret this as apple-set-os-loader being already installed
exit 0
elif [[ -e /boot/efi/EFI/BOOT/BOOTX64.EFI ]] then
mv /boot/efi/EFI/BOOT/BOOTX64.EFI /boot/efi/EFI/BOOT/bootx64_original.efi
cp ${apple-set-os-loader-installer}/bootx64.efi /boot/efi/EFI/BOOT/bootx64.efi
else
echo "Error: /boot/efi/EFI/BOOT/BOOTX64.EFI is missing"
fi
'';
};
environment.etc."modprobe.d/apple-gmux.conf".text = ''
# Enable the iGPU by default if present
options apple-gmux force_igd=y
'';
environment.systemPackages = with pkgs; [ apple-set-os-loader-installer ];
}

View file

@ -1,4 +1,4 @@
{ pkgs, ... }: { config, lib, pkgs, ... }:
let let
audioFiles = pkgs.fetchFromGitHub { audioFiles = pkgs.fetchFromGitHub {
@ -11,13 +11,45 @@ let
overrideAudioFiles = package: pluginsPath: overrideAudioFiles = package: pluginsPath:
package.overrideAttrs (new: old: { package.overrideAttrs (new: old: {
preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ]; preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ];
postPatchPhase = '' postPatchPhase = ''
cp -r ${audioFiles}/files/{profile-sets,paths} ${pluginsPath}/alsa/mixer/ cp -r ${audioFiles}/files/{profile-sets,paths} ${pluginsPath}/alsa/mixer/
''; '';
}); });
pipewirePackage = overrideAudioFiles pkgs.pipewire "spa/plugins/";
apple-set-os-loader-installer = pkgs.stdenv.mkDerivation rec {
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
'';
};
t2Cfg = config.appleT2Config;
in in
{ {
options = {
appleT2Config.enableAppleSetOsLoader = lib.mkOption {
default = false;
type = lib.types.bool;
description = "Whether to enable the appleSetOsLoader activation script.";
};
};
config = {
# For keyboard and touchbar # For keyboard and touchbar
boot.kernelPackages = with pkgs; recurseIntoAttrs (linuxPackagesFor (callPackage ./pkgs/linux-t2.nix { })); boot.kernelPackages = with pkgs; recurseIntoAttrs (linuxPackagesFor (callPackage ./pkgs/linux-t2.nix { }));
boot.initrd.kernelModules = [ "apple-bce" ]; boot.initrd.kernelModules = [ "apple-bce" ];
@ -31,12 +63,9 @@ in
hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/";
services.pipewire = rec { services.pipewire.package = pipewirePackage;
package = overrideAudioFiles pkgs.pipewire "spa/plugins/"; services.pipewire.wireplumber.package = pkgs.wireplumber.override {
pipewire = pipewirePackage;
wireplumber.package = pkgs.wireplumber.override {
pipewire = package;
};
}; };
# Make sure post-resume.service exists # Make sure post-resume.service exists
@ -47,9 +76,20 @@ in
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}''; 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}'';
serviceConfig.Type = "oneshot"; serviceConfig.Type = "oneshot";
description = "reload touchbar driver and restart upower"; description = "reload touchbar driver and restart upower";
# must run at boot (and not too early), and after suspend
wantedBy = [ "display-manager.service" "post-resume.target" ]; wantedBy = [ "display-manager.service" "post-resume.target" ];
# prevent running before suspend
after = [ "post-resume.target" ]; after = [ "post-resume.target" ];
}; };
# Activation script to install apple-set-os-loader in order to unlock the iGPU
system.activationScripts.appleSetOsLoader = lib.optionalString t2Cfg.enableAppleSetOsLoader ''
if [[ -e /boot/efi/EFI/BOOT/bootx64_original.efi ]]; then
true # It's already installed, no action required
elif [[ -e /boot/efi/EFI/BOOT/BOOTX64.EFI ]]; then
mv /boot/efi/EFI/BOOT/BOOTX64.EFI /boot/efi/EFI/BOOT/bootx64_original.efi
cp ${apple-set-os-loader-installer}/bootx64.efi /boot/efi/EFI/BOOT/bootx64.efi
else
echo "Error: /boot/efi/EFI/BOOT/BOOTX64.EFI is missing" >&2
fi
'';
};
} }