From b9a4e6953d0234cde64ac0cc55136adb3e92794b Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Wed, 1 Apr 2020 03:20:33 +0200 Subject: kernel: fix config generation Addresses https://github.com/NixOS/nixpkgs/issues/71803: Kernel options are not merged as described, especially the "optional" aspects. The error silences legitimate warnings. --- pkgs/test/kernel.nix | 90 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 32 deletions(-) (limited to 'pkgs/test') diff --git a/pkgs/test/kernel.nix b/pkgs/test/kernel.nix index 86f1b8d8e9ac..a4da10030332 100644 --- a/pkgs/test/kernel.nix +++ b/pkgs/test/kernel.nix @@ -1,53 +1,79 @@ +# to run these tests: +# nix-instantiate --eval --strict . -A tests.kernel-config +# +# make sure to use NON EXISTING kernel settings else they may conflict with +# common-config.nix { lib, pkgs }: -with lib.kernel; -with lib.asserts; -with lib.modules; +with lib; +with kernel; -# To test nixos/modules/system/boot/kernel_config.nix; let - # copied from release-lib.nix - assertTrue = bool: - if bool - then pkgs.runCommand "evaluated-to-true" {} "touch $out" - else pkgs.runCommand "evaluated-to-false" {} "false"; - lts_kernel = pkgs.linuxPackages.kernel; - kernelTestConfig = structuredConfig: (lts_kernel.override { - structuredExtraConfig = structuredConfig; - }).configfile.structuredConfig; + # to see the result once the module transformed the lose structured config + getConfig = structuredConfig: + (lts_kernel.override { + structuredExtraConfig = structuredConfig; + }).configfile.structuredConfig; mandatoryVsOptionalConfig = mkMerge [ - { USB_DEBUG = option yes;} - { USB_DEBUG = yes;} + { NIXOS_FAKE_USB_DEBUG = yes;} + { NIXOS_FAKE_USB_DEBUG = option yes; } ]; freeformConfig = mkMerge [ - { MMC_BLOCK_MINORS = freeform "32"; } # same as default, won't trigger any error - { MMC_BLOCK_MINORS = freeform "64"; } # will trigger an error but the message is not great: + { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "32"; } # same as default, won't trigger any error + { NIXOS_FAKE_MMC_BLOCK_MINORS = freeform "64"; } # will trigger an error but the message is not great: ]; yesWinsOverNoConfig = mkMerge [ - # default for "8139TOO_PIO" is no - { "8139TOO_PIO" = yes; } # yes wins over no by default - { "8139TOO_PIO" = no; } + # default for "NIXOS_TEST_BOOLEAN" is no + { "NIXOS_TEST_BOOLEAN" = yes; } # yes wins over no by default + { "NIXOS_TEST_BOOLEAN" = no; } + ]; + + optionalNoWins = mkMerge [ + { NIXOS_FAKE_USB_DEBUG = option yes;} + { NIXOS_FAKE_USB_DEBUG = yes;} + ]; + + allOptionalRemainOptional = mkMerge [ + { NIXOS_FAKE_USB_DEBUG = option yes;} + { NIXOS_FAKE_USB_DEBUG = option yes;} ]; + in -{ +runTests { + testEasy = { + expr = (getConfig { NIXOS_FAKE_USB_DEBUG = yes;}).NIXOS_FAKE_USB_DEBUG; + expected = { tristate = "y"; optional = false; freeform = null; }; + }; + # mandatory flag should win over optional - mandatoryCheck = (kernelTestConfig mandatoryVsOptionalConfig); + testMandatoryCheck = { + expr = (getConfig mandatoryVsOptionalConfig).NIXOS_FAKE_USB_DEBUG.optional; + expected = false; + }; + + testYesWinsOverNo = { + expr = (getConfig yesWinsOverNoConfig)."NIXOS_TEST_BOOLEAN".tristate; + expected = "y"; + }; + + testAllOptionalRemainOptional = { + expr = (getConfig allOptionalRemainOptional)."NIXOS_FAKE_USB_DEBUG".optional; + expected = true; + }; # check that freeform options are unique # Should trigger - # > The option `settings.MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `' and `' - freeformCheck = let - res = builtins.tryEval ( (kernelTestConfig freeformConfig).MMC_BLOCK_MINORS.freeform); - in - assertTrue (res.success == false); - - yesVsNoCheck = let - res = kernelTestConfig yesWinsOverNoConfig; - in - assertTrue (res."8139TOO_PIO".tristate == "y"); + # > The option `settings.NIXOS_FAKE_MMC_BLOCK_MINORS.freeform' has conflicting definitions, in `' and `' + testTreeform = let + res = builtins.tryEval ( (getConfig freeformConfig).NIXOS_FAKE_MMC_BLOCK_MINORS.freeform); + in { + expr = res.success; + expected = false; + }; + } -- cgit 1.4.1 From 27edd9efb3cea58629091778fcbf1c3ca994f075 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 16 May 2020 00:20:32 +0000 Subject: cross/tests: Use `crossPkgs.runCommand` so we have `strictDeps` --- pkgs/test/cross/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkgs/test') diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix index 6c31a16f2fd5..e65805c6a401 100644 --- a/pkgs/test/cross/default.nix +++ b/pkgs/test/cross/default.nix @@ -13,7 +13,7 @@ let compareTest = { emulator, pkgFun, hostPkgs, crossPkgs, exec, args ? [] }: let pkgName = (pkgFun hostPkgs).name; args' = lib.concatStringsSep " " args; - in pkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" { + in crossPkgs.runCommand "test-${pkgName}-${crossPkgs.hostPlatform.config}" { nativeBuildInputs = [ pkgs.dos2unix ]; } '' # Just in case we are using wine, get rid of that annoying extra -- cgit 1.4.1 From c71ab32a678a98ce1ec069956bc55d6ea606f55c Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 27 Apr 2020 22:39:58 -0400 Subject: pkg-config-wrapper: Init This fixes longstanding build issues --- pkgs/build-support/pkg-config-wrapper/add-flags.sh | 12 +++ pkgs/build-support/pkg-config-wrapper/default.nix | 117 +++++++++++++++++++++ .../pkg-config-wrapper/pkg-config-wrapper.sh | 21 ++++ .../build-support/pkg-config-wrapper/setup-hook.sh | 29 +++++ .../python-modules/pkgconfig/default.nix | 2 +- pkgs/development/tools/misc/pkg-config/default.nix | 2 - .../tools/misc/pkg-config/setup-hook.sh | 6 -- pkgs/test/cross/default.nix | 14 +++ pkgs/top-level/all-packages.nix | 17 ++- 9 files changed, 208 insertions(+), 12 deletions(-) create mode 100644 pkgs/build-support/pkg-config-wrapper/add-flags.sh create mode 100644 pkgs/build-support/pkg-config-wrapper/default.nix create mode 100644 pkgs/build-support/pkg-config-wrapper/pkg-config-wrapper.sh create mode 100644 pkgs/build-support/pkg-config-wrapper/setup-hook.sh delete mode 100644 pkgs/development/tools/misc/pkg-config/setup-hook.sh (limited to 'pkgs/test') diff --git a/pkgs/build-support/pkg-config-wrapper/add-flags.sh b/pkgs/build-support/pkg-config-wrapper/add-flags.sh new file mode 100644 index 000000000000..35ecf62ca230 --- /dev/null +++ b/pkgs/build-support/pkg-config-wrapper/add-flags.sh @@ -0,0 +1,12 @@ +# See cc-wrapper for comments. +var_templates_list=( + PKG_CONFIG_PATH +) + +accumulateRoles + +for var in "${var_templates_list[@]}"; do + mangleVarList "$var" ${role_suffixes[@]+"${role_suffixes[@]}"} +done + +export NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_@suffixSalt@=1 diff --git a/pkgs/build-support/pkg-config-wrapper/default.nix b/pkgs/build-support/pkg-config-wrapper/default.nix new file mode 100644 index 000000000000..87efc3b18aa8 --- /dev/null +++ b/pkgs/build-support/pkg-config-wrapper/default.nix @@ -0,0 +1,117 @@ +# The wrapper script ensures variables like PKG_CONFIG_PATH and +# PKG_CONFIG_PATH_FOR_BUILD work properly. + +{ stdenvNoCC +, buildPackages +, pkg-config +, propagateDoc ? pkg-config != null && pkg-config ? man +, extraPackages ? [], extraBuildCommands ? "" +}: + +with stdenvNoCC.lib; + +let + stdenv = stdenvNoCC; + inherit (stdenv) hostPlatform targetPlatform; + + # Prefix for binaries. Customarily ends with a dash separator. + # + # TODO(@Ericson2314) Make unconditional, or optional but always true by + # default. + targetPrefix = stdenv.lib.optionalString (targetPlatform != hostPlatform) + (targetPlatform.config + "-"); + + # See description in cc-wrapper. + suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config; + +in + +stdenv.mkDerivation { + pname = targetPrefix + pkg-config.pname + "-wrapper"; + inherit (pkg-config) version; + + preferLocalBuild = true; + + shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or ""; + + inherit targetPrefix suffixSalt; + + outputs = [ "out" ] ++ optionals propagateDoc [ "man" ]; + + passthru = { + inherit pkg-config; + }; + + dontBuild = true; + dontConfigure = true; + + unpackPhase = '' + src=$PWD + ''; + + installPhase = + '' + mkdir -p $out/bin $out/nix-support + + wrap() { + local dst="$1" + local wrapper="$2" + export prog="$3" + substituteAll "$wrapper" "$out/bin/$dst" + chmod +x "$out/bin/$dst" + } + + echo $pkg-config > $out/nix-support/orig-pkg-config + + wrap ${targetPrefix}pkg-config ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/pkg-config" + ''; + + strictDeps = true; + + wrapperName = "PKG_CONFIG_WRAPPER"; + + setupHooks = [ + ../setup-hooks/role.bash + ./setup-hook.sh + ]; + + postFixup = + '' + + ## + ## User env support + ## + + # Propagate the underling unwrapped pkg-config so that if you + # install the wrapper, you get anything else it might provide. + printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages + '' + + + optionalString propagateDoc '' + ## + ## Man page and info support + ## + + ln -s ${pkg-config.man} $man + '' + + + '' + substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh + substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash + + ## + ## Extra custom steps + ## + '' + + + extraBuildCommands; + + meta = + let pkg-config_ = if pkg-config != null then pkg-config else {}; in + (if pkg-config_ ? meta then removeAttrs pkg-config.meta ["priority"] else {}) // + { description = + stdenv.lib.attrByPath ["meta" "description"] "pkg-config" pkg-config_ + + " (wrapper script)"; + priority = 10; + }; +} diff --git a/pkgs/build-support/pkg-config-wrapper/pkg-config-wrapper.sh b/pkgs/build-support/pkg-config-wrapper/pkg-config-wrapper.sh new file mode 100644 index 000000000000..f7c7429eb0b3 --- /dev/null +++ b/pkgs/build-support/pkg-config-wrapper/pkg-config-wrapper.sh @@ -0,0 +1,21 @@ +#! @shell@ +set -eu -o pipefail +o posix +shopt -s nullglob + +if (( "${NIX_DEBUG:-0}" >= 7 )); then + set -x +fi + +source @out@/nix-support/utils.bash + +if [ -z "${NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then + source @out@/nix-support/add-flags.sh +fi + +if (( ${#role_suffixes[@]} > 0 )); then + # replace env var with nix-modified one + PKG_CONFIG_PATH=$PKG_CONFIG_PATH_@suffixSalt@ exec @prog@ "$@" +else + # pkg-config isn't a bonafied dependency so ignore setup hook entirely + exec @prog@ "$@" +fi diff --git a/pkgs/build-support/pkg-config-wrapper/setup-hook.sh b/pkgs/build-support/pkg-config-wrapper/setup-hook.sh new file mode 100644 index 000000000000..12b9af5e5837 --- /dev/null +++ b/pkgs/build-support/pkg-config-wrapper/setup-hook.sh @@ -0,0 +1,29 @@ +# pkg-config Wrapper hygiene +# +# See comments in cc-wrapper's setup hook. This works exactly the same way. + +# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a +# native compile. +# +# TODO(@Ericson2314): No native exception +[[ -z ${strictDeps-} ]] || (( "$hostOffset" < 0 )) || return 0 + +pkgConfigWrapper_addPkgConfigPath () { + # See ../setup-hooks/role.bash + local role_post + getHostRoleEnvHook + + addToSearchPath "PKG_CONFIG_PATH${role_post}" "$1/lib/pkgconfig" + addToSearchPath "PKG_CONFIG_PATH${role_post}" "$1/share/pkgconfig" +} + +# See ../setup-hooks/role.bash +getTargetRole +getTargetRoleWrapper + +addEnvHooks "$targetOffset" pkgConfigWrapper_addPkgConfigPath + +export PKG_CONFIG${role_post}=@targetPrefix@pkg-config + +# No local scope in sourced file +unset -v role_post diff --git a/pkgs/development/python-modules/pkgconfig/default.nix b/pkgs/development/python-modules/pkgconfig/default.nix index 2e6fb7c47058..c338f6d47e57 100644 --- a/pkgs/development/python-modules/pkgconfig/default.nix +++ b/pkgs/development/python-modules/pkgconfig/default.nix @@ -4,7 +4,7 @@ buildPythonPackage rec { pname = "pkgconfig"; version = "1.5.1"; - setupHook = pkgconfig.setupHook; + setupHooks = pkgconfig.setupHooks; src = fetchPypi { inherit pname version; diff --git a/pkgs/development/tools/misc/pkg-config/default.nix b/pkgs/development/tools/misc/pkg-config/default.nix index 494b8d893d42..d5e766283ce6 100644 --- a/pkgs/development/tools/misc/pkg-config/default.nix +++ b/pkgs/development/tools/misc/pkg-config/default.nix @@ -6,8 +6,6 @@ stdenv.mkDerivation rec { pname = "pkg-config"; version = "0.29.2"; - setupHook = ./setup-hook.sh; - src = fetchurl { url = "https://pkgconfig.freedesktop.org/releases/${pname}-${version}.tar.gz"; sha256 = "14fmwzki1rlz8bs2p810lk6jqdxsk966d8drgsjmi54cd00rrikg"; diff --git a/pkgs/development/tools/misc/pkg-config/setup-hook.sh b/pkgs/development/tools/misc/pkg-config/setup-hook.sh deleted file mode 100644 index 34a9b9f1173b..000000000000 --- a/pkgs/development/tools/misc/pkg-config/setup-hook.sh +++ /dev/null @@ -1,6 +0,0 @@ -addPkgConfigPath () { - addToSearchPath PKG_CONFIG_PATH $1/lib/pkgconfig - addToSearchPath PKG_CONFIG_PATH $1/share/pkgconfig -} - -addEnvHooks "$targetOffset" addPkgConfigPath diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix index e65805c6a401..c5a241437732 100644 --- a/pkgs/test/cross/default.nix +++ b/pkgs/test/cross/default.nix @@ -91,6 +91,20 @@ let pkgFun = pkgs: pkgs.hello; }; + pkg-config = {platformFun, crossPkgs, emulator}: crossPkgs.runCommand + "test-pkg-config-${crossPkgs.hostPlatform.config}" + { + depsBuildBuild = [ crossPkgs.pkgsBuildBuild.pkg-config ]; + nativeBuildInputs = [ crossPkgs.pkgsBuildHost.pkg-config crossPkgs.buildPackages.zlib ]; + depsBuildTarget = [ crossPkgs.pkgsBuildTarget.pkg-config ]; + buildInputs = [ crossPkgs.zlib ]; + NIX_DEBUG = 7; + } '' + mkdir $out + ${crossPkgs.pkgsBuildBuild.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-build" + ${crossPkgs.pkgsBuildHost.pkg-config.targetPrefix}pkg-config --cflags zlib > "$out/for-host" + ! diff "$out/for-build" "$out/for-host" + ''; }; in { diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 23bd5ffd7718..680177a2610a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -329,7 +329,11 @@ in # break dependency cycles fetchurl = stdenv.fetchurlBoot; zlib = buildPackages.zlib.override { fetchurl = stdenv.fetchurlBoot; }; - pkgconfig = buildPackages.pkgconfig.override { fetchurl = stdenv.fetchurlBoot; }; + pkgconfig = buildPackages.pkgconfig.override (old: { + pkg-config = old.pkg-config.override { + fetchurl = stdenv.fetchurlBoot; + }; + }); perl = buildPackages.perl.override { fetchurl = stdenv.fetchurlBoot; }; openssl = buildPackages.openssl.override { fetchurl = stdenv.fetchurlBoot; @@ -10737,10 +10741,17 @@ in pkgconf = callPackage ../development/tools/misc/pkgconf {}; - pkg-config = callPackage ../development/tools/misc/pkg-config { }; + pkg-config-unwrapped = callPackage ../development/tools/misc/pkg-config { }; + pkg-config = callPackage ../build-support/pkg-config-wrapper { + pkg-config = pkg-config-unwrapped; + }; pkgconfig = pkg-config; # added 2018-02-02 - pkg-configUpstream = lowPrio (pkg-config.override { vanilla = true; }); + pkg-configUpstream = lowPrio (pkg-config.override (old: { + pkg-config = old.pkg-config.override { + vanilla = true; + }; + })); pkgconfigUpstream = pkg-configUpstream; # added 2018-02-02 inherit (nodePackages) postcss-cli; -- cgit 1.4.1