From 991534337080ff5955820b36d8b3bd0f93afe571 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 25 Dec 2023 01:12:03 +0800 Subject: [PATCH] fix: nixos-hardware's apple-t2 hardcoded some path --- .../shoukei/apple-set-os-loader.nix | 61 +++++++++++++++++++ hosts/12kingdoms/shoukei/default.nix | 3 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 hosts/12kingdoms/shoukei/apple-set-os-loader.nix diff --git a/hosts/12kingdoms/shoukei/apple-set-os-loader.nix b/hosts/12kingdoms/shoukei/apple-set-os-loader.nix new file mode 100644 index 00000000..ceaff3b3 --- /dev/null +++ b/hosts/12kingdoms/shoukei/apple-set-os-loader.nix @@ -0,0 +1,61 @@ +{ + pkgs, + config, + lib, + ... +}: let + t2Cfg = config.hardware.myapple-t2; + efiPrefix = config.boot.loader.efi.efiSysMountPoint; + + 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 { + options = { + hardware.myapple-t2.enableAppleSetOsLoader = lib.mkOption { + default = false; + type = lib.types.bool; + description = "Whether to enable the appleSetOsLoader activation script."; + }; + }; + + config = { + # Activation script to install apple-set-os-loader in order to unlock the iGPU + system.activationScripts.myappleSetOsLoader = lib.optionalString t2Cfg.enableAppleSetOsLoader '' + if [[ -e ${efiPrefix}/efi/boot/bootx64_original.efi ]]; then + true # It's already installed, no action required + elif [[ -e ${efiPrefix}/efi/boot/bootx64.efi ]]; then + # Copy the new bootloader to a temporary location + cp ${apple-set-os-loader-installer}/bootx64.efi ${efiPrefix}/efi/boot/bootx64_temp.efi + + # Rename the original bootloader + mv ${efiPrefix}/efi/boot/bootx64.efi ${efiPrefix}/efi/boot/bootx64_original.efi + + # Move the new bootloader to the final destination + mv ${efiPrefix}/efi/boot/bootx64_temp.efi ${efiPrefix}/efi/boot/bootx64.efi + else + echo "Error: ${efiPrefix}/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 + ''; + }; +} diff --git a/hosts/12kingdoms/shoukei/default.nix b/hosts/12kingdoms/shoukei/default.nix index ec8ba49d..b4b3efcb 100644 --- a/hosts/12kingdoms/shoukei/default.nix +++ b/hosts/12kingdoms/shoukei/default.nix @@ -12,7 +12,8 @@ { imports = [ nixos-hardware.nixosModules.apple-t2 - {hardware.apple-t2.enableAppleSetOsLoader = true;} + ./apple-set-os-loader.nix + {hardware.myapple-t2.enableAppleSetOsLoader = true;} ./hardware-configuration.nix ./impermanence.nix