feat: add installer for apple-set-os-loader-installer

This commit is contained in:
Olof Sandell 2023-08-07 21:55:09 +02:00 committed by Jörg Thalheim
parent 128c044298
commit bb215e68e5
2 changed files with 71 additions and 1 deletions

View file

@ -1,4 +1,4 @@
## NixOS on T2 Macs
# NixOS on T2 Macs
This is the `nixos-hardware` module of the [T2 Linux Project](https://t2linux.org).
@ -7,3 +7,32 @@ Overall, most features (WiFi, bluetooth, audio, touchbar, ...) of Macs are suppo
Following [this guide](https://wiki.t2linux.org/distributions/nixos/installation/) is the recommended way to install, as it incudes the extra things you have to do on a T2 Mac.
You can consult the [wiki](https://wiki.t2linux.org/) for information specific to T2 Macs.
## 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.
### What it Does:
Upon activation, this module performs the following:
- Renames the existing `BOOTX64.EFI` file to `bootx64_original.efi`.
- Installs the `apple-set-os-loader` hook in its place as `bootx64.efi`.
- Before the system boots the hook unlocks the iGPU and subsequently calls the original `bootx64_original.efi`.
### How to Implement:
1. **Integrate the apple-set-os-loader installer** into your `configuration.nix`:
```
imports = [
...
"${builtins.fetchGit { url = "https://github.com/NixOS/nixos-hardware.git"; }}/apple/t2/apple-set-os-loader-installer.nix"
];
```
2. **Rebuild your system**:
```
sudo nixos-rebuild switch
```
> **Note**: Always ensure compatibility and make backups of your data before making any system changes.

View file

@ -0,0 +1,41 @@
{ 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 ];
}