diff --git a/apple/t2/default.nix b/apple/t2/default.nix index 1b40d760..ce15cc39 100644 --- a/apple/t2/default.nix +++ b/apple/t2/default.nix @@ -8,34 +8,47 @@ let inherit (lib) types; - audioFiles = pkgs.fetchFromGitHub { - owner = "kekrby"; - repo = "t2-better-audio"; - rev = "e46839a28963e2f7d364020518b9dac98236bcae"; - hash = "sha256-x7K0qa++P1e1vuCGxnsFxL1d9+nwMtZUJ6Kd9e27TFs="; + t2bce-alsa-ucm = pkgs.stdenvNoCC.mkDerivation (_: { + name = "t2bce-alsa-ucm"; + src = pkgs.fetchFromGitHub { + owner = "deqrocks"; + repo = "t2bce"; + rev = "967465dc67d3a9b1e48dea620f7258baa526f4f2"; + hash = "sha256-EVUvNg30bFhJCtcyPAGbWjGX0+CORs4nWG5Bpvbr590="; + }; + + meta = { + description = "ALSA Usage Configuration Manager configuration for T2 Macs"; + license = lib.licenses.mit; + }; + + dontBuild = true; + + installPhase = '' + runHook preInstall + + cd ./t2bce_audio-alsa-ucm-conf + mkdir -p "$out/share/alsa/" + cp -vR ./ucm2 "$out/share/alsa/" + + runHook postInstall + ''; + }); + + patched-alsa-ucm = pkgs.symlinkJoin { + inherit (t2bce-alsa-ucm) src meta; + name = "t2bce-alsa-ucm-patched"; + paths = [ + pkgs.alsa-ucm-conf + t2bce-alsa-ucm + ]; }; - audioFilesUdevRules = pkgs.runCommand "audio-files-udev-rules" { } '' - mkdir -p $out/lib/udev/rules.d - cp ${audioFiles}/files/*.rules $out/lib/udev/rules.d - substituteInPlace $out/lib/udev/rules.d/*.rules --replace "/usr/bin/sed" "${pkgs.gnused}/bin/sed" - ''; - - overrideAudioFiles = - package: pluginsPath: - package.overrideAttrs ( - _new: old: { - preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ]; - postPatchPhase = '' - cp -r ${audioFiles}/files/{profile-sets,paths} ${pluginsPath}/alsa/mixer/ - ''; - } - ); - - pipewirePackage = overrideAudioFiles pkgs.pipewire "spa/plugins/"; + patchedAudioAlsaEnv = lib.genAttrs [ "pipewire" "wireplumber" "pulseaudio" ] (_: { + environment.ALSA_CONFIG_UCM2 = config.environment.variables.ALSA_CONFIG_UCM2; + }); t2Cfg = config.hardware.apple-t2; - in { imports = [ @@ -85,9 +98,7 @@ in if t2Cfg.kernelChannel == "stable" then ./pkgs/linux-t2 else ./pkgs/linux-t2/latest.nix ) { } ); - boot.initrd.kernelModules = [ "apple-bce" ]; - - services.udev.packages = [ audioFilesUdevRules ]; + boot.initrd.kernelModules = [ "t2bce-vhci" ]; # For audio and suspend boot.kernelParams = [ @@ -96,19 +107,19 @@ in "pm_async=off" ]; - services.pipewire.package = pipewirePackage; - services.pipewire.wireplumber.package = pkgs.wireplumber.override { - pipewire = pipewirePackage; + # audio configuration + # https://github.com/nix-community/nixos-apple-silicon/blob/66d8dd2c27f99bd5420c99938b60695aac1785c4/apple-silicon-support/modules/sound/default.nix#L46 + environment.variables.ALSA_CONFIG_UCM2 = "${patched-alsa-ucm}/share/alsa/ucm2"; + # setting systemd.globalEnvironment is likely going to have unexpected side effects + systemd = { + services = patchedAudioAlsaEnv; + user.services = patchedAudioAlsaEnv; }; # Make sure post-resume.service exists powerManagement.enable = true; } - { - services.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; - } - (lib.mkIf t2Cfg.enableIGPU { # Enable the iGPU by default if present environment.etc."modprobe.d/apple-gmux.conf".text = '' diff --git a/apple/t2/pkgs/linux-t2/default.nix b/apple/t2/pkgs/linux-t2/default.nix index 61dcb22d..1936fe32 100644 --- a/apple/t2/pkgs/linux-t2/default.nix +++ b/apple/t2/pkgs/linux-t2/default.nix @@ -1,6 +1,3 @@ -{ callPackage, linux_6_18, ... }@args: +{ callPackage, ... }@args: -callPackage ./generic.nix args { - kernel = linux_6_18; - patchesFile = ./stable.json; -} +callPackage ./generic.nix args ./stable.json diff --git a/apple/t2/pkgs/linux-t2/generic.nix b/apple/t2/pkgs/linux-t2/generic.nix index a4e6e284..39f34f1e 100644 --- a/apple/t2/pkgs/linux-t2/generic.nix +++ b/apple/t2/pkgs/linux-t2/generic.nix @@ -1,13 +1,13 @@ { lib, fetchurl, # fetchpatch does unnecessary normalization + buildLinux, + linuxKernel, ... }@args: -{ - kernel, - patchesFile, -}: +patchesFile: + let inherit (builtins) readFile fromJSON; @@ -23,33 +23,58 @@ let } ) patchset.patches; in -kernel.override ( - args - // { +buildLinux ( + { pname = "linux-t2"; + version = patchset.kernel.version; + + src = fetchurl { + inherit (patchset.kernel) url hash; + }; structuredExtraConfig = with lib.kernel; { - APPLE_BCE = module; + T2BCE_CORE = module; + T2BCE_VHCI = module; + T2BCE_AUDIO = module; + T2BCE_AVE = module; APPLE_GMUX = module; APFS_FS = module; BRCMFMAC = module; BT_BCM = module; BT_HCIBCM4377 = module; - BT_HCIUART_BCM = yes; BT_HCIUART = module; + BT_HCIUART_BCM = yes; + DRM_APPLETBDRM = module; + HID_APPLE = module; HID_APPLETB_BL = module; HID_APPLETB_KBD = module; - HID_APPLE = module; HID_MAGICMOUSE = module; - DRM_APPLETBDRM = module; HID_SENSOR_ALS = module; + SENSORS_APPLESMC = module; SND_PCM = module; STAGING = yes; + + # required for t2bce_ave + I2C = yes; + MEDIA_SUPPORT = yes; + MEDIA_CAMERA_SUPPORT = yes; + MEDIA_ANALOG_TV_SUPPORT = yes; + MEDIA_DIGITAL_TV_SUPPORT = yes; + MEDIA_RADIO_SUPPORT = yes; + MEDIA_SDR_SUPPORT = yes; + MEDIA_PLATFORM_SUPPORT = yes; + MEDIA_TEST_SUPPORT = yes; }; - kernelPatches = t2-patches ++ (args.kernelPatches or [ ]); + kernelPatches = [ + # include default patches for good measure + linuxKernel.kernelPatches.request_key_helper + linuxKernel.kernelPatches.bridge_stp_helper + ] + ++ t2-patches + ++ (args.kernelPatches or [ ]); - argsOverride.extraMeta = { + extraMeta = { description = "The Linux kernel (with patches from the T2 Linux project)"; # take responsibility for the downstream kernel diff --git a/apple/t2/pkgs/linux-t2/latest.json b/apple/t2/pkgs/linux-t2/latest.json index 069c95dc..4847ff3d 100644 --- a/apple/t2/pkgs/linux-t2/latest.json +++ b/apple/t2/pkgs/linux-t2/latest.json @@ -1,25 +1,30 @@ { - "base_url": "https://raw.githubusercontent.com/t2linux/linux-t2-patches/7ee7d19c38e5df31a386b2a0c35ca8f064003960/", + "base_url": "https://raw.githubusercontent.com/t2linux/linux-t2-patches/65fdd4d492d7e219a05742ce4768f16e5ba4f976/", + "kernel": { + "version": "7.2.9", + "url": "mirror://kernel/linux/kernel/v7.x/linux-7.2.9.tar.xz", + "hash": "sha256:1fnqp28vrikz9gqhb42k0dsggqf8i07j0s9qy33scr53a6zdzidl" + }, "patches": [ { - "name": "1001-Add-apple-bce-driver.patch", - "hash": "sha256-v/P3Ws3x+OPnmX3vSFLxARON0HNjjDRe7QJ+KP9tVsc=" + "name": "1001-Add-t2bce-driver-stack.patch", + "hash": "sha256-QeAffMClzGsGdHC5Qce744X2WUcx6PI0CJ5BQ8txxQ8=" }, { - "name": "1002-Put-apple-bce-in-drivers-staging.patch", - "hash": "sha256-rK1lQ3fjHJH//50n37xgWrUs4CZ8lmFw0iDpbq5zoaY=" + "name": "1002-Integrate-t2bce-driver-stack.patch", + "hash": "sha256-nPAPGV9IROyxSQzSztwNS1fY0ziGQJ7evKBs1ZSHwiE=" }, { "name": "2008-i915-4-lane-quirk-for-mbp15-1.patch", - "hash": "sha256-S2osR1aSjqJiO7rNZP1sKt2+Uxyitwse/6BXMJvE9as=" + "hash": "sha256-gTYP7WHV/Qulobdi1nNdYsv1CWgkM8pGvsCFQ+rvhrw=" }, { "name": "2009-apple-gmux-allow-switching-to-igpu-at-probe.patch", - "hash": "sha256-6i+fh/Ifle0di5/tMOdMm0NMkEmeUb17hYM/g2j2dfI=" + "hash": "sha256-OczfcYSvkw2lBZQzZjCV4LHSe6CnaJ1J8GBkgEbiOXk=" }, { "name": "3001-applesmc-convert-static-structures-to-drvdata.patch", - "hash": "sha256-7KGC0pCos351wKNhwJI/Qoc7w+orOPpiTkdCN50G8nI=" + "hash": "sha256-FVtOCXInI5OUqpTVDVsZ1taMwj3z+d3PeRgjnQQljG4=" }, { "name": "3002-applesmc-make-io-port-base-addr-dynamic.patch", @@ -55,35 +60,55 @@ }, { "name": "4001-asahi-trackpad.patch", - "hash": "sha256-ANHSNoy5nK2b+rSAG0bJ8j6ZBmNqgeCddHXVS31KyDw=" + "hash": "sha256-RuYI0t+rMu29wSkVT4suYJgGzS1ZruN/HBZWkLivlDw=" }, { "name": "4003-HID-apple-ignore-the-trackpad-on-T2-Macs.patch", - "hash": "sha256-T2tYcFLeWUdx6QawANe3ZNVSRxmo1IdPiSpGLQk4IDY=" + "hash": "sha256-LLZzcysLTuQrSXWXbdq7AASxfMInQoqpWzRNZAKws9k=" }, { "name": "4004-HID-magicmouse-Add-support-for-trackpads-found-on-T2.patch", - "hash": "sha256-ubchCEv1BZ7t/zkI9DpHA4gUln9cdu4yHzVJI2TNlS0=" - }, - { - "name": "4005-HID-magicmouse-fix-regression-breaking-support-for-M.patch", - "hash": "sha256-oT+3AeETnKfzblxtcTD18c61BKoD9yAsga0AL3R8u7k=" + "hash": "sha256-kUnbtl/54cihscirl9kP0Gsot7bdP0rYKlj6gQ10hk0=" }, { "name": "5001-HID-appletb-kbd-add-option-to-switch-default-layer-o.patch", "hash": "sha256-KV5DTjALzNugs92Jum6VUt0wgblK/6PG1KorovHcIX0=" }, + { + "name": "5002-drm-appletbdrm-Add-suspend-and-resume-support.patch", + "hash": "sha256-NFa5ZpNguUC9ELfphvCrVHEh59tN/ZA9vQl6YD1avbI=" + }, + { + "name": "6001-drm-amd-pm-Fix-boot-problems-in-5300.patch", + "hash": "sha256-l6pyVkpumURgoQ/f1kGfw47YhMuuMjpiHgjP6QN8dNE=" + }, { "name": "7001-drm-i915-fbdev-Discard-BIOS-framebuffers-exceeding-h.patch", "hash": "sha256-/EKN7JsAxcpAgfJFtPp2NLYaGqQ0kl8wjJEXifSzJpY=" }, + { + "name": "7002-drm-amdgpu-reset-VI-ASIC-on-MacBookPro15-1.patch", + "hash": "sha256-lLruG4lJAI6fI94w2LzHmrbspXArrq+rbI/SJmhwXqo=" + }, + { + "name": "7003-amdgpu-add-support-for-5K.patch", + "hash": "sha256-RX3tiju4gNFlrrYWOMdUr0HAdSN5RliliiPAQw5I6/M=" + }, { "name": "8001-Add-APFS-driver.patch", - "hash": "sha256-EbIbfkncp5Jax2suny/jlFt+cD9MyYMV2rWFJIbgbg4=" + "hash": "sha256-DU/jX8wuM6Y/5iZztg05GjWlzVlo8DfVpCJ3BxFoTJo=" }, { "name": "8002-Necessary-modifications-to-build-APFS-with-the-kerne.patch", "hash": "sha256-zCTetF2NPhMH2BknPumhPz2sf26X9Lcra7xCA3R2WMY=" + }, + { + "name": "9001-ACPI-x86-Apple-T2-systems-need-early-CPU-offlining.patch", + "hash": "sha256-camFPvnBQMErjVrbsdPPfsbyy59w0e0iPkVR1Juzv8o=" + }, + { + "name": "9002-Bluetooth-hci_event-strip-Broadcom-vendor-bits-from-adv-type.patch", + "hash": "sha256-oikMBjD4gyqTs351q7nTz6lI6rJqOe1/LfxpHAieEOs=" } ] } diff --git a/apple/t2/pkgs/linux-t2/latest.nix b/apple/t2/pkgs/linux-t2/latest.nix index 4bf1becb..dffc3865 100644 --- a/apple/t2/pkgs/linux-t2/latest.nix +++ b/apple/t2/pkgs/linux-t2/latest.nix @@ -1,6 +1,3 @@ -{ callPackage, linux_7_0, ... }@args: +{ callPackage, ... }@args: -callPackage ./generic.nix args { - kernel = linux_7_0; - patchesFile = ./latest.json; -} +callPackage ./generic.nix args ./latest.json diff --git a/apple/t2/pkgs/linux-t2/stable.json b/apple/t2/pkgs/linux-t2/stable.json index a06bd02b..091d16ac 100644 --- a/apple/t2/pkgs/linux-t2/stable.json +++ b/apple/t2/pkgs/linux-t2/stable.json @@ -1,17 +1,26 @@ { - "base_url": "https://raw.githubusercontent.com/t2linux/linux-t2-patches/facf1c778667c3ef62104949ef64c75ce7e43b0a/", + "base_url": "https://raw.githubusercontent.com/t2linux/linux-t2-patches/2eed0f6c812e8f36cb7a7f7bcde69f6f87074bdf/", + "kernel": { + "version": "6.18.55", + "url": "mirror://kernel/linux/kernel/v6.x/linux-6.18.55.tar.xz", + "hash": "sha256:1yadaa2gz74nh3pawpwv6lamalnd7wpiv1xb88pw2rd1c606647l" + }, "patches": [ { - "name": "1001-Add-apple-bce-driver.patch", - "hash": "sha256-rrL3oVkYeq5ZslnjCQw4hcEK6knsm6U/wp1XnJmQTSA=" + "name": "1001-Add-t2bce-driver-stack.patch", + "hash": "sha256-OG4Y7cN75pHWF7huV+2Fqtq0ik2aITMWtF43mD+RFCU=" }, { - "name": "1002-Put-apple-bce-in-drivers-staging.patch", - "hash": "sha256-deWROYcncl51sOmtvUHM61e5FM1beHbOJVp4iI31LHM=" + "name": "1002-Integrate-t2bce-driver-stack.patch", + "hash": "sha256-z3g3IOAL+Nze88oKDSYpLHVtFnhz2kP1Udap5J64WmM=" + }, + { + "name": "1003-Fix-for-6.18.patch", + "hash": "sha256-ozJkJFm11oGDW1Gwrp4AR4Ifv9X8Yix6uF9ZBFJ76+M=" }, { "name": "2008-i915-4-lane-quirk-for-mbp15-1.patch", - "hash": "sha256-S2osR1aSjqJiO7rNZP1sKt2+Uxyitwse/6BXMJvE9as=" + "hash": "sha256-gTYP7WHV/Qulobdi1nNdYsv1CWgkM8pGvsCFQ+rvhrw=" }, { "name": "2009-apple-gmux-allow-switching-to-igpu-at-probe.patch", @@ -19,7 +28,7 @@ }, { "name": "3001-applesmc-convert-static-structures-to-drvdata.patch", - "hash": "sha256-7KGC0pCos351wKNhwJI/Qoc7w+orOPpiTkdCN50G8nI=" + "hash": "sha256-c/d+c5eKzhbtfUKtLC7AB+6vMXge4ZzPJAUbNENWH7g=" }, { "name": "3002-applesmc-make-io-port-base-addr-dynamic.patch", @@ -55,31 +64,35 @@ }, { "name": "4001-asahi-trackpad.patch", - "hash": "sha256-+YXyIjtlVrLo8allTO3M1A+xold5FUXaZ8dwD2j5HDc=" + "hash": "sha256-2h3TdPsX9HBXx5jkZ2S2GJkjFcdL8vKD1G69iqd9IWg=" }, { "name": "4003-HID-apple-ignore-the-trackpad-on-T2-Macs.patch", - "hash": "sha256-T2tYcFLeWUdx6QawANe3ZNVSRxmo1IdPiSpGLQk4IDY=" + "hash": "sha256-LLZzcysLTuQrSXWXbdq7AASxfMInQoqpWzRNZAKws9k=" }, { "name": "4004-HID-magicmouse-Add-support-for-trackpads-found-on-T2.patch", - "hash": "sha256-ubchCEv1BZ7t/zkI9DpHA4gUln9cdu4yHzVJI2TNlS0=" - }, - { - "name": "4005-HID-magicmouse-fix-regression-breaking-support-for-M.patch", - "hash": "sha256-oT+3AeETnKfzblxtcTD18c61BKoD9yAsga0AL3R8u7k=" + "hash": "sha256-kUnbtl/54cihscirl9kP0Gsot7bdP0rYKlj6gQ10hk0=" }, { "name": "5001-HID-appletb-kbd-add-option-to-switch-default-layer-o.patch", "hash": "sha256-KV5DTjALzNugs92Jum6VUt0wgblK/6PG1KorovHcIX0=" }, + { + "name": "5002-drm-appletbdrm-Add-suspend-and-resume-support.patch", + "hash": "sha256-NFa5ZpNguUC9ELfphvCrVHEh59tN/ZA9vQl6YD1avbI=" + }, { "name": "7001-drm-i915-fbdev-Discard-BIOS-framebuffers-exceeding-h.patch", "hash": "sha256-/EKN7JsAxcpAgfJFtPp2NLYaGqQ0kl8wjJEXifSzJpY=" }, + { + "name": "7002-drm-amdgpu-reset-VI-ASIC-on-MacBookPro15-1.patch", + "hash": "sha256-lLruG4lJAI6fI94w2LzHmrbspXArrq+rbI/SJmhwXqo=" + }, { "name": "8001-Add-APFS-driver.patch", - "hash": "sha256-2By3Zlg/i5rUUJDlWc6JoiqapUnbVplk2lHzDhvAhzI=" + "hash": "sha256-fL9TftzTd5PurxIDrzaPsysGExrMySGOsm6H8NFd7JY=" }, { "name": "8002-Necessary-modifications-to-build-APFS-with-the-kerne.patch", diff --git a/apple/t2/pkgs/linux-t2/update-patches.py b/apple/t2/pkgs/linux-t2/update-patches.py index 7b907293..ec29a4c9 100755 --- a/apple/t2/pkgs/linux-t2/update-patches.py +++ b/apple/t2/pkgs/linux-t2/update-patches.py @@ -15,21 +15,26 @@ API_BASE = "https://api.github.com" PATCH_PATTERN = re.compile(r"^\d{4}-.*\.patch$") parser = argparse.ArgumentParser( - description="Update linux-t2 patches from a GitHub repository." + description="Update linux-t2 patches from a GitHub repository.", + epilog=''' + If both --branch and --reference flags are given, the argument of --reference will be used to fetch the Git + revision for patches and --branch as the kernel branch. + + If only --branch is given, the argument will be used for both resolving the Git ref and the kernel branch. + ''', ) parser.add_argument("filename", help="the output filename") parser.add_argument( "--repository", - help="the source github repository", + help="the source github repository (default: %(default)s)", default="t2linux/linux-t2-patches", nargs="?", ) -ref_group = parser.add_mutually_exclusive_group() -ref_group.add_argument( +parser.add_argument( "--reference", help="the git reference for the patches", default=None, nargs="?" ) -ref_group.add_argument( - "--branch", help="the git branch to fetch", default=None, nargs="?" +parser.add_argument( + "--branch", help="the kernel branch to fetch (default: latest, example: 6.18)", default=None, nargs="?" ) @@ -62,6 +67,27 @@ def main(): reference = args.reference branch = args.branch + print("Fetching kernel releases") + releases = requests.get("https://kernel.org/releases.json").json()['releases'] + match = None + patched_url = "" + if not branch: + print("Branch not provided, fetching latest non-mainline kernel version") + # if the json schema changes this script would break, hopefully won't happen + match = next(filter(lambda x: x["moniker"] != "mainline", releases), None) + else: + match = next(filter(lambda x: x["version"].startswith(branch), releases), None) + if not match: + print(f"ERROR: could not find a kernel release for branch {branch}.") + return 1 + patched_url = match['source'].replace('https://cdn.kernel.org/pub', 'mirror://kernel') + + release_hash = subprocess.check_output(["nix-prefetch-url", "--type", "sha256", patched_url]).decode().strip() + print(f" Kernel: {match['version']}") + print(f" URL: {patched_url}") + print(f" Hash: sha256:{release_hash}") + kernel = {"version": match["version"], "url": patched_url, "hash": f"sha256:{release_hash}"} + if reference is None: if branch is None: print("Branch and reference not provided, fetching default branch") @@ -85,7 +111,7 @@ def main(): for future in as_completed(futures): patches_with_hash.append(future.result()) - result = {"base_url": base_url, "patches": sorted(patches_with_hash, key=lambda p: p["name"])} + result = {"base_url": base_url, "kernel": kernel, "patches": sorted(patches_with_hash, key=lambda p: p["name"])} with open(args.filename, "w+") as f: json.dump(result, f, indent=2)