Rebase to flake parts #7

This commit is contained in:
2026-05-08 19:12:16 -03:00
parent 1015cf4577
commit f98606dcce
23 changed files with 1060 additions and 11 deletions
@@ -0,0 +1,27 @@
{ ... }: {
# T2: align with https://github.com/deqrocks/apple-bce#required-kernel-parameters (suspend stack).
# (Older t2linux guidance used s2idle + pcie_ports=compat; deqrocks fork expects deep + auto + pm_async=off.)
boot.kernelParams = [
"mem_sleep_default=deep"
"intel_iommu=on"
"iommu=pt"
"pcie_ports=auto"
"pm_async=off"
# https://wiki.t2linux.org/guides/hybrid-graphics/#enabling-the-igpu — helps some post-suspend black screens.
"i915.enable_guc=3"
];
# Hybrid T2 Macs: prefer Intel for display/GL (saves power; avoids broken AMDGPU after resume).
# https://wiki.t2linux.org/guides/hybrid-graphics/
boot.extraModprobeConfig = ''
options apple-gmux force_igd=y
'';
# If the AMD dGPU misbehaves after S3 (Electron apps wont start, suspend breaks), keep it unloaded.
# See https://github.com/deqrocks/apple-bce#notes-for-dgpu-models — drop this list if you need DRI_PRIME
# or external displays wired through the dGPU.
boot.blacklistedKernelModules = [ "amdgpu" ];
boot.kernelModules = [ "apple-bce" ];
boot.initrd.availableKernelModules = [ "apple-bce" ];
}
@@ -0,0 +1,65 @@
{ lib, pkgs, inputs, config, ... }:
let
# Two-stage callPackage matches nixos-hardware apple/t2 generic.nix.
linuxT2GenericFromDir =
{ lib, ... }@args:
{ kernel, t2linuxPatchesSrc }:
let
patchNames = lib.sort lib.lessThan (
lib.filter (n: builtins.match "^[0-9]{4}-.*\\.patch$" n != null) (
lib.attrNames (builtins.readDir t2linuxPatchesSrc)
)
);
t2Patches = map
(name: {
inherit name;
patch = "${t2linuxPatchesSrc}/${name}";
})
patchNames;
in
kernel.override (
args
// {
pname = "linux-t2";
structuredExtraConfig = with lib.kernel; {
# In-tree staging driver disabled; we ship deqrocks/apple-bce via boot.extraModulePackages.
APPLE_BCE = no;
APPLE_GMUX = module;
APFS_FS = module;
BRCMFMAC = module;
BT_BCM = module;
BT_HCIBCM4377 = module;
BT_HCIUART_BCM = yes;
BT_HCIUART = module;
HID_APPLETB_BL = module;
HID_APPLETB_KBD = module;
HID_APPLE = module;
HID_MAGICMOUSE = module;
DRM_APPLETBDRM = module;
HID_SENSOR_ALS = module;
SND_PCM = module;
STAGING = yes;
};
kernelPatches = t2Patches ++ (args.kernelPatches or [ ]);
argsOverride.extraMeta = {
description = "The Linux kernel (with patches from the T2 Linux project)";
maintainers = with lib.maintainers; [ soopyc ];
};
}
// (args.argsOverride or { })
);
linuxT2Kernel = (pkgs.callPackage linuxT2GenericFromDir { }) {
kernel = pkgs.linux_6_19;
t2linuxPatchesSrc = inputs.t2linux-patches;
};
in
{
boot.kernelPackages = lib.mkForce (pkgs.linuxPackagesFor linuxT2Kernel);
# https://github.com/deqrocks/apple-bce (branch no-state-suspend) — BCE + suspend-oriented fixes.
# README also mentions companion userspace: t2-upower, t2-kbd-tb (not packaged here yet).
boot.extraModulePackages = [
(config.boot.kernelPackages.callPackage ./apple-bce.nix { })
];
}