From b32b188154bda2f0b430afac19e404216aaded23 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 20:00:53 +1300 Subject: [PATCH 01/17] Convert the repos.linux-surface-kernel set to a function --- microsoft/surface/repos.nix | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/microsoft/surface/repos.nix b/microsoft/surface/repos.nix index 1ee00b9..3ee09a9 100644 --- a/microsoft/surface/repos.nix +++ b/microsoft/surface/repos.nix @@ -1,10 +1,11 @@ { lib, pkgs, fetchFromGitHub, fetchurl }: { - linux-surface-kernel = fetchFromGitHub { - owner = "linux-surface"; - repo = "kernel"; - rev = "db94c89f56d6ceae03ca3802e11197f48e6c539f"; - sha256 = "0c58ri0i9gdb4w7l361pnkvq6ap17kmgnxngh0bcdmgn4dc88wx2"; - }; + # This is the owner and repo for the pre-patched kernel from the "linux-surface" project: + linux-surface-kernel = { rev, sha256 }: + fetchFromGitHub { + owner = "linux-surface"; + repo = "kernel"; + inherit rev sha256; + }; ath10k-firmware = fetchFromGitHub { owner = "kvalo"; From 35e317a280f6457c5ba085d985175346fa6694b7 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 20:01:29 +1300 Subject: [PATCH 02/17] Use new repos.linux-surface-kernel function --- microsoft/surface/kernel/linux-5.16.11.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/microsoft/surface/kernel/linux-5.16.11.nix b/microsoft/surface/kernel/linux-5.16.11.nix index 022c069..ae8dbd4 100644 --- a/microsoft/surface/kernel/linux-5.16.11.nix +++ b/microsoft/surface/kernel/linux-5.16.11.nix @@ -9,7 +9,11 @@ let modDirVersion = version; extraMeta.branch = "5.16"; - src = repos.linux-surface-kernel; + src = repos.linux-surface-kernel { + # Kernel 5.16.11 + rev = "db94c89f56d6ceae03ca3802e11197f48e6c539f"; + sha256 = "0c58ri0i9gdb4w7l361pnkvq6ap17kmgnxngh0bcdmgn4dc88wx2"; + }; kernelPatches = [{ name = "microsoft-surface-patches-linux-5.16.2"; From 158f86bb326dd3529f288bb476464f61679a41c3 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 20:23:51 +1300 Subject: [PATCH 03/17] DRY the MS Surface kernel module --- microsoft/surface/kernel/default.nix | 38 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/microsoft/surface/kernel/default.nix b/microsoft/surface/kernel/default.nix index 354fe90..1a1ca6b 100644 --- a/microsoft/surface/kernel/default.nix +++ b/microsoft/surface/kernel/default.nix @@ -1,5 +1,37 @@ -{ config, lib, pkgs, ... }: +{ lib, + buildLinux, + callPackage, + linuxPackagesFor, + ... +}: -{ - boot.kernelPackages = pkgs.callPackage ./linux-5.16.11.nix { }; +# To test the kernel build: +# nix-build -E "with import {}; (pkgs.callPackage ./. {}).kernel" + +let + inherit (lib) kernel recurseIntoAttrs; + repos = callPackage ../repos.nix {}; + + linuxPackage = + { version, + modDirVersion ? version, + branch, + src, + kernelPatches ? [], + ... + }: let + buildLinux' = buildLinux { + inherit version src kernelPatches; + modDirVersion = version; + extraMeta.branch = branch; + }; + linuxPackagesFor' = (linuxPackagesFor buildLinux'); + in recurseIntoAttrs linuxPackagesFor'; + + linux-5_16_11 = linuxPackage ( + callPackage ./linux-5.16.11.nix { inherit repos; } + ); + +in { + boot.kernelPackages = linux-5_16_11; } From 3de7b6e0c58abe80fa5bdab87be66464898639ee Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 20:28:52 +1300 Subject: [PATCH 04/17] Use the newly refactored code --- microsoft/surface/kernel/default.nix | 2 +- microsoft/surface/kernel/linux-5.16.11.nix | 156 ++++++++++----------- 2 files changed, 79 insertions(+), 79 deletions(-) diff --git a/microsoft/surface/kernel/default.nix b/microsoft/surface/kernel/default.nix index 1a1ca6b..b266919 100644 --- a/microsoft/surface/kernel/default.nix +++ b/microsoft/surface/kernel/default.nix @@ -6,7 +6,7 @@ }: # To test the kernel build: -# nix-build -E "with import {}; (pkgs.callPackage ./. {}).kernel" +# nix-build -E "with import {}; (pkgs.callPackage ./. {}).boot.kernelPackages.kernel" let inherit (lib) kernel recurseIntoAttrs; diff --git a/microsoft/surface/kernel/linux-5.16.11.nix b/microsoft/surface/kernel/linux-5.16.11.nix index ae8dbd4..6083531 100644 --- a/microsoft/surface/kernel/linux-5.16.11.nix +++ b/microsoft/surface/kernel/linux-5.16.11.nix @@ -1,91 +1,91 @@ -{ lib, callPackage, linuxPackagesFor, ... }: -# To test the kernel build: -# nix-build -E "with import {}; (pkgs.callPackage ./linux-5.16.11.nix {}).kernel" +{ lib, + repos, +}: + let - repos = callPackage ../repos.nix {}; - linuxPkg = { fetchurl, buildLinux, ... }@args: - buildLinux (args // rec { - version = "5.16.11"; - modDirVersion = version; - extraMeta.branch = "5.16"; + inherit (lib) kernel; + version = "5.16.11"; - src = repos.linux-surface-kernel { - # Kernel 5.16.11 - rev = "db94c89f56d6ceae03ca3802e11197f48e6c539f"; - sha256 = "0c58ri0i9gdb4w7l361pnkvq6ap17kmgnxngh0bcdmgn4dc88wx2"; - }; +in { + inherit version; + modDirVersion = version; + branch = "5.16"; + src = repos.linux-surface-kernel { + # Kernel 5.16.11 from the linux-surface/kernel repo: + rev = "db94c89f56d6ceae03ca3802e11197f48e6c539f"; + sha256 = "0c58ri0i9gdb4w7l361pnkvq6ap17kmgnxngh0bcdmgn4dc88wx2"; + }; + kernelPatches = [{ + name = "microsoft-surface-patches-linux-${version}"; + patch = null; + structuredExtraConfig = with kernel; { + # + # Surface Aggregator Module + # + SURFACE_AGGREGATOR = module; + SURFACE_AGGREGATOR_ERROR_INJECTION = no; + SURFACE_AGGREGATOR_BUS = yes; + SURFACE_AGGREGATOR_CDEV = module; + SURFACE_AGGREGATOR_REGISTRY = module; - kernelPatches = [{ - name = "microsoft-surface-patches-linux-5.16.2"; - patch = null; - structuredExtraConfig = with lib.kernel; { - # - # Surface Aggregator Module - # - SURFACE_AGGREGATOR = module; - SURFACE_AGGREGATOR_ERROR_INJECTION = no; - SURFACE_AGGREGATOR_BUS = yes; - SURFACE_AGGREGATOR_CDEV = module; - SURFACE_AGGREGATOR_REGISTRY = module; + SURFACE_ACPI_NOTIFY = module; + SURFACE_DTX = module; + SURFACE_PLATFORM_PROFILE = module; - SURFACE_ACPI_NOTIFY = module; - SURFACE_DTX = module; - SURFACE_PLATFORM_PROFILE = module; + SURFACE_HID = module; + SURFACE_KBD = module; - SURFACE_HID = module; - SURFACE_KBD = module; + BATTERY_SURFACE = module; + CHARGER_SURFACE = module; - BATTERY_SURFACE = module; - CHARGER_SURFACE = module; + # + # Surface laptop 1 keyboard + # + SERIAL_DEV_BUS = yes; + SERIAL_DEV_CTRL_TTYPORT = yes; - # - # Surface laptop 1 keyboard - # - SERIAL_DEV_BUS = yes; - SERIAL_DEV_CTRL_TTYPORT = yes; + # + # Surface Hotplug + # + SURFACE_HOTPLUG = module; - # - # Surface Hotplug - # - SURFACE_HOTPLUG = module; + # + # IPTS touchscreen + # + # This only enables the user interface for IPTS data. + # For the touchscreen to work, you need to install iptsd. + # + MISC_IPTS = module; - # - # IPTS touchscreen - # - # This only enables the user interface for IPTS data. - # For the touchscreen to work, you need to install iptsd. - # - MISC_IPTS = module; + # + # Cameras: IPU3 + # + VIDEO_IPU3_IMGU = module; + VIDEO_IPU3_CIO2 = module; + CIO2_BRIDGE = yes; + INTEL_SKL_INT3472 = module; - # - # Cameras: IPU3 - # - VIDEO_IPU3_IMGU = module; - VIDEO_IPU3_CIO2 = module; - CIO2_BRIDGE = yes; - INTEL_SKL_INT3472 = module; + # + # Cameras: Sensor drivers + # + VIDEO_OV5693 = module; + VIDEO_OV8865 = module; - # - # Cameras: Sensor drivers - # - VIDEO_OV5693 = module; - VIDEO_OV8865 = module; + # + # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 + # + APDS9960 = module; - # - # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 - # - APDS9960 = module; + # + # Other Drivers + # + INPUT_SOC_BUTTON_ARRAY = module; + SURFACE_3_BUTTON = module; + SURFACE_3_POWER_OPREGION = module; + SURFACE_PRO3_BUTTON = module; + SURFACE_GPE = module; + SURFACE_BOOK1_DGPU_SWITCH = module; + }; + }]; +} - # - # Other Drivers - # - INPUT_SOC_BUTTON_ARRAY = module; - SURFACE_3_BUTTON = module; - SURFACE_3_POWER_OPREGION = module; - SURFACE_PRO3_BUTTON = module; - SURFACE_GPE = module; - SURFACE_BOOK1_DGPU_SWITCH = module; - }; - }]; - } // (args.argsOverride or {})); -in lib.recurseIntoAttrs (linuxPackagesFor (callPackage linuxPkg {})) From 50ce82cc84b7fd4394c1387f3155bc7c100d7bdf Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 22:26:47 +1300 Subject: [PATCH 05/17] Fix for unexpected recursion error Might be related to how these packages access "pkgs" ? --- microsoft/surface/kernel/default.nix | 14 +++++--------- microsoft/surface/repos.nix | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/microsoft/surface/kernel/default.nix b/microsoft/surface/kernel/default.nix index b266919..1920dfe 100644 --- a/microsoft/surface/kernel/default.nix +++ b/microsoft/surface/kernel/default.nix @@ -1,16 +1,12 @@ -{ lib, - buildLinux, - callPackage, - linuxPackagesFor, - ... -}: +{ config, lib, pkgs, ... }: # To test the kernel build: # nix-build -E "with import {}; (pkgs.callPackage ./. {}).boot.kernelPackages.kernel" let inherit (lib) kernel recurseIntoAttrs; - repos = callPackage ../repos.nix {}; + inherit (pkgs) buildLinux linuxPackagesFor; + repos = pkgs.callPackage ../repos.nix {}; linuxPackage = { version, @@ -25,11 +21,11 @@ let modDirVersion = version; extraMeta.branch = branch; }; - linuxPackagesFor' = (linuxPackagesFor buildLinux'); + linuxPackagesFor' = linuxPackagesFor buildLinux'; in recurseIntoAttrs linuxPackagesFor'; linux-5_16_11 = linuxPackage ( - callPackage ./linux-5.16.11.nix { inherit repos; } + pkgs.callPackage ./linux-5.16.11.nix { inherit repos; } ); in { diff --git a/microsoft/surface/repos.nix b/microsoft/surface/repos.nix index 3ee09a9..42e31de 100644 --- a/microsoft/surface/repos.nix +++ b/microsoft/surface/repos.nix @@ -1,4 +1,4 @@ -{ lib, pkgs, fetchFromGitHub, fetchurl }: { +{ fetchFromGitHub, fetchurl }: { # This is the owner and repo for the pre-patched kernel from the "linux-surface" project: linux-surface-kernel = { rev, sha256 }: fetchFromGitHub { From 5d0ade69589d2d53397137ef900322a43947b416 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 23:21:34 +1300 Subject: [PATCH 06/17] Add-back linux-surface/linux-surface repo, for easy access to the kernel patches --- microsoft/surface/repos.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/microsoft/surface/repos.nix b/microsoft/surface/repos.nix index 42e31de..586d094 100644 --- a/microsoft/surface/repos.nix +++ b/microsoft/surface/repos.nix @@ -1,4 +1,11 @@ { fetchFromGitHub, fetchurl }: { + linux-surface = fetchFromGitHub { + owner = "linux-surface"; + repo = "linux-surface"; + rev = "6d0fa58a6eadda44b35a3c5e60db2ed0fa0c101e"; + sha256 = "sha256-Jf6DN/pZaGIk58pA+CUylpl09Wi4vA3vKZC60b3WcOg="; + }; + # This is the owner and repo for the pre-patched kernel from the "linux-surface" project: linux-surface-kernel = { rev, sha256 }: fetchFromGitHub { From d93d29bdc980a80eb1643184d4429e84046b162d Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 23:21:34 +1300 Subject: [PATCH 07/17] Add-back linux-surface/linux-surface repo, for easy access to the kernel patches --- microsoft/surface/repos.nix | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/microsoft/surface/repos.nix b/microsoft/surface/repos.nix index 1ee00b9..586d094 100644 --- a/microsoft/surface/repos.nix +++ b/microsoft/surface/repos.nix @@ -1,11 +1,19 @@ -{ lib, pkgs, fetchFromGitHub, fetchurl }: { - linux-surface-kernel = fetchFromGitHub { +{ fetchFromGitHub, fetchurl }: { + linux-surface = fetchFromGitHub { owner = "linux-surface"; - repo = "kernel"; - rev = "db94c89f56d6ceae03ca3802e11197f48e6c539f"; - sha256 = "0c58ri0i9gdb4w7l361pnkvq6ap17kmgnxngh0bcdmgn4dc88wx2"; + repo = "linux-surface"; + rev = "6d0fa58a6eadda44b35a3c5e60db2ed0fa0c101e"; + sha256 = "sha256-Jf6DN/pZaGIk58pA+CUylpl09Wi4vA3vKZC60b3WcOg="; }; + # This is the owner and repo for the pre-patched kernel from the "linux-surface" project: + linux-surface-kernel = { rev, sha256 }: + fetchFromGitHub { + owner = "linux-surface"; + repo = "kernel"; + inherit rev sha256; + }; + ath10k-firmware = fetchFromGitHub { owner = "kvalo"; repo = "ath10k-firmware"; From a51973c994d614f8af069394064966ef8b7237b0 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 23:43:50 +1300 Subject: [PATCH 08/17] Add linux-surface patches for 5.19.2 --- microsoft/surface/kernel/linux-5.19.2.nix | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 microsoft/surface/kernel/linux-5.19.2.nix diff --git a/microsoft/surface/kernel/linux-5.19.2.nix b/microsoft/surface/kernel/linux-5.19.2.nix new file mode 100644 index 0000000..f893e81 --- /dev/null +++ b/microsoft/surface/kernel/linux-5.19.2.nix @@ -0,0 +1,71 @@ +{ lib, + fetchurl, +}: + +let + inherit (lib) kernel; + version = "5.19.2"; + +in { + inherit version; + modDirVersion = version; + branch = "5.19"; + src = fetchurl { + url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz"; + sha256 = "sha256-SOQKH1UB7GxA48htPVMZIAtojy2TYPcoMwhNdIAf5j0="; + }; + patches = repos.linux-surface + "/patches/${branch}"; + + kernelPatches = [ + { + name = "microsoft-surface-patches-linux-${version}"; + patch = null; + structuredExtraConfig = with lib.kernel; { + }; + } + { + name = "ms-surface/0001-surface3-oemb"; + patch = patches + "/0001-surface3-oemb.patch"; + } + { + name = "ms-surface/0002-mwifiex"; + patch = patches + "/0002-mwifiex.patch"; + } + { + name = "ms-surface/0003-ath10k"; + patch = patches + "/0003-ath10k.patch"; + } + { + name = "ms-surface/0004-ipts"; + patch = patches + "/0004-ipts.patch"; + } + { + name = "ms-surface/0005-surface-sam"; + patch = patches + "/0005-surface-sam.patch"; + } + { + name = "ms-surface/0006-surface-sam-over-hid"; + patch = patches + "/0006-surface-sam-over-hid.patch"; + } + { + name = "ms-surface/0007-surface-button"; + patch = patches + "/0007-surface-button.patch"; + } + { + name = "ms-surface/0008-surface-typecover"; + patch = patches + "/0008-surface-typecover.patch"; + } + { + name = "ms-surface/0009-surface-gpe"; + patch = patches + "/0009-surface-gpe.patch"; + } + { + name = "ms-surface/0010-cameras"; + patch = patches + "/0010-cameras.patch"; + } + { + name = "ms-surface/0011-amd-gpio"; + patch = patches + "/0011-amd-gpio.patch"; + } + ]; +} From 87adbffa11fc633470fe8411b477b77975c0a8f3 Mon Sep 17 00:00:00 2001 From: mexisme Date: Tue, 29 Nov 2022 00:00:31 +1300 Subject: [PATCH 09/17] Fix-ups --- microsoft/surface/kernel/default.nix | 35 +++++++++++++++++++++-- microsoft/surface/kernel/linux-5.19.2.nix | 7 +++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/microsoft/surface/kernel/default.nix b/microsoft/surface/kernel/default.nix index 354fe90..97fd174 100644 --- a/microsoft/surface/kernel/default.nix +++ b/microsoft/surface/kernel/default.nix @@ -1,5 +1,36 @@ { config, lib, pkgs, ... }: -{ - boot.kernelPackages = pkgs.callPackage ./linux-5.16.11.nix { }; +# To test the kernel build: +# nix-build -E "with import {}; (pkgs.callPackage ./. {}).boot.kernelPackages.kernel" + +let + inherit (lib) kernel recurseIntoAttrs; + inherit (pkgs) buildLinux linuxPackagesFor; + repos = pkgs.callPackage ../repos.nix {}; + + linuxPackage = + { version, + modDirVersion ? version, + branch, + src, + kernelPatches ? [], + ... + }: let + buildLinux' = buildLinux { + inherit version src kernelPatches; + modDirVersion = version; + extraMeta.branch = branch; + }; + linuxPackagesFor' = linuxPackagesFor buildLinux'; + in recurseIntoAttrs linuxPackagesFor'; + + linux-5_16_11 = linuxPackage ( + pkgs.callPackage ./linux-5.16.11.nix { inherit repos; } + ); + linux-5_19_2 = linuxPackage ( + pkgs.callPackage ./linux-5.19.2.nix { inherit repos; } + ); + +in { + boot.kernelPackages = linux-5_19_2; } diff --git a/microsoft/surface/kernel/linux-5.19.2.nix b/microsoft/surface/kernel/linux-5.19.2.nix index f893e81..c941b88 100644 --- a/microsoft/surface/kernel/linux-5.19.2.nix +++ b/microsoft/surface/kernel/linux-5.19.2.nix @@ -1,20 +1,21 @@ { lib, fetchurl, + repos, }: let inherit (lib) kernel; version = "5.19.2"; + branch = "5.19"; + patches = repos.linux-surface + "/patches/${branch}"; in { - inherit version; + inherit version branch; modDirVersion = version; - branch = "5.19"; src = fetchurl { url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz"; sha256 = "sha256-SOQKH1UB7GxA48htPVMZIAtojy2TYPcoMwhNdIAf5j0="; }; - patches = repos.linux-surface + "/patches/${branch}"; kernelPatches = [ { From 87597ab307c5eaae6142f9adcfb1e47dac472eec Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 13:37:20 +1300 Subject: [PATCH 10/17] Remove obsolete files --- microsoft/surface/kernel/linux-5.16.11.nix | 91 ---------------------- microsoft/surface/kernel/linux-5.19.2.nix | 72 ----------------- 2 files changed, 163 deletions(-) delete mode 100644 microsoft/surface/kernel/linux-5.16.11.nix delete mode 100644 microsoft/surface/kernel/linux-5.19.2.nix diff --git a/microsoft/surface/kernel/linux-5.16.11.nix b/microsoft/surface/kernel/linux-5.16.11.nix deleted file mode 100644 index 6083531..0000000 --- a/microsoft/surface/kernel/linux-5.16.11.nix +++ /dev/null @@ -1,91 +0,0 @@ -{ lib, - repos, -}: - -let - inherit (lib) kernel; - version = "5.16.11"; - -in { - inherit version; - modDirVersion = version; - branch = "5.16"; - src = repos.linux-surface-kernel { - # Kernel 5.16.11 from the linux-surface/kernel repo: - rev = "db94c89f56d6ceae03ca3802e11197f48e6c539f"; - sha256 = "0c58ri0i9gdb4w7l361pnkvq6ap17kmgnxngh0bcdmgn4dc88wx2"; - }; - kernelPatches = [{ - name = "microsoft-surface-patches-linux-${version}"; - patch = null; - structuredExtraConfig = with kernel; { - # - # Surface Aggregator Module - # - SURFACE_AGGREGATOR = module; - SURFACE_AGGREGATOR_ERROR_INJECTION = no; - SURFACE_AGGREGATOR_BUS = yes; - SURFACE_AGGREGATOR_CDEV = module; - SURFACE_AGGREGATOR_REGISTRY = module; - - SURFACE_ACPI_NOTIFY = module; - SURFACE_DTX = module; - SURFACE_PLATFORM_PROFILE = module; - - SURFACE_HID = module; - SURFACE_KBD = module; - - BATTERY_SURFACE = module; - CHARGER_SURFACE = module; - - # - # Surface laptop 1 keyboard - # - SERIAL_DEV_BUS = yes; - SERIAL_DEV_CTRL_TTYPORT = yes; - - # - # Surface Hotplug - # - SURFACE_HOTPLUG = module; - - # - # IPTS touchscreen - # - # This only enables the user interface for IPTS data. - # For the touchscreen to work, you need to install iptsd. - # - MISC_IPTS = module; - - # - # Cameras: IPU3 - # - VIDEO_IPU3_IMGU = module; - VIDEO_IPU3_CIO2 = module; - CIO2_BRIDGE = yes; - INTEL_SKL_INT3472 = module; - - # - # Cameras: Sensor drivers - # - VIDEO_OV5693 = module; - VIDEO_OV8865 = module; - - # - # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 - # - APDS9960 = module; - - # - # Other Drivers - # - INPUT_SOC_BUTTON_ARRAY = module; - SURFACE_3_BUTTON = module; - SURFACE_3_POWER_OPREGION = module; - SURFACE_PRO3_BUTTON = module; - SURFACE_GPE = module; - SURFACE_BOOK1_DGPU_SWITCH = module; - }; - }]; -} - diff --git a/microsoft/surface/kernel/linux-5.19.2.nix b/microsoft/surface/kernel/linux-5.19.2.nix deleted file mode 100644 index c941b88..0000000 --- a/microsoft/surface/kernel/linux-5.19.2.nix +++ /dev/null @@ -1,72 +0,0 @@ -{ lib, - fetchurl, - repos, -}: - -let - inherit (lib) kernel; - version = "5.19.2"; - branch = "5.19"; - patches = repos.linux-surface + "/patches/${branch}"; - -in { - inherit version branch; - modDirVersion = version; - src = fetchurl { - url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz"; - sha256 = "sha256-SOQKH1UB7GxA48htPVMZIAtojy2TYPcoMwhNdIAf5j0="; - }; - - kernelPatches = [ - { - name = "microsoft-surface-patches-linux-${version}"; - patch = null; - structuredExtraConfig = with lib.kernel; { - }; - } - { - name = "ms-surface/0001-surface3-oemb"; - patch = patches + "/0001-surface3-oemb.patch"; - } - { - name = "ms-surface/0002-mwifiex"; - patch = patches + "/0002-mwifiex.patch"; - } - { - name = "ms-surface/0003-ath10k"; - patch = patches + "/0003-ath10k.patch"; - } - { - name = "ms-surface/0004-ipts"; - patch = patches + "/0004-ipts.patch"; - } - { - name = "ms-surface/0005-surface-sam"; - patch = patches + "/0005-surface-sam.patch"; - } - { - name = "ms-surface/0006-surface-sam-over-hid"; - patch = patches + "/0006-surface-sam-over-hid.patch"; - } - { - name = "ms-surface/0007-surface-button"; - patch = patches + "/0007-surface-button.patch"; - } - { - name = "ms-surface/0008-surface-typecover"; - patch = patches + "/0008-surface-typecover.patch"; - } - { - name = "ms-surface/0009-surface-gpe"; - patch = patches + "/0009-surface-gpe.patch"; - } - { - name = "ms-surface/0010-cameras"; - patch = patches + "/0010-cameras.patch"; - } - { - name = "ms-surface/0011-amd-gpio"; - patch = patches + "/0011-amd-gpio.patch"; - } - ]; -} From b01a6d58df799cd87ba9cf9a2b23ecb114d5e221 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 13:38:14 +1300 Subject: [PATCH 11/17] Remove obsolete file --- microsoft/surface/kernel/linux-5.16.11.nix | 91 ---------------------- 1 file changed, 91 deletions(-) delete mode 100644 microsoft/surface/kernel/linux-5.16.11.nix diff --git a/microsoft/surface/kernel/linux-5.16.11.nix b/microsoft/surface/kernel/linux-5.16.11.nix deleted file mode 100644 index 6083531..0000000 --- a/microsoft/surface/kernel/linux-5.16.11.nix +++ /dev/null @@ -1,91 +0,0 @@ -{ lib, - repos, -}: - -let - inherit (lib) kernel; - version = "5.16.11"; - -in { - inherit version; - modDirVersion = version; - branch = "5.16"; - src = repos.linux-surface-kernel { - # Kernel 5.16.11 from the linux-surface/kernel repo: - rev = "db94c89f56d6ceae03ca3802e11197f48e6c539f"; - sha256 = "0c58ri0i9gdb4w7l361pnkvq6ap17kmgnxngh0bcdmgn4dc88wx2"; - }; - kernelPatches = [{ - name = "microsoft-surface-patches-linux-${version}"; - patch = null; - structuredExtraConfig = with kernel; { - # - # Surface Aggregator Module - # - SURFACE_AGGREGATOR = module; - SURFACE_AGGREGATOR_ERROR_INJECTION = no; - SURFACE_AGGREGATOR_BUS = yes; - SURFACE_AGGREGATOR_CDEV = module; - SURFACE_AGGREGATOR_REGISTRY = module; - - SURFACE_ACPI_NOTIFY = module; - SURFACE_DTX = module; - SURFACE_PLATFORM_PROFILE = module; - - SURFACE_HID = module; - SURFACE_KBD = module; - - BATTERY_SURFACE = module; - CHARGER_SURFACE = module; - - # - # Surface laptop 1 keyboard - # - SERIAL_DEV_BUS = yes; - SERIAL_DEV_CTRL_TTYPORT = yes; - - # - # Surface Hotplug - # - SURFACE_HOTPLUG = module; - - # - # IPTS touchscreen - # - # This only enables the user interface for IPTS data. - # For the touchscreen to work, you need to install iptsd. - # - MISC_IPTS = module; - - # - # Cameras: IPU3 - # - VIDEO_IPU3_IMGU = module; - VIDEO_IPU3_CIO2 = module; - CIO2_BRIDGE = yes; - INTEL_SKL_INT3472 = module; - - # - # Cameras: Sensor drivers - # - VIDEO_OV5693 = module; - VIDEO_OV8865 = module; - - # - # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 - # - APDS9960 = module; - - # - # Other Drivers - # - INPUT_SOC_BUTTON_ARRAY = module; - SURFACE_3_BUTTON = module; - SURFACE_3_POWER_OPREGION = module; - SURFACE_PRO3_BUTTON = module; - SURFACE_GPE = module; - SURFACE_BOOK1_DGPU_SWITCH = module; - }; - }]; -} - From d2b7a0fb9a62feb21e98ea43da2cda787132bd92 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 14:40:24 +1300 Subject: [PATCH 12/17] Kernel 6.0.11 for MS Surface Devices --- microsoft/surface/kernel/default.nix | 4 -- microsoft/surface/kernel/linux-6.0.11.nix | 65 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/microsoft/surface/kernel/default.nix b/microsoft/surface/kernel/default.nix index 2a17bbb..74293ff 100644 --- a/microsoft/surface/kernel/default.nix +++ b/microsoft/surface/kernel/default.nix @@ -33,9 +33,5 @@ let ); in { -<<<<<<< Updated upstream - boot.kernelPackages = linux-5_19_17; -======= boot.kernelPackages = linux-6_0_11; ->>>>>>> Stashed changes } diff --git a/microsoft/surface/kernel/linux-6.0.11.nix b/microsoft/surface/kernel/linux-6.0.11.nix index 6cfd457..1eb2f84 100644 --- a/microsoft/surface/kernel/linux-6.0.11.nix +++ b/microsoft/surface/kernel/linux-6.0.11.nix @@ -22,6 +22,71 @@ in { name = "microsoft-surface-patches-linux-${version}"; patch = null; structuredExtraConfig = with lib.kernel; { + # + # Surface Aggregator Module + # + CONFIG_SURFACE_AGGREGATOR = module; + CONFIG_SURFACE_AGGREGATOR_ERROR_INJECTION = no; + CONFIG_SURFACE_AGGREGATOR_BUS = yes; + CONFIG_SURFACE_AGGREGATOR_CDEV = module; + CONFIG_SURFACE_AGGREGATOR_HUB = module; + CONFIG_SURFACE_AGGREGATOR_REGISTRY = module; + CONFIG_SURFACE_AGGREGATOR_TABLET_SWITCH = module; + + CONFIG_SURFACE_ACPI_NOTIFY = module; + CONFIG_SURFACE_DTX = module; + CONFIG_SURFACE_PLATFORM_PROFILE = module; + + CONFIG_SURFACE_HID = module; + CONFIG_SURFACE_KBD = module; + + CONFIG_BATTERY_SURFACE = module; + CONFIG_CHARGER_SURFACE = module; + + # + # Surface Hotplug + # + CONFIG_SURFACE_HOTPLUG = module; + + # + # IPTS touchscreen + # + # This only enables the user interface for IPTS data. + # For the touchscreen to work, you need to install iptsd. + # + CONFIG_MISC_IPTS = module; + + # + # Cameras: IPU3 + # + CONFIG_VIDEO_DW9719 = module; + CONFIG_VIDEO_IPU3_IMGU = module; + CONFIG_VIDEO_IPU3_CIO2 = module; + CONFIG_CIO2_BRIDGE = yes; + CONFIG_INTEL_SKL_INT3472 = module; + CONFIG_REGULATOR_TPS68470 = module; + CONFIG_COMMON_CLK_TPS68470 = module; + + # + # Cameras: Sensor drivers + # + CONFIG_VIDEO_OV5693 = module; + CONFIG_VIDEO_OV7251 = module; + CONFIG_VIDEO_OV8865 = module; + + # + # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 + # + CONFIG_APDS9960 = module; + + # + # Other Drivers + # + CONFIG_INPUT_SOC_BUTTON_ARRAY = module; + CONFIG_SURFACE_3_POWER_OPREGION = module; + CONFIG_SURFACE_PRO3_BUTTON = module; + CONFIG_SURFACE_GPE = module; + CONFIG_SURFACE_BOOK1_DGPU_SWITCH = module; }; } { From f99c9d5b1f537f60ec371a2105b7dae8073ff735 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 16:01:37 +1300 Subject: [PATCH 13/17] Tidy-up --- microsoft/surface/default.nix | 28 +++++++++++++------ .../surface-go/ath10k/ath10k-replace.nix | 7 +++-- .../firmware/surface-go/ath10k/default.nix | 13 +++++---- microsoft/surface/kernel/linux-5.19.17.nix | 5 +--- microsoft/surface/repos.nix | 4 ++- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/microsoft/surface/default.nix b/microsoft/surface/default.nix index 56dfd07..da01f16 100644 --- a/microsoft/surface/default.nix +++ b/microsoft/surface/default.nix @@ -1,10 +1,15 @@ -{ config, lib, pkgs, ... }: { +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkDefault; + +in { imports = [ ./kernel ./firmware/surface-go/ath10k ]; - boot.extraModprobeConfig = lib.mkDefault '' + boot.extraModprobeConfig = mkDefault '' options i915 enable_fbc=1 enable_rc6=1 modeset=1 options snd_hda_intel power_save=1 options snd_ac97_codec power_save=1 @@ -15,18 +20,25 @@ boot.kernelParams = [ "mem_sleep_default=deep" ]; # NOTE: Check the README before enabling TLP: - services.tlp.enable = lib.mkDefault false; + services.tlp.enable = mkDefault false; # i.e. needed for wifi firmware, see https://github.com/NixOS/nixos-hardware/issues/364 - hardware.enableRedistributableFirmware = lib.mkDefault true; - hardware.sensor.iio.enable = lib.mkDefault true; + hardware.enableRedistributableFirmware = mkDefault true; + hardware.sensor.iio.enable = mkDefault true; - environment.systemPackages = with pkgs; [ surface-control ]; + environment.systemPackages = [ + pkgs.surface-control + ]; users.groups.surface-control = { }; - services.udev.packages = [ pkgs.surface-control ]; + services.udev.packages = [ + pkgs.surface-control + ]; + systemd.services.iptsd = { description = "IPTSD"; script = "${pkgs.iptsd}/bin/iptsd"; - wantedBy = [ "multi-user.target" ]; + wantedBy = [ + "multi-user.target" + ]; }; } diff --git a/microsoft/surface/firmware/surface-go/ath10k/ath10k-replace.nix b/microsoft/surface/firmware/surface-go/ath10k/ath10k-replace.nix index be0e4fe..e62307d 100644 --- a/microsoft/surface/firmware/surface-go/ath10k/ath10k-replace.nix +++ b/microsoft/surface/firmware/surface-go/ath10k/ath10k-replace.nix @@ -1,9 +1,10 @@ -{stdenv, lib, pkgs, firmwareLinuxNonfree, ...}: +{ stdenv, lib, pkgs, firmwareLinuxNonfree, ... }: + let repos = (pkgs.callPackage ../../../repos.nix {}); killernetworking_firmware = repos.surface-go-ath10k-firmware_backup + "/K1535_Debian"; -in -stdenv.mkDerivation { + +in stdenv.mkDerivation { pname = "microsoft-surface-go-firmware-linux-nonfree"; inherit (firmwareLinuxNonfree) version; src = firmwareLinuxNonfree; diff --git a/microsoft/surface/firmware/surface-go/ath10k/default.nix b/microsoft/surface/firmware/surface-go/ath10k/default.nix index b23fe2e..f861f8e 100644 --- a/microsoft/surface/firmware/surface-go/ath10k/default.nix +++ b/microsoft/surface/firmware/surface-go/ath10k/default.nix @@ -1,21 +1,24 @@ { config, lib, pkgs, ... }: + let + inherit (lib) mkDefault mkEnableOption mkIf; + cfg = config.hardware.microsoft-surface.firmware.surface-go-ath10k; -in -{ + +in { options = { hardware.microsoft-surface.firmware.surface-go-ath10k = { - replace = lib.mkEnableOption ''Use the "board.bin" firmware for ath10k-based WiFi on Surface Go.''; + replace = mkEnableOption ''Use the "board.bin" firmware for ath10k-based WiFi on Surface Go.''; }; }; - config = lib.mkIf cfg.replace { + config = mkIf cfg.replace { hardware.enableAllFirmware = true; hardware.firmware = [ (pkgs.callPackage ./ath10k-replace.nix {}) ]; - boot.extraModprobeConfig = lib.mkDefault '' + boot.extraModprobeConfig = mkDefault '' options ath10k_core skip_otp=Y ''; }; diff --git a/microsoft/surface/kernel/linux-5.19.17.nix b/microsoft/surface/kernel/linux-5.19.17.nix index 6093c9b..ddd8c91 100644 --- a/microsoft/surface/kernel/linux-5.19.17.nix +++ b/microsoft/surface/kernel/linux-5.19.17.nix @@ -1,7 +1,4 @@ -{ lib, - fetchurl, - repos, -}: +{ lib, fetchurl, repos,}: let inherit (lib) kernel; diff --git a/microsoft/surface/repos.nix b/microsoft/surface/repos.nix index 586d094..b5f3f05 100644 --- a/microsoft/surface/repos.nix +++ b/microsoft/surface/repos.nix @@ -1,4 +1,6 @@ -{ fetchFromGitHub, fetchurl }: { +{ fetchFromGitHub, fetchurl }: + +{ linux-surface = fetchFromGitHub { owner = "linux-surface"; repo = "linux-surface"; From e37520e48b3882f4ec773d2e56d41dd914cae34d Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 17:32:25 +1300 Subject: [PATCH 14/17] Rearrange the kernels to make them self-defining --- microsoft/surface/default.nix | 2 + microsoft/surface/kernel/default.nix | 37 ++--- microsoft/surface/kernel/linux-5.19.17.nix | 135 ---------------- .../surface/kernel/linux-5.19.17/default.nix | 153 ++++++++++++++++++ microsoft/surface/kernel/linux-package.nix | 23 +++ 5 files changed, 188 insertions(+), 162 deletions(-) delete mode 100644 microsoft/surface/kernel/linux-5.19.17.nix create mode 100644 microsoft/surface/kernel/linux-5.19.17/default.nix create mode 100644 microsoft/surface/kernel/linux-package.nix diff --git a/microsoft/surface/default.nix b/microsoft/surface/default.nix index da01f16..e193d2a 100644 --- a/microsoft/surface/default.nix +++ b/microsoft/surface/default.nix @@ -9,6 +9,8 @@ in { ./firmware/surface-go/ath10k ]; + microsoft-surface.kernel-version = mkDefault "5.19.17"; + boot.extraModprobeConfig = mkDefault '' options i915 enable_fbc=1 enable_rc6=1 modeset=1 options snd_hda_intel power_save=1 diff --git a/microsoft/surface/kernel/default.nix b/microsoft/surface/kernel/default.nix index 893f1bd..0c8dcfc 100644 --- a/microsoft/surface/kernel/default.nix +++ b/microsoft/surface/kernel/default.nix @@ -1,33 +1,16 @@ { config, lib, pkgs, ... }: -# To test the kernel build: -# nix-build -E "with import {}; (pkgs.callPackage ./. {}).boot.kernelPackages.kernel" - let - inherit (lib) kernel recurseIntoAttrs; - inherit (pkgs) buildLinux linuxPackagesFor; - repos = pkgs.callPackage ../repos.nix {}; - - linuxPackage = - { version, - modDirVersion ? version, - branch, - src, - kernelPatches ? [], - ... - }: let - buildLinux' = buildLinux { - inherit version src kernelPatches; - modDirVersion = version; - extraMeta.branch = branch; - }; - linuxPackagesFor' = linuxPackagesFor buildLinux'; - in recurseIntoAttrs linuxPackagesFor'; - - linux-5_19_17 = linuxPackage ( - pkgs.callPackage ./linux-5.19.17.nix { inherit repos; } - ); + inherit (lib) mkOption types; in { - boot.kernelPackages = linux-5_19_17; + imports = [ + ./linux-5.19.17 + ]; + + options.microsoft-surface.kernel-version = mkOption { + description = "Kernel Version to use (patched for MS Surface)"; + type = types.enum [ ]; + # default = "5.19.17"; + }; } diff --git a/microsoft/surface/kernel/linux-5.19.17.nix b/microsoft/surface/kernel/linux-5.19.17.nix deleted file mode 100644 index ddd8c91..0000000 --- a/microsoft/surface/kernel/linux-5.19.17.nix +++ /dev/null @@ -1,135 +0,0 @@ -{ lib, fetchurl, repos,}: - -let - inherit (lib) kernel; - version = "5.19.17"; - branch = "5.19"; - patches = repos.linux-surface + "/patches/${branch}"; - -in { - inherit version branch; - modDirVersion = version; - src = fetchurl { - url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz"; - sha256 = "sha256-yTuzhKl60fCk8Y5ELOApEkJyL3gCPspliyI0RUHwlIk="; - }; - - kernelPatches = [ - { - name = "microsoft-surface-patches-linux-${version}"; - patch = null; - structuredExtraConfig = with lib.kernel; { - # - # Surface Aggregator Module - # - SURFACE_AGGREGATOR = module; - SURFACE_AGGREGATOR_ERROR_INJECTION = no; - SURFACE_AGGREGATOR_BUS = yes; - SURFACE_AGGREGATOR_CDEV = module; - SURFACE_AGGREGATOR_REGISTRY = module; - - SURFACE_ACPI_NOTIFY = module; - SURFACE_DTX = module; - SURFACE_PLATFORM_PROFILE = module; - - SURFACE_HID = module; - SURFACE_KBD = module; - - BATTERY_SURFACE = module; - CHARGER_SURFACE = module; - - # - # Surface laptop 1 keyboard - # - SERIAL_DEV_BUS = yes; - SERIAL_DEV_CTRL_TTYPORT = yes; - - # - # Surface Hotplug - # - SURFACE_HOTPLUG = module; - - # - # IPTS touchscreen - # - # This only enables the user interface for IPTS data. - # For the touchscreen to work, you need to install iptsd. - # - MISC_IPTS = module; - - # - # Cameras: IPU3 - # - VIDEO_IPU3_IMGU = module; - VIDEO_IPU3_CIO2 = module; - CIO2_BRIDGE = yes; - INTEL_SKL_INT3472 = module; - - # - # Cameras: Sensor drivers - # - VIDEO_OV5693 = module; - VIDEO_OV8865 = module; - - # - # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 - # - APDS9960 = module; - - # - # Other Drivers - # - INPUT_SOC_BUTTON_ARRAY = module; - SURFACE_3_BUTTON = module; - SURFACE_3_POWER_OPREGION = module; - SURFACE_PRO3_BUTTON = module; - SURFACE_GPE = module; - SURFACE_BOOK1_DGPU_SWITCH = module; - }; - } - { - name = "ms-surface/0001-surface3-oemb"; - patch = patches + "/0001-surface3-oemb.patch"; - } - { - name = "ms-surface/0002-mwifiex"; - patch = patches + "/0002-mwifiex.patch"; - } - { - name = "ms-surface/0003-ath10k"; - patch = patches + "/0003-ath10k.patch"; - } - { - name = "ms-surface/0004-ipts"; - patch = patches + "/0004-ipts.patch"; - } - { - name = "ms-surface/0005-surface-sam"; - patch = patches + "/0005-surface-sam.patch"; - } - { - name = "ms-surface/0006-surface-sam-over-hid"; - patch = patches + "/0006-surface-sam-over-hid.patch"; - } - { - name = "ms-surface/0007-surface-button"; - patch = patches + "/0007-surface-button.patch"; - } - { - name = "ms-surface/0008-surface-typecover"; - patch = patches + "/0008-surface-typecover.patch"; - } - { - name = "ms-surface/0009-surface-gpe"; - patch = patches + "/0009-surface-gpe.patch"; - } - { - name = "ms-surface/0010-cameras"; - patch = patches + "/0010-cameras.patch"; - } - { - name = "ms-surface/0011-amd-gpio"; - patch = patches + "/0011-amd-gpio.patch"; - } - ]; -} diff --git a/microsoft/surface/kernel/linux-5.19.17/default.nix b/microsoft/surface/kernel/linux-5.19.17/default.nix new file mode 100644 index 0000000..e1bf29d --- /dev/null +++ b/microsoft/surface/kernel/linux-5.19.17/default.nix @@ -0,0 +1,153 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) kernel mkIf mkOption types; + inherit (pkgs) fetchurl; + + inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage repos; + + cfg = config.microsoft-surface.kernel-version; + + version = "5.19.17"; + extraMeta.branch = "5.19"; + patches = repos.linux-surface + "/patches/${extraMeta.branch}"; + + kernelPackages = linuxPackage { + inherit version extraMeta; + # modDirVersion = version; + src = fetchurl { + url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz"; + sha256 = "sha256-yTuzhKl60fCk8Y5ELOApEkJyL3gCPspliyI0RUHwlIk="; + }; + + kernelPatches = [ + { + name = "microsoft-surface-patches-linux-${version}"; + patch = null; + structuredExtraConfig = with lib.kernel; { + # + # Surface Aggregator Module + # + SURFACE_AGGREGATOR = module; + SURFACE_AGGREGATOR_ERROR_INJECTION = no; + SURFACE_AGGREGATOR_BUS = yes; + SURFACE_AGGREGATOR_CDEV = module; + SURFACE_AGGREGATOR_REGISTRY = module; + + SURFACE_ACPI_NOTIFY = module; + SURFACE_DTX = module; + SURFACE_PLATFORM_PROFILE = module; + + SURFACE_HID = module; + SURFACE_KBD = module; + + BATTERY_SURFACE = module; + CHARGER_SURFACE = module; + + # + # Surface laptop 1 keyboard + # + SERIAL_DEV_BUS = yes; + SERIAL_DEV_CTRL_TTYPORT = yes; + + # + # Surface Hotplug + # + SURFACE_HOTPLUG = module; + + # + # IPTS touchscreen + # + # This only enables the user interface for IPTS data. + # For the touchscreen to work, you need to install iptsd. + # + MISC_IPTS = module; + + # + # Cameras: IPU3 + # + VIDEO_IPU3_IMGU = module; + VIDEO_IPU3_CIO2 = module; + CIO2_BRIDGE = yes; + INTEL_SKL_INT3472 = module; + + # + # Cameras: Sensor drivers + # + VIDEO_OV5693 = module; + VIDEO_OV8865 = module; + + # + # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 + # + APDS9960 = module; + + # + # Other Drivers + # + INPUT_SOC_BUTTON_ARRAY = module; + SURFACE_3_BUTTON = module; + SURFACE_3_POWER_OPREGION = module; + SURFACE_PRO3_BUTTON = module; + SURFACE_GPE = module; + SURFACE_BOOK1_DGPU_SWITCH = module; + }; + } + { + name = "ms-surface/0001-surface3-oemb"; + patch = patches + "/0001-surface3-oemb.patch"; + } + { + name = "ms-surface/0002-mwifiex"; + patch = patches + "/0002-mwifiex.patch"; + } + { + name = "ms-surface/0003-ath10k"; + patch = patches + "/0003-ath10k.patch"; + } + { + name = "ms-surface/0004-ipts"; + patch = patches + "/0004-ipts.patch"; + } + { + name = "ms-surface/0005-surface-sam"; + patch = patches + "/0005-surface-sam.patch"; + } + { + name = "ms-surface/0006-surface-sam-over-hid"; + patch = patches + "/0006-surface-sam-over-hid.patch"; + } + { + name = "ms-surface/0007-surface-button"; + patch = patches + "/0007-surface-button.patch"; + } + { + name = "ms-surface/0008-surface-typecover"; + patch = patches + "/0008-surface-typecover.patch"; + } + { + name = "ms-surface/0009-surface-gpe"; + patch = patches + "/0009-surface-gpe.patch"; + } + { + name = "ms-surface/0010-cameras"; + patch = patches + "/0010-cameras.patch"; + } + { + name = "ms-surface/0011-amd-gpio"; + patch = patches + "/0011-amd-gpio.patch"; + } + ]; + }; + +in { + options.microsoft-surface.kernel-version = mkOption { + type = types.enum [ "5.19.17" ]; + }; + + config = mkIf (cfg == "5.19.17") { + boot = { + inherit kernelPackages; + }; + }; +} diff --git a/microsoft/surface/kernel/linux-package.nix b/microsoft/surface/kernel/linux-package.nix new file mode 100644 index 0000000..4858e4f --- /dev/null +++ b/microsoft/surface/kernel/linux-package.nix @@ -0,0 +1,23 @@ +{ lib, + buildLinux, + callPackage, + fetchurl, + linuxPackagesFor, +}: + +let + inherit (lib) kernel recurseIntoAttrs; + +in { + repos = callPackage ../repos.nix {}; + + linuxPackage = + { version, + modDirVersion ? version, + ... + } @ args: + let + buildLinux' = buildLinux (args // { inherit modDirVersion; }); + linuxPackagesFor' = linuxPackagesFor buildLinux'; + in recurseIntoAttrs linuxPackagesFor'; +} From e84ab22523d77f340594282b130ebcfbbdb93a5b Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 17:38:21 +1300 Subject: [PATCH 15/17] Extract the kernel patches out --- .../surface/kernel/linux-5.19.17/default.nix | 130 +----------------- .../surface/kernel/linux-5.19.17/patches.nix | 123 +++++++++++++++++ 2 files changed, 130 insertions(+), 123 deletions(-) create mode 100644 microsoft/surface/kernel/linux-5.19.17/patches.nix diff --git a/microsoft/surface/kernel/linux-5.19.17/default.nix b/microsoft/surface/kernel/linux-5.19.17/default.nix index e1bf29d..d33a43e 100644 --- a/microsoft/surface/kernel/linux-5.19.17/default.nix +++ b/microsoft/surface/kernel/linux-5.19.17/default.nix @@ -1,7 +1,7 @@ { config, lib, pkgs, ... }: let - inherit (lib) kernel mkIf mkOption types; + inherit (lib) mkIf mkOption types; inherit (pkgs) fetchurl; inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage repos; @@ -10,134 +10,18 @@ let version = "5.19.17"; extraMeta.branch = "5.19"; - patches = repos.linux-surface + "/patches/${extraMeta.branch}"; + patchDir = repos.linux-surface + "/patches/${extraMeta.branch}"; + kernelPatches = pkgs.callPackage ./patches.nix { + inherit (lib) kernel; + inherit version patchDir; + }; kernelPackages = linuxPackage { - inherit version extraMeta; - # modDirVersion = version; + inherit version extraMeta kernelPatches; src = fetchurl { url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz"; sha256 = "sha256-yTuzhKl60fCk8Y5ELOApEkJyL3gCPspliyI0RUHwlIk="; }; - - kernelPatches = [ - { - name = "microsoft-surface-patches-linux-${version}"; - patch = null; - structuredExtraConfig = with lib.kernel; { - # - # Surface Aggregator Module - # - SURFACE_AGGREGATOR = module; - SURFACE_AGGREGATOR_ERROR_INJECTION = no; - SURFACE_AGGREGATOR_BUS = yes; - SURFACE_AGGREGATOR_CDEV = module; - SURFACE_AGGREGATOR_REGISTRY = module; - - SURFACE_ACPI_NOTIFY = module; - SURFACE_DTX = module; - SURFACE_PLATFORM_PROFILE = module; - - SURFACE_HID = module; - SURFACE_KBD = module; - - BATTERY_SURFACE = module; - CHARGER_SURFACE = module; - - # - # Surface laptop 1 keyboard - # - SERIAL_DEV_BUS = yes; - SERIAL_DEV_CTRL_TTYPORT = yes; - - # - # Surface Hotplug - # - SURFACE_HOTPLUG = module; - - # - # IPTS touchscreen - # - # This only enables the user interface for IPTS data. - # For the touchscreen to work, you need to install iptsd. - # - MISC_IPTS = module; - - # - # Cameras: IPU3 - # - VIDEO_IPU3_IMGU = module; - VIDEO_IPU3_CIO2 = module; - CIO2_BRIDGE = yes; - INTEL_SKL_INT3472 = module; - - # - # Cameras: Sensor drivers - # - VIDEO_OV5693 = module; - VIDEO_OV8865 = module; - - # - # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 - # - APDS9960 = module; - - # - # Other Drivers - # - INPUT_SOC_BUTTON_ARRAY = module; - SURFACE_3_BUTTON = module; - SURFACE_3_POWER_OPREGION = module; - SURFACE_PRO3_BUTTON = module; - SURFACE_GPE = module; - SURFACE_BOOK1_DGPU_SWITCH = module; - }; - } - { - name = "ms-surface/0001-surface3-oemb"; - patch = patches + "/0001-surface3-oemb.patch"; - } - { - name = "ms-surface/0002-mwifiex"; - patch = patches + "/0002-mwifiex.patch"; - } - { - name = "ms-surface/0003-ath10k"; - patch = patches + "/0003-ath10k.patch"; - } - { - name = "ms-surface/0004-ipts"; - patch = patches + "/0004-ipts.patch"; - } - { - name = "ms-surface/0005-surface-sam"; - patch = patches + "/0005-surface-sam.patch"; - } - { - name = "ms-surface/0006-surface-sam-over-hid"; - patch = patches + "/0006-surface-sam-over-hid.patch"; - } - { - name = "ms-surface/0007-surface-button"; - patch = patches + "/0007-surface-button.patch"; - } - { - name = "ms-surface/0008-surface-typecover"; - patch = patches + "/0008-surface-typecover.patch"; - } - { - name = "ms-surface/0009-surface-gpe"; - patch = patches + "/0009-surface-gpe.patch"; - } - { - name = "ms-surface/0010-cameras"; - patch = patches + "/0010-cameras.patch"; - } - { - name = "ms-surface/0011-amd-gpio"; - patch = patches + "/0011-amd-gpio.patch"; - } - ]; }; in { diff --git a/microsoft/surface/kernel/linux-5.19.17/patches.nix b/microsoft/surface/kernel/linux-5.19.17/patches.nix new file mode 100644 index 0000000..86a7141 --- /dev/null +++ b/microsoft/surface/kernel/linux-5.19.17/patches.nix @@ -0,0 +1,123 @@ +{ kernel, + patchDir, + version, +}: + +[ + { + name = "microsoft-surface-patches-linux-${version}"; + patch = null; + structuredExtraConfig = with kernel; { + # + # Surface Aggregator Module + # + SURFACE_AGGREGATOR = module; + SURFACE_AGGREGATOR_ERROR_INJECTION = no; + SURFACE_AGGREGATOR_BUS = yes; + SURFACE_AGGREGATOR_CDEV = module; + SURFACE_AGGREGATOR_REGISTRY = module; + + SURFACE_ACPI_NOTIFY = module; + SURFACE_DTX = module; + SURFACE_PLATFORM_PROFILE = module; + + SURFACE_HID = module; + SURFACE_KBD = module; + + BATTERY_SURFACE = module; + CHARGER_SURFACE = module; + + # + # Surface laptop 1 keyboard + # + SERIAL_DEV_BUS = yes; + SERIAL_DEV_CTRL_TTYPORT = yes; + + # + # Surface Hotplug + # + SURFACE_HOTPLUG = module; + + # + # IPTS touchscreen + # + # This only enables the user interface for IPTS data. + # For the touchscreen to work, you need to install iptsd. + # + MISC_IPTS = module; + + # + # Cameras: IPU3 + # + VIDEO_IPU3_IMGU = module; + VIDEO_IPU3_CIO2 = module; + CIO2_BRIDGE = yes; + INTEL_SKL_INT3472 = module; + + # + # Cameras: Sensor drivers + # + VIDEO_OV5693 = module; + VIDEO_OV8865 = module; + + # + # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 + # + APDS9960 = module; + + # + # Other Drivers + # + INPUT_SOC_BUTTON_ARRAY = module; + SURFACE_3_BUTTON = module; + SURFACE_3_POWER_OPREGION = module; + SURFACE_PRO3_BUTTON = module; + SURFACE_GPE = module; + SURFACE_BOOK1_DGPU_SWITCH = module; + }; + } + { + name = "ms-surface/0001-surface3-oemb"; + patch = patchDir + "/0001-surface3-oemb.patch"; + } + { + name = "ms-surface/0002-mwifiex"; + patch = patchDir + "/0002-mwifiex.patch"; + } + { + name = "ms-surface/0003-ath10k"; + patch = patchDir + "/0003-ath10k.patch"; + } + { + name = "ms-surface/0004-ipts"; + patch = patchDir + "/0004-ipts.patch"; + } + { + name = "ms-surface/0005-surface-sam"; + patch = patchDir + "/0005-surface-sam.patch"; + } + { + name = "ms-surface/0006-surface-sam-over-hid"; + patch = patchDir + "/0006-surface-sam-over-hid.patch"; + } + { + name = "ms-surface/0007-surface-button"; + patch = patchDir + "/0007-surface-button.patch"; + } + { + name = "ms-surface/0008-surface-typecover"; + patch = patchDir + "/0008-surface-typecover.patch"; + } + { + name = "ms-surface/0009-surface-gpe"; + patch = patchDir + "/0009-surface-gpe.patch"; + } + { + name = "ms-surface/0010-cameras"; + patch = patchDir + "/0010-cameras.patch"; + } + { + name = "ms-surface/0011-amd-gpio"; + patch = patchDir + "/0011-amd-gpio.patch"; + } +] From be728899cfc9c9c53910b5f1bb928c06fd6688ff Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 17:39:24 +1300 Subject: [PATCH 16/17] Tidy-up --- microsoft/surface/default.nix | 2 +- microsoft/surface/kernel/default.nix | 5 ++--- microsoft/surface/kernel/linux-5.19.17/default.nix | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/microsoft/surface/default.nix b/microsoft/surface/default.nix index e193d2a..22f6c6c 100644 --- a/microsoft/surface/default.nix +++ b/microsoft/surface/default.nix @@ -9,7 +9,7 @@ in { ./firmware/surface-go/ath10k ]; - microsoft-surface.kernel-version = mkDefault "5.19.17"; + microsoft-surface.kernelVersion = mkDefault "5.19.17"; boot.extraModprobeConfig = mkDefault '' options i915 enable_fbc=1 enable_rc6=1 modeset=1 diff --git a/microsoft/surface/kernel/default.nix b/microsoft/surface/kernel/default.nix index 0c8dcfc..627ed3d 100644 --- a/microsoft/surface/kernel/default.nix +++ b/microsoft/surface/kernel/default.nix @@ -8,9 +8,8 @@ in { ./linux-5.19.17 ]; - options.microsoft-surface.kernel-version = mkOption { + options.microsoft-surface.kernelVersion = mkOption { description = "Kernel Version to use (patched for MS Surface)"; - type = types.enum [ ]; - # default = "5.19.17"; + type = types.enum [ ]; }; } diff --git a/microsoft/surface/kernel/linux-5.19.17/default.nix b/microsoft/surface/kernel/linux-5.19.17/default.nix index d33a43e..6cc1830 100644 --- a/microsoft/surface/kernel/linux-5.19.17/default.nix +++ b/microsoft/surface/kernel/linux-5.19.17/default.nix @@ -6,7 +6,7 @@ let inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage repos; - cfg = config.microsoft-surface.kernel-version; + cfg = config.microsoft-surface; version = "5.19.17"; extraMeta.branch = "5.19"; @@ -25,11 +25,11 @@ let }; in { - options.microsoft-surface.kernel-version = mkOption { + options.microsoft-surface.kernelVersion = mkOption { type = types.enum [ "5.19.17" ]; }; - config = mkIf (cfg == "5.19.17") { + config = mkIf (cfg.kernelVersion == "5.19.17") { boot = { inherit kernelPackages; }; From cd760508241d2bfe18c2aed64cee04043694ac14 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 5 Dec 2022 17:51:33 +1300 Subject: [PATCH 17/17] Update for code refactor --- microsoft/surface/default.nix | 2 +- microsoft/surface/kernel/linux-6.0.11.nix | 133 ------------------ .../surface/kernel/linux-6.0.11/default.nix | 38 +++++ .../surface/kernel/linux-6.0.11/patches.nix | 118 ++++++++++++++++ 4 files changed, 157 insertions(+), 134 deletions(-) delete mode 100644 microsoft/surface/kernel/linux-6.0.11.nix create mode 100644 microsoft/surface/kernel/linux-6.0.11/default.nix create mode 100644 microsoft/surface/kernel/linux-6.0.11/patches.nix diff --git a/microsoft/surface/default.nix b/microsoft/surface/default.nix index 22f6c6c..9a59e9f 100644 --- a/microsoft/surface/default.nix +++ b/microsoft/surface/default.nix @@ -9,7 +9,7 @@ in { ./firmware/surface-go/ath10k ]; - microsoft-surface.kernelVersion = mkDefault "5.19.17"; + microsoft-surface.kernelVersion = mkDefault "6.0.11"; boot.extraModprobeConfig = mkDefault '' options i915 enable_fbc=1 enable_rc6=1 modeset=1 diff --git a/microsoft/surface/kernel/linux-6.0.11.nix b/microsoft/surface/kernel/linux-6.0.11.nix deleted file mode 100644 index 1eb2f84..0000000 --- a/microsoft/surface/kernel/linux-6.0.11.nix +++ /dev/null @@ -1,133 +0,0 @@ -{ lib, - fetchurl, - repos, -}: - -let - inherit (lib) kernel; - version = "6.0.11"; - branch = "6.0"; - patches = repos.linux-surface + "/patches/${branch}"; - -in { - inherit version branch; - modDirVersion = version; - src = fetchurl { - url = "mirror://kernel/linux/kernel/v6.x/linux-${version}.tar.xz"; - sha256 = "sha256-K65hMeZJceHjT/OV+lQpcRNMhXvbCykGmrhHx8mpx2I="; - }; - - kernelPatches = [ - { - name = "microsoft-surface-patches-linux-${version}"; - patch = null; - structuredExtraConfig = with lib.kernel; { - # - # Surface Aggregator Module - # - CONFIG_SURFACE_AGGREGATOR = module; - CONFIG_SURFACE_AGGREGATOR_ERROR_INJECTION = no; - CONFIG_SURFACE_AGGREGATOR_BUS = yes; - CONFIG_SURFACE_AGGREGATOR_CDEV = module; - CONFIG_SURFACE_AGGREGATOR_HUB = module; - CONFIG_SURFACE_AGGREGATOR_REGISTRY = module; - CONFIG_SURFACE_AGGREGATOR_TABLET_SWITCH = module; - - CONFIG_SURFACE_ACPI_NOTIFY = module; - CONFIG_SURFACE_DTX = module; - CONFIG_SURFACE_PLATFORM_PROFILE = module; - - CONFIG_SURFACE_HID = module; - CONFIG_SURFACE_KBD = module; - - CONFIG_BATTERY_SURFACE = module; - CONFIG_CHARGER_SURFACE = module; - - # - # Surface Hotplug - # - CONFIG_SURFACE_HOTPLUG = module; - - # - # IPTS touchscreen - # - # This only enables the user interface for IPTS data. - # For the touchscreen to work, you need to install iptsd. - # - CONFIG_MISC_IPTS = module; - - # - # Cameras: IPU3 - # - CONFIG_VIDEO_DW9719 = module; - CONFIG_VIDEO_IPU3_IMGU = module; - CONFIG_VIDEO_IPU3_CIO2 = module; - CONFIG_CIO2_BRIDGE = yes; - CONFIG_INTEL_SKL_INT3472 = module; - CONFIG_REGULATOR_TPS68470 = module; - CONFIG_COMMON_CLK_TPS68470 = module; - - # - # Cameras: Sensor drivers - # - CONFIG_VIDEO_OV5693 = module; - CONFIG_VIDEO_OV7251 = module; - CONFIG_VIDEO_OV8865 = module; - - # - # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 - # - CONFIG_APDS9960 = module; - - # - # Other Drivers - # - CONFIG_INPUT_SOC_BUTTON_ARRAY = module; - CONFIG_SURFACE_3_POWER_OPREGION = module; - CONFIG_SURFACE_PRO3_BUTTON = module; - CONFIG_SURFACE_GPE = module; - CONFIG_SURFACE_BOOK1_DGPU_SWITCH = module; - }; - } - { - name = "ms-surface/0001-surface3-oemb"; - patch = patches + "/0001-surface3-oemb.patch"; - } - { - name = "ms-surface/0002-mwifiex"; - patch = patches + "/0002-mwifiex.patch"; - } - { - name = "ms-surface/0003-ath10k"; - patch = patches + "/0003-ath10k.patch"; - } - { - name = "ms-surface/0004-ipts"; - patch = patches + "/0004-ipts.patch"; - } - { - name = "ms-surface/0005-surface-sam"; - patch = patches + "/0005-surface-sam.patch"; - } - { - name = "ms-surface/0006-surface-sam-over-hid"; - patch = patches + "/0006-surface-sam-over-hid.patch"; - } - { - name = "ms-surface/0007-surface-button"; - patch = patches + "/0007-surface-button.patch"; - } - { - name = "ms-surface/0008-surface-typecover"; - patch = patches + "/0008-surface-typecover.patch"; - } - { - name = "ms-surface/0009-cameras"; - patch = patches + "/0009-cameras.patch"; - } - # { - # name = "ms-surface/0010-amd-gpio"; - # patch = patches + "/0010-amd-gpio.patch"; - # } - ]; -} diff --git a/microsoft/surface/kernel/linux-6.0.11/default.nix b/microsoft/surface/kernel/linux-6.0.11/default.nix new file mode 100644 index 0000000..652f241 --- /dev/null +++ b/microsoft/surface/kernel/linux-6.0.11/default.nix @@ -0,0 +1,38 @@ +{ config, lib, pkgs, ... }: + +let + inherit (lib) mkIf mkOption types; + inherit (pkgs) fetchurl; + + inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage repos; + + cfg = config.microsoft-surface; + + version = "6.0.11"; + extraMeta.branch = "6.0"; + patchDir = repos.linux-surface + "/patches/${extraMeta.branch}"; + kernelPatches = pkgs.callPackage ./patches.nix { + inherit (lib) kernel; + inherit version patchDir; + }; + + kernelPackages = linuxPackage { + inherit version extraMeta kernelPatches; + src = fetchurl { + url = "mirror://kernel/linux/kernel/v6.x/linux-${version}.tar.xz"; + sha256 = "sha256-K65hMeZJceHjT/OV+lQpcRNMhXvbCykGmrhHx8mpx2I="; + }; + }; + + +in { + options.microsoft-surface.kernelVersion = mkOption { + type = types.enum [ "6.0.11" ]; + }; + + config = mkIf (cfg.kernelVersion == "6.0.11") { + boot = { + inherit kernelPackages; + }; + }; +} diff --git a/microsoft/surface/kernel/linux-6.0.11/patches.nix b/microsoft/surface/kernel/linux-6.0.11/patches.nix new file mode 100644 index 0000000..e111c26 --- /dev/null +++ b/microsoft/surface/kernel/linux-6.0.11/patches.nix @@ -0,0 +1,118 @@ +{ kernel, + patchDir, + version, +}: + +[ + { + name = "microsoft-surface-patches-linux-${version}"; + patch = null; + structuredExtraConfig = with kernel; { + # + # Surface Aggregator Module + # + CONFIG_SURFACE_AGGREGATOR = module; + CONFIG_SURFACE_AGGREGATOR_ERROR_INJECTION = no; + CONFIG_SURFACE_AGGREGATOR_BUS = yes; + CONFIG_SURFACE_AGGREGATOR_CDEV = module; + CONFIG_SURFACE_AGGREGATOR_HUB = module; + CONFIG_SURFACE_AGGREGATOR_REGISTRY = module; + CONFIG_SURFACE_AGGREGATOR_TABLET_SWITCH = module; + + CONFIG_SURFACE_ACPI_NOTIFY = module; + CONFIG_SURFACE_DTX = module; + CONFIG_SURFACE_PLATFORM_PROFILE = module; + + CONFIG_SURFACE_HID = module; + CONFIG_SURFACE_KBD = module; + + CONFIG_BATTERY_SURFACE = module; + CONFIG_CHARGER_SURFACE = module; + + # + # Surface Hotplug + # + CONFIG_SURFACE_HOTPLUG = module; + + # + # IPTS touchscreen + # + # This only enables the user interface for IPTS data. + # For the touchscreen to work, you need to install iptsd. + # + CONFIG_MISC_IPTS = module; + + # + # Cameras: IPU3 + # + CONFIG_VIDEO_DW9719 = module; + CONFIG_VIDEO_IPU3_IMGU = module; + CONFIG_VIDEO_IPU3_CIO2 = module; + CONFIG_CIO2_BRIDGE = yes; + CONFIG_INTEL_SKL_INT3472 = module; + CONFIG_REGULATOR_TPS68470 = module; + CONFIG_COMMON_CLK_TPS68470 = module; + + # + # Cameras: Sensor drivers + # + CONFIG_VIDEO_OV5693 = module; + CONFIG_VIDEO_OV7251 = module; + CONFIG_VIDEO_OV8865 = module; + + # + # ALS Sensor for Surface Book 3, Surface Laptop 3, Surface Pro 7 + # + CONFIG_APDS9960 = module; + + # + # Other Drivers + # + CONFIG_INPUT_SOC_BUTTON_ARRAY = module; + CONFIG_SURFACE_3_POWER_OPREGION = module; + CONFIG_SURFACE_PRO3_BUTTON = module; + CONFIG_SURFACE_GPE = module; + CONFIG_SURFACE_BOOK1_DGPU_SWITCH = module; + }; + } + { + name = "ms-surface/0001-surface3-oemb"; + patch = patchDir + "/0001-surface3-oemb.patch"; + } + { + name = "ms-surface/0002-mwifiex"; + patch = patchDir + "/0002-mwifiex.patch"; + } + { + name = "ms-surface/0003-ath10k"; + patch = patchDir + "/0003-ath10k.patch"; + } + { + name = "ms-surface/0004-ipts"; + patch = patchDir + "/0004-ipts.patch"; + } + { + name = "ms-surface/0005-surface-sam"; + patch = patchDir + "/0005-surface-sam.patch"; + } + { + name = "ms-surface/0006-surface-sam-over-hid"; + patch = patchDir + "/0006-surface-sam-over-hid.patch"; + } + { + name = "ms-surface/0007-surface-button"; + patch = patchDir + "/0007-surface-button.patch"; + } + { + name = "ms-surface/0008-surface-typecover"; + patch = patchDir + "/0008-surface-typecover.patch"; + } + { + name = "ms-surface/0009-cameras"; + patch = patchDir + "/0009-cameras.patch"; + } + # { + # name = "ms-surface/0010-amd-gpio"; + # patch = patchDir + "/0010-amd-gpio.patch"; + # } +]