|
49 | 49 |
|
50 | 50 | in |
51 | 51 | { |
52 | | - options = { |
53 | | - hardware.apple-t2.enableAppleSetOsLoader = lib.mkOption { |
| 52 | + options.hardware.apple-t2 = { |
| 53 | + enableAppleSetOsLoader = lib.mkOption { |
54 | 54 | default = false; |
55 | 55 | type = lib.types.bool; |
56 | 56 | description = "Whether to enable the appleSetOsLoader activation script."; |
57 | 57 | }; |
58 | | - }; |
59 | | - |
60 | | - config = { |
61 | | - # For keyboard and touchbar |
62 | | - boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { }); |
63 | | - boot.initrd.kernelModules = [ "apple-bce" ]; |
64 | | - |
65 | | - services.udev.packages = [ audioFilesUdevRules tiny-dfrPackage ]; |
66 | | - |
67 | | - # For audio |
68 | | - boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ]; |
69 | | - |
70 | | - hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; |
71 | | - |
72 | | - services.pipewire.package = pipewirePackage; |
73 | | - services.pipewire.wireplumber.package = pkgs.wireplumber.override { |
74 | | - pipewire = pipewirePackage; |
75 | | - }; |
76 | | - |
77 | | - # For tiny-dfr |
78 | | - systemd.services.tiny-dfr = { |
79 | | - enable = true; |
80 | | - description = "Tiny Apple silicon touch bar daemon"; |
81 | | - after = [ "systemd-user-sessions.service" "[email protected]" "plymouth-quit.service" "systemd-logind.service" ]; |
82 | | - bindsTo = [ "dev-tiny_dfr_display.device" "dev-tiny_dfr_backlight.device" ]; |
83 | | - startLimitIntervalSec = 30; |
84 | | - startLimitBurst = 2; |
85 | | - script = "${tiny-dfrPackage}/bin/tiny-dfr"; |
86 | | - restartTriggers = [ tiny-dfrPackage ]; |
87 | | - }; |
88 | 58 |
|
89 | | - environment.etc."tiny-dfr/config.toml" = { |
90 | | - source = "${tiny-dfrPackage}/share/tiny-dfr/config.toml"; |
| 59 | + enableTinyDfr = lib.mkOption { |
| 60 | + default = true; |
| 61 | + type = lib.types.bool; |
| 62 | + description = "Whether to enable the tiny-dfr touchbar service."; |
91 | 63 | }; |
| 64 | + }; |
92 | 65 |
|
93 | | - # Make sure post-resume.service exists |
94 | | - powerManagement.enable = true; |
95 | | - |
96 | | - # Activation script to install apple-set-os-loader in order to unlock the iGPU |
97 | | - system.activationScripts.appleSetOsLoader = lib.optionalString t2Cfg.enableAppleSetOsLoader '' |
98 | | - if [[ -e /boot/efi/efi/boot/bootx64_original.efi ]]; then |
99 | | - true # It's already installed, no action required |
100 | | - elif [[ -e /boot/efi/efi/boot/bootx64.efi ]]; then |
101 | | - # Copy the new bootloader to a temporary location |
102 | | - cp ${apple-set-os-loader-installer}/bootx64.efi /boot/efi/efi/boot/bootx64_temp.efi |
103 | | -
|
104 | | - # Rename the original bootloader |
105 | | - mv /boot/efi/efi/boot/bootx64.efi /boot/efi/efi/boot/bootx64_original.efi |
106 | | -
|
107 | | - # Move the new bootloader to the final destination |
108 | | - mv /boot/efi/efi/boot/bootx64_temp.efi /boot/efi/efi/boot/bootx64.efi |
109 | | - else |
110 | | - echo "Error: /boot/efi/efi/boot/bootx64.efi is missing" >&2 |
111 | | - fi |
112 | | - ''; |
| 66 | + config = lib.mkMerge [ |
| 67 | + { |
| 68 | + # For keyboard and touchbar |
| 69 | + boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.callPackage ./pkgs/linux-t2.nix { }); |
| 70 | + boot.initrd.kernelModules = [ "apple-bce" ]; |
| 71 | + |
| 72 | + services.udev.packages = [ audioFilesUdevRules ]; |
| 73 | + |
| 74 | + # For audio |
| 75 | + boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ]; |
| 76 | + |
| 77 | + hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; |
| 78 | + |
| 79 | + services.pipewire.package = pipewirePackage; |
| 80 | + services.pipewire.wireplumber.package = pkgs.wireplumber.override { |
| 81 | + pipewire = pipewirePackage; |
| 82 | + }; |
| 83 | + |
| 84 | + # Make sure post-resume.service exists |
| 85 | + powerManagement.enable = true; |
| 86 | + } |
| 87 | + (lib.mkIf t2Cfg.enableAppleSetOsLoader { |
| 88 | + # Activation script to install apple-set-os-loader in order to unlock the iGPU |
| 89 | + system.activationScripts.appleSetOsLoader = '' |
| 90 | + if [[ -e /boot/efi/efi/boot/bootx64_original.efi ]]; then |
| 91 | + true # It's already installed, no action required |
| 92 | + elif [[ -e /boot/efi/efi/boot/bootx64.efi ]]; then |
| 93 | + # Copy the new bootloader to a temporary location |
| 94 | + cp ${apple-set-os-loader-installer}/bootx64.efi /boot/efi/efi/boot/bootx64_temp.efi |
| 95 | +
|
| 96 | + # Rename the original bootloader |
| 97 | + mv /boot/efi/efi/boot/bootx64.efi /boot/efi/efi/boot/bootx64_original.efi |
| 98 | +
|
| 99 | + # Move the new bootloader to the final destination |
| 100 | + mv /boot/efi/efi/boot/bootx64_temp.efi /boot/efi/efi/boot/bootx64.efi |
| 101 | + else |
| 102 | + echo "Error: /boot/efi/efi/boot/bootx64.efi is missing" >&2 |
| 103 | + fi |
| 104 | + ''; |
113 | 105 |
|
114 | | - # Enable the iGPU by default if present |
115 | | - environment.etc."modprobe.d/apple-gmux.conf".text = lib.optionalString t2Cfg.enableAppleSetOsLoader '' |
116 | | - options apple-gmux force_igd=y |
117 | | - ''; |
118 | | - }; |
| 106 | + # Enable the iGPU by default if present |
| 107 | + environment.etc."modprobe.d/apple-gmux.conf".text = '' |
| 108 | + options apple-gmux force_igd=y |
| 109 | + ''; |
| 110 | + }) |
| 111 | + (lib.mkIf t2Cfg.enableTinyDfr { |
| 112 | + services.udev.packages = [ tiny-dfrPackage ]; |
| 113 | + |
| 114 | + systemd.services.tiny-dfr = { |
| 115 | + enable = true; |
| 116 | + description = "Tiny Apple silicon touch bar daemon"; |
| 117 | + after = [ "systemd-user-sessions.service" "[email protected]" "plymouth-quit.service" "systemd-logind.service" ]; |
| 118 | + bindsTo = [ "dev-tiny_dfr_display.device" "dev-tiny_dfr_backlight.device" ]; |
| 119 | + startLimitIntervalSec = 30; |
| 120 | + startLimitBurst = 2; |
| 121 | + script = "${tiny-dfrPackage}/bin/tiny-dfr"; |
| 122 | + restartTriggers = [ tiny-dfrPackage ]; |
| 123 | + }; |
| 124 | + |
| 125 | + environment.etc."tiny-dfr/config.toml" = { |
| 126 | + source = "${tiny-dfrPackage}/share/tiny-dfr/config.toml"; |
| 127 | + }; |
| 128 | + }) |
| 129 | + ]; |
119 | 130 | } |
0 commit comments