From b32b188154bda2f0b430afac19e404216aaded23 Mon Sep 17 00:00:00 2001 From: mexisme Date: Mon, 28 Nov 2022 20:00:53 +1300 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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 {