From da36847d925058fd86f027b64cc712c57be11ad8 Mon Sep 17 00:00:00 2001 From: Charles Strahan Date: Sat, 30 Apr 2016 00:19:57 -0400 Subject: [PATCH] nixos: make it easy to apply kernel patches This makes it easy to specify kernel patches: boot.kernelPatches = [ pkgs.kernelPatches.ubuntu_fan_4_4 ]; To make the `boot.kernelPatches` option possible, this also makes it easy to extend and/or modify the kernel packages within a linuxPackages set. For example: pkgs.linuxPackages.extend (self: super: { kernel = super.kernel.override { kernelPatches = super.kernel.kernelPatches ++ [ pkgs.kernelPatches.ubuntu_fan_4_4 ]; }; }); Closes #15095 --- lib/trivial.nix | 21 +++++++++++++ nixos/modules/system/boot/kernel.nix | 16 +++++++++- pkgs/top-level/all-packages.nix | 45 ++++++++++++++-------------- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/lib/trivial.nix b/lib/trivial.nix index 3e606f0df48f..a0c31757ba7a 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -53,6 +53,27 @@ rec { # argument, but it's nice this way if several uses of `extends` are cascaded. extends = f: rattrs: self: let super = rattrs self; in super // f self super; + # Create an overridable, recursive attribute set. For example: + # + # nix-repl> obj = makeExtensible (self: { }) + # + # nix-repl> obj + # { __unfix__ = «lambda»; extend = «lambda»; } + # + # nix-repl> obj = obj.extend (self: super: { foo = "foo"; }) + # + # nix-repl> obj + # { __unfix__ = «lambda»; extend = «lambda»; foo = "foo"; } + # + # nix-repl> obj = obj.extend (self: super: { foo = super.foo + " + "; bar = "bar"; foobar = self.foo + self.bar; }) + # + # nix-repl> obj + # { __unfix__ = «lambda»; bar = "bar"; extend = «lambda»; foo = "foo + "; foobar = "foo + bar"; } + makeExtensible = rattrs: + fix' rattrs // { + extend = f: makeExtensible (extends f rattrs); + }; + # Flip the order of the arguments of a binary function. flip = f: a: b: f b a; diff --git a/nixos/modules/system/boot/kernel.nix b/nixos/modules/system/boot/kernel.nix index ba15d0318b17..51b3b8a3dca9 100644 --- a/nixos/modules/system/boot/kernel.nix +++ b/nixos/modules/system/boot/kernel.nix @@ -4,7 +4,9 @@ with lib; let - kernel = config.boot.kernelPackages.kernel; + inherit (config.boot) kernelPatches; + + inherit (config.boot.kernelPackages) kernel; kernelModulesConf = pkgs.writeText "nixos.conf" '' @@ -21,6 +23,11 @@ in boot.kernelPackages = mkOption { default = pkgs.linuxPackages; + apply = kernelPackages: kernelPackages.extend (self: super: { + kernel = super.kernel.override { + kernelPatches = super.kernel.kernelPatches ++ kernelPatches; + }; + }); # We don't want to evaluate all of linuxPackages for the manual # - some of it might not even evaluate correctly. defaultText = "pkgs.linuxPackages"; @@ -39,6 +46,13 @@ in ''; }; + boot.kernelPatches = mkOption { + type = types.listOf types.attrs; + default = []; + example = literalExample "[ pkgs.kernelPatches.ubuntu_fan_4_4 ]"; + description = "A list of additional patches to apply to the kernel."; + }; + boot.kernelParams = mkOption { type = types.listOf types.str; default = [ ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index baf918453876..e6e1b94a2a67 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -10873,7 +10873,9 @@ in for a specific kernel. This function can then be called for whatever kernel you're using. */ - linuxPackagesFor = kernel: self: let callPackage = newScope self; in rec { + linuxPackagesFor = kernel: lib.makeExtensible (self: with self; { + callPackage = newScope self; + inherit kernel; accelio = callPackage ../development/libraries/accelio { }; @@ -10991,7 +10993,7 @@ in configFile = "kernel"; inherit kernel spl; }; - }; + }); # The current default kernel / kernel modules. linuxPackages = linuxPackages_4_4; @@ -11002,29 +11004,27 @@ in linux_latest = linuxPackages_latest.kernel; # Build the kernel modules for the some of the kernels. - linuxPackages_mptcp = linuxPackagesFor pkgs.linux_mptcp linuxPackages_mptcp; - linuxPackages_rpi = linuxPackagesFor pkgs.linux_rpi linuxPackages_rpi; - linuxPackages_3_10 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_3_10 linuxPackages_3_10); - linuxPackages_3_10_tuxonice = linuxPackagesFor pkgs.linux_3_10_tuxonice linuxPackages_3_10_tuxonice; - linuxPackages_3_12 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_3_12 linuxPackages_3_12); - linuxPackages_3_18 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_3_18 linuxPackages_3_18); - linuxPackages_4_1 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_1 linuxPackages_4_1); - linuxPackages_4_4 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_4 linuxPackages_4_4); - linuxPackages_4_7 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_7 linuxPackages_4_7); - linuxPackages_4_8 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_8 linuxPackages_4_8); + linuxPackages_mptcp = linuxPackagesFor pkgs.linux_mptcp; + linuxPackages_rpi = linuxPackagesFor pkgs.linux_rpi; + linuxPackages_3_10 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_3_10); + linuxPackages_3_10_tuxonice = linuxPackagesFor pkgs.linux_3_10_tuxonice; + linuxPackages_3_12 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_3_12); + linuxPackages_3_18 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_3_18); + linuxPackages_4_1 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_1); + linuxPackages_4_4 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_4); + linuxPackages_4_7 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_7); + linuxPackages_4_8 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_4_8); # Don't forget to update linuxPackages_latest! # Intentionally lacks recurseIntoAttrs, as -rc kernels will quite likely break out-of-tree modules and cause failed Hydra builds. - linuxPackages_testing = linuxPackagesFor pkgs.linux_testing linuxPackages_testing; + linuxPackages_testing = linuxPackagesFor pkgs.linux_testing; linuxPackages_custom = {version, src, configfile}: - let linuxPackages_self = (linuxPackagesFor (pkgs.linuxManualConfig {inherit version src configfile; - allowImportFromDerivation=true;}) - linuxPackages_self); - in recurseIntoAttrs linuxPackages_self; + recurseIntoAttrs (linuxPackagesFor (pkgs.linuxManualConfig {inherit version src configfile; + allowImportFromDerivation=true;})); # Build a kernel for Xen dom0 - linuxPackages_latest_xen_dom0 = recurseIntoAttrs (linuxPackagesFor (pkgs.linux_latest.override { features.xen_dom0=true; }) linuxPackages_latest); + linuxPackages_latest_xen_dom0 = recurseIntoAttrs (linuxPackagesFor (pkgs.linux_latest.override { features.xen_dom0=true; })); # Grsecurity packages @@ -11044,8 +11044,7 @@ in }; linuxPackages_grsec_nixos = - let self = linuxPackagesFor linux_grsec_nixos self; - in recurseIntoAttrs self; + recurseIntoAttrs (linuxPackagesFor linux_grsec_nixos); # An unsupported grsec xen guest kernel linux_grsec_server_xen = linux_grsec_nixos.override { @@ -11059,9 +11058,9 @@ in }; # ChromiumOS kernels - linuxPackages_chromiumos_3_14 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_chromiumos_3_14 linuxPackages_chromiumos_3_14); - linuxPackages_chromiumos_3_18 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_chromiumos_3_18 linuxPackages_chromiumos_3_18); - linuxPackages_chromiumos_latest = recurseIntoAttrs (linuxPackagesFor pkgs.linux_chromiumos_latest linuxPackages_chromiumos_latest); + linuxPackages_chromiumos_3_14 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_chromiumos_3_14); + linuxPackages_chromiumos_3_18 = recurseIntoAttrs (linuxPackagesFor pkgs.linux_chromiumos_3_18); + linuxPackages_chromiumos_latest = recurseIntoAttrs (linuxPackagesFor pkgs.linux_chromiumos_latest); # A function to build a manually-configured kernel linuxManualConfig = pkgs.buildLinux;