From 8605f354e2409ce5f7a9ad3589427e3d11937674 Mon Sep 17 00:00:00 2001 From: mexisme Date: Sun, 26 Nov 2023 12:42:11 +1300 Subject: [PATCH] Use a new linuxPackage function --- .../common/kernel/linux-6.1.x/default.nix | 8 +-- .../common/kernel/linux-6.1.x/patches.nix | 33 +++++++------ .../common/kernel/linux-6.5.x/default.nix | 8 +-- .../common/kernel/linux-6.5.x/patches.nix | 33 +++++++------ .../surface/common/kernel/linux-package.nix | 49 ++++++++++++++++--- 5 files changed, 84 insertions(+), 47 deletions(-) diff --git a/microsoft/surface/common/kernel/linux-6.1.x/default.nix b/microsoft/surface/common/kernel/linux-6.1.x/default.nix index 05ec4cf..45105cc 100644 --- a/microsoft/surface/common/kernel/linux-6.1.x/default.nix +++ b/microsoft/surface/common/kernel/linux-6.1.x/default.nix @@ -4,19 +4,19 @@ let inherit (lib) mkIf mkOption types; inherit (pkgs) fetchurl; - inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage repos; + inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage1 repos; cfg = config.microsoft-surface; version = "6.1.62"; extraMeta.branch = "6.1"; - patchDir = repos.linux-surface + "/patches/${extraMeta.branch}"; + patchSrc = repos.linux-surface + "/patches/${extraMeta.branch}"; kernelPatches = pkgs.callPackage ./patches.nix { inherit (lib) kernel; - inherit version patchDir; + inherit version patchSrc; }; - kernelPackages = linuxPackage { + kernelPackages = linuxPackage1 { inherit version extraMeta kernelPatches; src = fetchurl { url = "mirror://kernel/linux/kernel/v6.x/linux-${version}.tar.xz"; diff --git a/microsoft/surface/common/kernel/linux-6.1.x/patches.nix b/microsoft/surface/common/kernel/linux-6.1.x/patches.nix index e197649..5af71be 100644 --- a/microsoft/surface/common/kernel/linux-6.1.x/patches.nix +++ b/microsoft/surface/common/kernel/linux-6.1.x/patches.nix @@ -1,5 +1,6 @@ -{ kernel, - patchDir, +{ lib, + kernel ? lib.kernel, + patchSrc, version, }: @@ -84,58 +85,58 @@ } { name = "ms-surface/0001-surface3-oemb"; - patch = patchDir + "/0001-surface3-oemb.patch"; + patch = patchSrc + "/0001-surface3-oemb.patch"; } { name = "ms-surface/0002-mwifiex"; - patch = patchDir + "/0002-mwifiex.patch"; + patch = patchSrc + "/0002-mwifiex.patch"; } { name = "ms-surface/0003-ath10k"; - patch = patchDir + "/0003-ath10k.patch"; + patch = patchSrc + "/0003-ath10k.patch"; } { name = "ms-surface/0004-ipts"; - patch = patchDir + "/0004-ipts.patch"; + patch = patchSrc + "/0004-ipts.patch"; } { name = "ms-surface/0005-ithc"; - patch = patchDir + "/0005-ithc.patch"; + patch = patchSrc + "/0005-ithc.patch"; } { name = "ms-surface/0006-surface-sam"; - patch = patchDir + "/0006-surface-sam.patch"; + patch = patchSrc + "/0006-surface-sam.patch"; } { name = "ms-surface/0007-surface-sam-over-hid"; - patch = patchDir + "/0007-surface-sam-over-hid.patch"; + patch = patchSrc + "/0007-surface-sam-over-hid.patch"; } { name = "ms-surface/0008-surface-button"; - patch = patchDir + "/0008-surface-button.patch"; + patch = patchSrc + "/0008-surface-button.patch"; } { name = "ms-surface/0009-surface-typecover"; - patch = patchDir + "/0009-surface-typecover.patch"; + patch = patchSrc + "/0009-surface-typecover.patch"; } { name = "ms-surface/0010-surface-shutdown"; - patch = patchDir + "/0010-surface-shutdown.patch"; + patch = patchSrc + "/0010-surface-shutdown.patch"; } { name = "ms-surface/0011-surface-gpe"; - patch = patchDir + "/0011-surface-gpe.patch"; + patch = patchSrc + "/0011-surface-gpe.patch"; } { name = "ms-surface/0012-cameras"; - patch = patchDir + "/0012-cameras.patch"; + patch = patchSrc + "/0012-cameras.patch"; } { name = "ms-surface/0013-amd-gpio"; - patch = patchDir + "/0013-amd-gpio.patch"; + patch = patchSrc + "/0013-amd-gpio.patch"; } { name = "ms-surface/0014-rtc"; - patch = patchDir + "/0014-rtc.patch"; + patch = patchSrc + "/0014-rtc.patch"; } ] diff --git a/microsoft/surface/common/kernel/linux-6.5.x/default.nix b/microsoft/surface/common/kernel/linux-6.5.x/default.nix index b26b466..0d90108 100644 --- a/microsoft/surface/common/kernel/linux-6.5.x/default.nix +++ b/microsoft/surface/common/kernel/linux-6.5.x/default.nix @@ -4,19 +4,19 @@ let inherit (lib) mkIf mkOption types; inherit (pkgs) fetchurl; - inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage repos; + inherit (pkgs.callPackage ../linux-package.nix { }) linuxPackage1 repos; cfg = config.microsoft-surface; version = "6.5.11"; extraMeta.branch = "6.5"; - patchDir = repos.linux-surface + "/patches/${extraMeta.branch}"; + patchSrc = repos.linux-surface + "/patches/${extraMeta.branch}"; kernelPatches = pkgs.callPackage ./patches.nix { inherit (lib) kernel; - inherit version patchDir; + inherit version patchSrc; }; - kernelPackages = linuxPackage { + kernelPackages = linuxPackage1 { inherit version extraMeta kernelPatches; src = fetchurl { url = "mirror://kernel/linux/kernel/v6.x/linux-${version}.tar.xz"; diff --git a/microsoft/surface/common/kernel/linux-6.5.x/patches.nix b/microsoft/surface/common/kernel/linux-6.5.x/patches.nix index d7b9289..148f8b2 100644 --- a/microsoft/surface/common/kernel/linux-6.5.x/patches.nix +++ b/microsoft/surface/common/kernel/linux-6.5.x/patches.nix @@ -1,5 +1,6 @@ -{ kernel, - patchDir, +{ lib, + kernel ? lib.kernel, + patchSrc, version, }: @@ -85,58 +86,58 @@ } { name = "ms-surface/0001-surface3-oemb"; - patch = patchDir + "/0001-surface3-oemb.patch"; + patch = patchSrc + "/0001-surface3-oemb.patch"; } { name = "ms-surface/0002-mwifiex"; - patch = patchDir + "/0002-mwifiex.patch"; + patch = patchSrc + "/0002-mwifiex.patch"; } { name = "ms-surface/0003-ath10k"; - patch = patchDir + "/0003-ath10k.patch"; + patch = patchSrc + "/0003-ath10k.patch"; } { name = "ms-surface/0004-ipts"; - patch = patchDir + "/0004-ipts.patch"; + patch = patchSrc + "/0004-ipts.patch"; } { name = "ms-surface/0005-ithc"; - patch = patchDir + "/0005-ithc.patch"; + patch = patchSrc + "/0005-ithc.patch"; } { name = "ms-surface/0006-surface-sam"; - patch = patchDir + "/0006-surface-sam.patch"; + patch = patchSrc + "/0006-surface-sam.patch"; } { name = "ms-surface/0007-surface-sam-over-hid"; - patch = patchDir + "/0007-surface-sam-over-hid.patch"; + patch = patchSrc + "/0007-surface-sam-over-hid.patch"; } { name = "ms-surface/0008-surface-button"; - patch = patchDir + "/0008-surface-button.patch"; + patch = patchSrc + "/0008-surface-button.patch"; } { name = "ms-surface/0009-surface-typecover"; - patch = patchDir + "/0009-surface-typecover.patch"; + patch = patchSrc + "/0009-surface-typecover.patch"; } { name = "ms-surface/0010-surface-shutdown"; - patch = patchDir + "/0010-surface-shutdown.patch"; + patch = patchSrc + "/0010-surface-shutdown.patch"; } { name = "ms-surface/0011-surface-gpe"; - patch = patchDir + "/0011-surface-gpe.patch"; + patch = patchSrc + "/0011-surface-gpe.patch"; } { name = "ms-surface/0012-cameras"; - patch = patchDir + "/0012-cameras.patch"; + patch = patchSrc + "/0012-cameras.patch"; } { name = "ms-surface/0013-amd-gpio"; - patch = patchDir + "/0013-amd-gpio.patch"; + patch = patchSrc + "/0013-amd-gpio.patch"; } { name = "ms-surface/0014-rtc"; - patch = patchDir + "/0014-rtc.patch"; + patch = patchSrc + "/0014-rtc.patch"; } ] diff --git a/microsoft/surface/common/kernel/linux-package.nix b/microsoft/surface/common/kernel/linux-package.nix index c115df1..b4082a4 100644 --- a/microsoft/surface/common/kernel/linux-package.nix +++ b/microsoft/surface/common/kernel/linux-package.nix @@ -1,16 +1,17 @@ -{ lib, +{ pkgs, + lib, + fetchurl, buildLinux, - callPackage, linuxPackagesFor, }: let - inherit (lib) recurseIntoAttrs; + inherit (lib) recurseIntoAttrs versions; + repos = pkgs.callPackage ../repos.nix {}; -in { - repos = callPackage ../repos.nix {}; - - linuxPackage = + # Version 1 of the linuxPackage function: + # (DEPRECATED) + linuxPackage1 = { version, modDirVersion ? version, ... @@ -19,4 +20,38 @@ in { buildLinux' = buildLinux (args // { inherit modDirVersion; }); linuxPackagesFor' = linuxPackagesFor buildLinux'; in recurseIntoAttrs linuxPackagesFor'; + + # Version 1 of the linuxPackage funtion, with hopefully simplified arguments: + linuxPackage2 = + { url ? "mirror://kernel/linux/kernel/v${versions.major version}.x/linux-${version}.tar.xz", + sha256 ? null, + src ? (fetchurl { inherit url sha256; }), + version, + modDirVersion ? (versions.pad 3 version), + kernelPatches ? [], + ... + } @ args: let + inherit (builtins) removeAttrs; + + args' = { + inherit src version modDirVersion kernelPatches; + } // removeAttrs args [ "url" "sha256" ]; + linuxPackage = buildLinux args'; + linuxPackages' = recurseIntoAttrs (linuxPackagesFor linuxPackage); + in linuxPackages'; + + surfacePatches = + { patchSrc ? (repos.linux-surface + "/patches/${versions.major version}"), + version, + patchFn, + }: pkgs.callPackage patchFn { + inherit (lib) kernel; + inherit version patchSrc; + }; + +in { + inherit linuxPackage1 linuxPackage2 repos surfacePatches; + + # Default version: + linuxPackage = linuxPackage2; }