From afa0e02d64b15707262f13a348b33dad735bd80f Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Wed, 18 Sep 2019 17:34:02 +0900 Subject: [PATCH 1/2] lib.kernel: make public Remove the "version" parameter in order to make it more widely available. Starts making some kernel configuration helpers available. The intent is to be able to better build and check the linux kernel configuration. --- lib/default.nix | 3 +++ lib/kernel.nix | 7 +------ pkgs/os-specific/linux/kernel/common-config.nix | 9 +++++++-- pkgs/os-specific/linux/kernel/hardened-config.nix | 3 +-- pkgs/os-specific/linux/kernel/mptcp-config.nix | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 18d2dfae1e1..efa47a67f96 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -52,6 +52,9 @@ let # back-compat aliases platforms = systems.doubles; + # linux kernel configuration + kernel = callLibs ./kernel.nix; + inherit (builtins) add addErrorContext attrNames concatLists deepSeq elem elemAt filter genericClosure genList getAttr hasAttr head isAttrs isBool isInt isList isString length diff --git a/lib/kernel.nix b/lib/kernel.nix index 36ea3083828..bfadf148be2 100644 --- a/lib/kernel.nix +++ b/lib/kernel.nix @@ -1,12 +1,7 @@ -{ lib, version }: +{ lib }: with lib; { - # Common patterns/legacy - whenAtLeast = ver: mkIf (versionAtLeast version ver); - whenOlder = ver: mkIf (versionOlder version ver); - # range is (inclusive, exclusive) - whenBetween = verLow: verHigh: mkIf (versionAtLeast version verLow && versionOlder version verHigh); # Keeping these around in case we decide to change this horrible implementation :) diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index 3b409f15aba..d414a084262 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -16,10 +16,15 @@ }: with stdenv.lib; - - with import ../../../../lib/kernel.nix { inherit (stdenv) lib; inherit version; }; +with stdenv.lib.kernel; let + # Common patterns/legacy + whenAtLeast = ver: mkIf (versionAtLeast version ver); + whenOlder = ver: mkIf (versionOlder version ver); + # range is (inclusive, exclusive) + whenBetween = verLow: verHigh: mkIf (versionAtLeast version verLow && versionOlder version verHigh); + # configuration items have to be part of a subattrs flattenKConf = nested: mapAttrs (_: head) (zipAttrs (attrValues nested)); diff --git a/pkgs/os-specific/linux/kernel/hardened-config.nix b/pkgs/os-specific/linux/kernel/hardened-config.nix index 156a4cf4423..b72994d6dd6 100644 --- a/pkgs/os-specific/linux/kernel/hardened-config.nix +++ b/pkgs/os-specific/linux/kernel/hardened-config.nix @@ -11,8 +11,7 @@ { stdenv, version }: with stdenv.lib; -with import ../../../../lib/kernel.nix { inherit (stdenv) lib; inherit version; }; - +with stdenv.lib.kernel; assert (versionAtLeast version "4.9"); optionalAttrs (stdenv.hostPlatform.platform.kernelArch == "x86_64") { diff --git a/pkgs/os-specific/linux/kernel/mptcp-config.nix b/pkgs/os-specific/linux/kernel/mptcp-config.nix index e5e3ee283ff..9752e63d9f9 100644 --- a/pkgs/os-specific/linux/kernel/mptcp-config.nix +++ b/pkgs/os-specific/linux/kernel/mptcp-config.nix @@ -1,5 +1,5 @@ { stdenv }: -with import ../../../../lib/kernel.nix { inherit (stdenv) lib; version = null; }; +with stdenv.lib.kernel; { # DRM_AMDGPU = yes; From a4fe469d39bdb9a91f9f6c8bbbac15fd836b66ce Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Thu, 19 Sep 2019 20:12:35 +0900 Subject: [PATCH 2/2] lib.kernel: scoped whenXXX helpers whenAtLeast/whenBetween are made available in lib/kernel.nix but are now scoped under whenXXX. --- lib/kernel.nix | 10 ++++++++++ pkgs/os-specific/linux/kernel/common-config.nix | 6 +----- pkgs/os-specific/linux/kernel/hardened-config.nix | 2 ++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/kernel.nix b/lib/kernel.nix index bfadf148be2..2ce19f8cb68 100644 --- a/lib/kernel.nix +++ b/lib/kernel.nix @@ -13,4 +13,14 @@ with lib; module = { tristate = "m"; }; freeform = x: { freeform = x; }; + /* + Common patterns/legacy used in common-config/hardened-config.nix + */ + whenHelpers = version: { + whenAtLeast = ver: mkIf (versionAtLeast version ver); + whenOlder = ver: mkIf (versionOlder version ver); + # range is (inclusive, exclusive) + whenBetween = verLow: verHigh: mkIf (versionAtLeast version verLow && versionOlder version verHigh); + }; + } diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix index d414a084262..126e534520c 100644 --- a/pkgs/os-specific/linux/kernel/common-config.nix +++ b/pkgs/os-specific/linux/kernel/common-config.nix @@ -17,13 +17,9 @@ with stdenv.lib; with stdenv.lib.kernel; +with (stdenv.lib.kernel.whenHelpers version); let - # Common patterns/legacy - whenAtLeast = ver: mkIf (versionAtLeast version ver); - whenOlder = ver: mkIf (versionOlder version ver); - # range is (inclusive, exclusive) - whenBetween = verLow: verHigh: mkIf (versionAtLeast version verLow && versionOlder version verHigh); # configuration items have to be part of a subattrs diff --git a/pkgs/os-specific/linux/kernel/hardened-config.nix b/pkgs/os-specific/linux/kernel/hardened-config.nix index b72994d6dd6..b28ce770f7a 100644 --- a/pkgs/os-specific/linux/kernel/hardened-config.nix +++ b/pkgs/os-specific/linux/kernel/hardened-config.nix @@ -12,6 +12,8 @@ with stdenv.lib; with stdenv.lib.kernel; +with (stdenv.lib.kernel.whenHelpers version); + assert (versionAtLeast version "4.9"); optionalAttrs (stdenv.hostPlatform.platform.kernelArch == "x86_64") {