From 2d54ea30cfea085b64db92e6bf8848b73c1fac78 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 13 Jun 2023 16:54:30 +0200 Subject: [PATCH 1/7] macbook-air-6: remove mba6x_bl kernel module This does not compile against 6.x Kernel. This is also no longer necessary for 6.x Kernel. One can use "acpi_video0" device instead of "mba6x_backlight" device. --- apple/macbook-air/6/default.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apple/macbook-air/6/default.nix b/apple/macbook-air/6/default.nix index 555d704..c892026 100644 --- a/apple/macbook-air/6/default.nix +++ b/apple/macbook-air/6/default.nix @@ -4,15 +4,11 @@ imports = [ ../. ]; boot = { - extraModulePackages = with config.boot.kernelPackages; [ mba6x_bl ]; - kernelModules = [ "mba6x_bl" ]; - # Divides power consumption by two. kernelParams = [ "acpi_osi=" ]; }; services.xserver.deviceSection = lib.mkDefault '' - Option "Backlight" "mba6x_backlight" Option "TearFree" "true" ''; } From ba74676d675a4196ca728691e15536a60c94a257 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 02:56:32 +0000 Subject: [PATCH 2/7] build(deps): bump cachix/install-nix-action from 21 to 22 Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 21 to 22. - [Release notes](https://github.com/cachix/install-nix-action/releases) - [Commits](https://github.com/cachix/install-nix-action/compare/v21...v22) --- updated-dependencies: - dependency-name: cachix/install-nix-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e286189..bd918fb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v21 + - uses: cachix/install-nix-action@v22 with: nix_path: nixpkgs=channel:nixos-unstable - name: Show nixpkgs version From ef7a2674a79909ae2ca08d1f46ab6d117dadd78c Mon Sep 17 00:00:00 2001 From: buttergrillcorn <126628446+buttergrillcorn@users.noreply.github.com> Date: Tue, 20 Jun 2023 15:49:07 +0100 Subject: [PATCH 3/7] Update default.nix --- microsoft/surface/common/ipts/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft/surface/common/ipts/default.nix b/microsoft/surface/common/ipts/default.nix index 4faf49e..4d19aa0 100644 --- a/microsoft/surface/common/ipts/default.nix +++ b/microsoft/surface/common/ipts/default.nix @@ -19,7 +19,7 @@ in { systemd.services.iptsd = { description = "IPTSD"; path = with pkgs; [ iptsd ]; - script = "iptsd"; + script = "iptsd $(iptsd-find-hidraw)"; wantedBy = [ "multi-user.target" ]; }; }) From 1d0b3cf27b8b57a6ccc758f111b863d87bab7851 Mon Sep 17 00:00:00 2001 From: Lily Foster Date: Fri, 23 Jun 2023 07:38:13 -0400 Subject: [PATCH 4/7] treewide: avoid alias usage for intel-vaapi-driver based on nixos version --- common/gpu/intel/default.nix | 2 +- gpd/pocket-3/default.nix | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common/gpu/intel/default.nix b/common/gpu/intel/default.nix index 31db8b4..ed76057 100644 --- a/common/gpu/intel/default.nix +++ b/common/gpu/intel/default.nix @@ -8,7 +8,7 @@ }; hardware.opengl.extraPackages = with pkgs; [ - vaapiIntel + (if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then vaapiIntel else intel-vaapi-driver) libvdpau-va-gl intel-media-driver ]; diff --git a/gpd/pocket-3/default.nix b/gpd/pocket-3/default.nix index 64417b9..634e36b 100644 --- a/gpd/pocket-3/default.nix +++ b/gpd/pocket-3/default.nix @@ -14,7 +14,10 @@ in # GPU is an Intel Iris Xe, on a “TigerLake” mobile CPU boot.initrd.kernelModules = [ "i915" ]; # Early loading so the passphrase prompt appears on external displays services.xserver.videoDrivers = [ "intel" ]; - hardware.opengl.extraPackages = with pkgs; [ intel-media-driver vaapiIntel ]; + hardware.opengl.extraPackages = with pkgs; [ + intel-media-driver + (if (lib.versionOlder (lib.versions.majorMinor lib.version) "23.11") then vaapiIntel else intel-vaapi-driver) + ]; boot.kernelParams = [ # S3 suspend is broken as of Sept. 2022 (screen does not come back properly), use S2 From 8e28b9ee431b265d1fc74b8b819ea0816344c4a1 Mon Sep 17 00:00:00 2001 From: kekrby Date: Thu, 25 Aug 2022 18:17:01 +0300 Subject: [PATCH 5/7] apple/t2: init Co-authored-by: networkException --- README.md | 1 + apple/t2/README.md | 9 +++ apple/t2/default.nix | 55 +++++++++++++++++++ .../t2/fix-keyboard-backlight-and-touchbar.sh | 28 ++++++++++ apple/t2/pkgs/linux-t2.nix | 46 ++++++++++++++++ flake.nix | 1 + 6 files changed, 140 insertions(+) create mode 100644 apple/t2/README.md create mode 100644 apple/t2/default.nix create mode 100755 apple/t2/fix-keyboard-backlight-and-touchbar.sh create mode 100644 apple/t2/pkgs/linux-t2.nix diff --git a/README.md b/README.md index 2bbfd45..393686c 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ See code for all available configurations. | [Apple MacBook Pro 11,5](apple/macbook-pro/11-5) | `` | | [Apple MacBook Pro 12,1](apple/macbook-pro/12-1) | `` | | [Apple MacBook Pro 14,1](apple/macbook-pro/14-1) | `` | +| [Apple Macs with a T2 Chip](apple/t2) | `` | | [Asus ROG Strix G733QS](asus/rog-strix/g733qs) | `` | | [Asus ROG Zephyrus G14 GA401](asus/zephyrus/ga401) | `` | | [Asus ROG Zephyrus G14 GA402](asus/zephyrus/ga402) | `` | diff --git a/apple/t2/README.md b/apple/t2/README.md new file mode 100644 index 0000000..7f3a842 --- /dev/null +++ b/apple/t2/README.md @@ -0,0 +1,9 @@ +## NixOS on T2 Macs + +This is the `nixos-hardware` module of the [T2 Linux Project](https://t2linux.org). + +Overall, most features (WiFi, bluetooth, audio, touchbar, ...) of Macs are supported, [see this page](https://wiki.t2linux.org/state/) for a detailed list of things that work and things that don't/partially work. + +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. diff --git a/apple/t2/default.nix b/apple/t2/default.nix new file mode 100644 index 0000000..df62afc --- /dev/null +++ b/apple/t2/default.nix @@ -0,0 +1,55 @@ +{ pkgs, ... }: + +let + audioFiles = pkgs.fetchFromGitHub { + owner = "kekrby"; + repo = "t2-better-audio"; + rev = "e46839a28963e2f7d364020518b9dac98236bcae"; + hash = "sha256-x7K0qa++P1e1vuCGxnsFxL1d9+nwMtZUJ6Kd9e27TFs="; + }; + + overrideAudioFiles = package: pluginsPath: + package.overrideAttrs (new: old: { + preConfigurePhases = old.preConfigurePhases or [ ] ++ [ "postPatchPhase" ]; + + postPatchPhase = '' + cp -r ${audioFiles}/files/{profile-sets,paths} ${pluginsPath}/alsa/mixer/ + ''; + }); +in +{ + # For keyboard and touchbar + boot.kernelPackages = with pkgs; recurseIntoAttrs (linuxPackagesFor (callPackage ./pkgs/linux-t2.nix { })); + boot.initrd.kernelModules = [ "apple-bce" ]; + + # For audio + boot.kernelParams = [ "pcie_ports=compat" "intel_iommu=on" "iommu=pt" ]; + services.udev.extraRules = builtins.readFile (pkgs.substitute { + src = "${audioFiles}/files/91-audio-custom.rules"; + replacements = [ "--replace" "/usr/bin/sed" "${pkgs.gnused}/bin/sed" ]; + }); + + hardware.pulseaudio.package = overrideAudioFiles pkgs.pulseaudio "src/modules/"; + + services.pipewire = rec { + package = overrideAudioFiles pkgs.pipewire "spa/plugins/"; + + wireplumber.package = pkgs.wireplumber.override { + pipewire = package; + }; + }; + + # Make sure post-resume.service exists + powerManagement.enable = true; + + systemd.services.fix-keyboard-backlight-and-touchbar = { + path = [ pkgs.kmod ]; + serviceConfig.ExecStart = ''${pkgs.systemd}/bin/systemd-inhibit --what=sleep --why="fixing keyboard backlight and touchbar must finish before sleep" --mode=delay ${./fix-keyboard-backlight-and-touchbar.sh}''; + serviceConfig.Type = "oneshot"; + description = "reload touchbar driver and restart upower"; + # must run at boot (and not too early), and after suspend + wantedBy = [ "display-manager.service" "post-resume.target" ]; + # prevent running before suspend + after = [ "post-resume.target" ]; + }; +} diff --git a/apple/t2/fix-keyboard-backlight-and-touchbar.sh b/apple/t2/fix-keyboard-backlight-and-touchbar.sh new file mode 100755 index 0000000..c8c6a09 --- /dev/null +++ b/apple/t2/fix-keyboard-backlight-and-touchbar.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +set -eux + +unload () { + if modprobe -r "$1" 2>&1; + then echo ok + else echo fail + fi +} + +wait_unload() { + while sleep 1; do + output="$(unload "$1")" + case "$output" in + *is\ in\ use*) :;; + *ok*) return 0;; + *) echo "modprobe said: $output"; echo giving up; return 1; + esac + done +} + +wait_unload apple_touchbar +modprobe apple_touchbar + +# After suspend, the inode for the backlight device has changed. This service +# simply restarts upower to inform it of that change. +systemctl restart upower.service diff --git a/apple/t2/pkgs/linux-t2.nix b/apple/t2/pkgs/linux-t2.nix new file mode 100644 index 0000000..fef3550 --- /dev/null +++ b/apple/t2/pkgs/linux-t2.nix @@ -0,0 +1,46 @@ +{ lib, buildLinux, fetchFromGitHub, fetchurl, ... } @ args: + +let + patchRepo = fetchFromGitHub { + owner = "t2linux"; + repo = "linux-t2-patches"; + rev = "c0db79a25bc37dbd0c27636914b3903016a2fc39"; + hash = "sha256-VILJAK7F0E/8Z3sOzsUpS9dmtpull2XVXQkakZ0UTIA="; + }; + + version = "6.4"; + majorVersion = with lib; (elemAt (take 1 (splitVersion version)) 0); +in +buildLinux (args // { + inherit version; + + pname = "linux-t2"; + # Snippet from nixpkgs + modDirVersion = with lib; "${concatStringsSep "." (take 3 (splitVersion "${version}.0"))}"; + + src = fetchurl { + url = "mirror://kernel/linux/kernel/v${majorVersion}.x/linux-${version}.tar.xz"; + hash = "sha256-j6BYjwws7KRMrHeg45ukjJ8AprncaXYcAqXT76yNp/M="; + }; + + structuredExtraConfig = with lib.kernel; { + APPLE_BCE = module; + APPLE_GMUX = module; + BRCMFMAC = module; + BT_BCM = module; + BT_HCIBCM4377 = module; + BT_HCIUART_BCM = yes; + BT_HCIUART = module; + HID_APPLE_IBRIDGE = module; + HID_APPLE = module; + HID_APPLE_MAGIC_BACKLIGHT = module; + HID_APPLE_TOUCHBAR = module; + HID_SENSOR_ALS = module; + SND_PCM = module; + STAGING = yes; + }; + + kernelPatches = lib.attrsets.mapAttrsToList (file: type: { name = file; patch = "${patchRepo}/${file}"; }) + (lib.attrsets.filterAttrs (file: type: type == "regular" && lib.strings.hasSuffix ".patch" file) + (builtins.readDir patchRepo)); +} // (args.argsOverride or {})) diff --git a/flake.nix b/flake.nix index 43a2143..79b5997 100644 --- a/flake.nix +++ b/flake.nix @@ -13,6 +13,7 @@ apple-macbook-pro-11-5 = import ./apple/macbook-pro/11-5; apple-macbook-pro-12-1 = import ./apple/macbook-pro/12-1; apple-macbook-pro-14-1 = import ./apple/macbook-pro/14-1; + apple-t2 = import ./apple/t2; asus-battery = import ./asus/battery.nix; asus-fx504gd = import ./asus/fx504gd; asus-rog-strix-g733qs = import ./asus/rog-strix/g733qs; From 289a5af77e624b29b9efd06de262b324c8018abe Mon Sep 17 00:00:00 2001 From: Space Banana Date: Wed, 28 Jun 2023 00:55:39 +0100 Subject: [PATCH 6/7] Additional blocked nvidia kernel modules --- common/gpu/nvidia/disable.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/gpu/nvidia/disable.nix b/common/gpu/nvidia/disable.nix index 83e7d09..cc50981 100644 --- a/common/gpu/nvidia/disable.nix +++ b/common/gpu/nvidia/disable.nix @@ -22,5 +22,5 @@ # Remove NVIDIA VGA/3D controller devices ACTION=="add", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", ATTR{power/control}="auto", ATTR{remove}="1" ''; - boot.blacklistedKernelModules = lib.mkDefault [ "nouveau" "nvidia" ]; -} \ No newline at end of file + boot.blacklistedKernelModules = lib.mkDefault [ "nouveau" "nvidia" "nvidia_drm" "nvidia_modeset" ]; +} From ff35653b1493d6ae27acb04bf6851e095b23ffea Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Tue, 16 May 2023 19:42:48 +0800 Subject: [PATCH 7/7] starfive visionfive2: update kernel to 6.4.0 --- starfive/visionfive/v2/default.nix | 2 +- .../v2/{linux-6.3.nix => linux-6.4.nix} | 22 ++++----- starfive/visionfive/v2/verisilicon.patch | 46 +++++++++++++++++++ 3 files changed, 55 insertions(+), 15 deletions(-) rename starfive/visionfive/v2/{linux-6.3.nix => linux-6.4.nix} (50%) create mode 100644 starfive/visionfive/v2/verisilicon.patch diff --git a/starfive/visionfive/v2/default.nix b/starfive/visionfive/v2/default.nix index ee1ab3f..964b0e5 100644 --- a/starfive/visionfive/v2/default.nix +++ b/starfive/visionfive/v2/default.nix @@ -4,7 +4,7 @@ supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" ]; consoleLogLevel = lib.mkDefault 7; - kernelPackages = lib.mkDefault (pkgs.callPackage ./linux-6.3.nix { + kernelPackages = lib.mkDefault (pkgs.callPackage ./linux-6.4.nix { inherit (config.boot) kernelPatches; }); diff --git a/starfive/visionfive/v2/linux-6.3.nix b/starfive/visionfive/v2/linux-6.4.nix similarity index 50% rename from starfive/visionfive/v2/linux-6.3.nix rename to starfive/visionfive/v2/linux-6.4.nix index 6d7ed86..d0b8e4e 100644 --- a/starfive/visionfive/v2/linux-6.3.nix +++ b/starfive/visionfive/v2/linux-6.4.nix @@ -1,7 +1,7 @@ -{ lib, callPackage, linuxPackagesFor, kernelPatches, fetchpatch, ... }: +{ lib, callPackage, linuxPackagesFor, kernelPatches, ... }: let - modDirVersion = "6.3.0-rc4"; + modDirVersion = "6.4.0"; linuxPkg = { lib, fetchFromGitHub, buildLinux, ... }@args: buildLinux (args // { version = "${modDirVersion}-starfive-visionfive2"; @@ -9,23 +9,17 @@ let src = fetchFromGitHub { owner = "starfive-tech"; repo = "linux"; - rev = "a57bdb1d13f93c8fc1b3c668cc74d585bb20f3f8"; - sha256 = "sha256-jnQnJChIGCyJt+zwGfUTsMhrwmWek/ngIM6Pae6OXuI="; + rev = "e5a381c51d624ffd8784db908a58ae227d0608a4"; + sha256 = "sha256-gg3+2ITdnpo49UmySiAJnk47STW1I7kF7fsKGBVayRE="; }; inherit modDirVersion; - kernelPatches = [ - { - patch = fetchpatch { - url = - "https://github.com/torvalds/linux/commit/d83806c4c0cccc0d6d3c3581a11983a9c186a138.diff"; - hash = "sha256-xUnEJkzQRIIBF/0GIpS0Cd+h6OdSiJlyva5xwxtleE0="; - }; - } - ] ++ kernelPatches; + kernelPatches = [{ + name = "verisilicon"; + patch = ./verisilicon.patch; + }] ++ kernelPatches; structuredExtraConfig = with lib.kernel; { - PL330_DMA = no; PINCTRL_STARFIVE_JH7110_SYS = yes; SERIAL_8250_DW = yes; }; diff --git a/starfive/visionfive/v2/verisilicon.patch b/starfive/visionfive/v2/verisilicon.patch new file mode 100644 index 0000000..4ef8c1e --- /dev/null +++ b/starfive/visionfive/v2/verisilicon.patch @@ -0,0 +1,46 @@ +From f6df0d69978ceb373d14c9337c4cda74d604f46d Mon Sep 17 00:00:00 2001 +From: Nick Cao +Date: Sat, 1 Jul 2023 17:19:22 +0800 +Subject: [PATCH 1/2] drm/verisilicon: add missing null entry in vs_drm_dt_ids + +--- + drivers/gpu/drm/verisilicon/vs_drv.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c b/drivers/gpu/drm/verisilicon/vs_drv.c +index b740fe934035..1255a373f7a2 100644 +--- a/drivers/gpu/drm/verisilicon/vs_drv.c ++++ b/drivers/gpu/drm/verisilicon/vs_drv.c +@@ -258,6 +258,7 @@ static SIMPLE_DEV_PM_OPS(vs_drm_pm_ops, vs_drm_suspend, vs_drm_resume); + + static const struct of_device_id vs_drm_dt_ids[] = { + { .compatible = "verisilicon,display-subsystem", }, ++ {}, + }; + + MODULE_DEVICE_TABLE(of, vs_drm_dt_ids); +-- +2.41.0 + +From f7d2f6e8c6e566cdd441b7bd4710f7628af15dcb Mon Sep 17 00:00:00 2001 +From: Nick Cao +Date: Sat, 1 Jul 2023 17:49:05 +0800 +Subject: [PATCH 2/2] drm/verisilicon: import DMA_BUF namespace + +--- + drivers/gpu/drm/verisilicon/vs_drv.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/drivers/gpu/drm/verisilicon/vs_drv.c b/drivers/gpu/drm/verisilicon/vs_drv.c +index 1255a373f7a2..8627027047aa 100644 +--- a/drivers/gpu/drm/verisilicon/vs_drv.c ++++ b/drivers/gpu/drm/verisilicon/vs_drv.c +@@ -299,4 +299,5 @@ module_init(vs_drm_init); + module_exit(vs_drm_fini); + + MODULE_DESCRIPTION("VeriSilicon DRM Driver"); ++MODULE_IMPORT_NS(DMA_BUF); + MODULE_LICENSE("GPL"); +-- +2.41.0 +