Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make-derivation.nix: lib.warn if drv.__spliced missing #263082

Closed
wants to merge 11 commits into from
3 changes: 2 additions & 1 deletion pkgs/development/compilers/gcc/all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
, cloog_0_18_0, cloog
, lowPrio
, wrapCC
, __splicedPackages
}@args:

let
Expand All @@ -27,7 +28,7 @@ let
libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then args.libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor majorMinorVersion else { };
isl = if stdenv.isDarwin then null
else if atLeast "9" then isl_0_20
else if atLeast "9" then __splicedPackages.isl_0_20
else if atLeast "7" then isl_0_17
else if atLeast "6" then (if stdenv.targetPlatform.isRedox then isl_0_17 else isl_0_14)
else if atLeast "4.9" then isl_0_11
Expand Down
6 changes: 3 additions & 3 deletions pkgs/development/compilers/gcc/common/configure-flags.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ lib, stdenv
, targetPackages
, targetPackages_bintools

, withoutTargetLibc, libcCross
, threadsCross
Expand Down Expand Up @@ -56,8 +56,8 @@ let
crossConfigureFlags =
# Ensure that -print-prog-name is able to find the correct programs.
[
"--with-as=${if targetPackages.stdenv.cc.bintools.isLLVM then binutils else targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-as"
"--with-ld=${targetPackages.stdenv.cc.bintools}/bin/${targetPlatform.config}-ld"
"--with-as=${if targetPackages_bintools.isLLVM then binutils else targetPackages_bintools}/bin/${targetPlatform.config}-as"
"--with-ld=${targetPackages_bintools}/bin/${targetPlatform.config}-ld"
]
++ (if withoutTargetLibc then [
"--disable-libssp"
Expand Down
6 changes: 3 additions & 3 deletions pkgs/development/compilers/gcc/common/dependencies.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
, stdenv
, version
, buildPackages
, targetPackages
, texinfo
, which
, gettext
Expand All @@ -12,6 +11,7 @@
, gmp
, mpfr
, libmpc
, targetPackages_bintools
, libucontext ? null
, libxcrypt ? null
, cloog ? null
Expand Down Expand Up @@ -62,7 +62,7 @@ in
depsBuildTarget =
(
if hostPlatform == buildPlatform then [
targetPackages.stdenv.cc.bintools # newly-built gcc will be used
targetPackages_bintools # newly-built gcc will be used
] else assert targetPlatform == hostPlatform; [
# build != host == target
stdenv.cc
Expand All @@ -77,7 +77,7 @@ in
]
++ optionals (lib.versionAtLeast version "10") [ libxcrypt ]
++ [
targetPackages.stdenv.cc.bintools # For linking code at run-time
targetPackages_bintools # For linking code at run-time
]
++ optionals (lib.versionOlder version "5" && cloog != null) [ cloog ]
++ optionals (isl != null) [ isl ]
Expand Down
5 changes: 3 additions & 2 deletions pkgs/development/compilers/gcc/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs
{ lib, stdenv, fetchurl, fetchpatch, noSysDirs
, langC ? true, langCC ? true, langFortran ? false
, langAda ? false
, langObjC ? stdenv.targetPlatform.isDarwin
Expand All @@ -14,6 +14,7 @@
, texinfo ? null
, perl ? null # optional, for texi2pod (then pod2man)
, gmp, mpfr, libmpc, gettext, which, patchelf, binutils
, targetPackages_bintools
, isl ? null # optional, for the Graphite optimization framework.
, zlib ? null
, libucontext ? null
Expand Down Expand Up @@ -173,7 +174,7 @@ let inherit version;
reproducibleBuild
staticCompiler
stdenv
targetPackages
targetPackages_bintools
texinfo
threadsCross
which
Expand Down
3 changes: 2 additions & 1 deletion pkgs/development/libraries/cracklib/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let version = "2.9.11"; in
{ stdenv, lib, buildPackages, fetchurl, zlib, gettext
, cracklib
, lists ? [ (fetchurl {
url = "https://github.com/cracklib/cracklib/releases/download/v${version}/cracklib-words-${version}.gz";
hash = "sha256-popxGjE1c517Z+nzYLM/DU7M+b1/rE0XwNXkVqkcUXo=";
Expand All @@ -15,7 +16,7 @@ stdenv.mkDerivation rec {
hash = "sha256-yosEmjwtOyIloejRXWE3mOvHSOOVA4jtomlN5Qe6YCA=";
};

nativeBuildInputs = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) buildPackages.cracklib;
nativeBuildInputs = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) cracklib;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to get more fit in cross: Shouldn't this use canExecute?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is what you mean, then yes, that would be an improvement (let's put it in a separate PR though -- one thing at a time).

diff --git a/pkgs/development/libraries/cracklib/default.nix b/pkgs/development/libraries/cracklib/default.nix
index ba5d96a95182..defdb2965173 100644
--- a/pkgs/development/libraries/cracklib/default.nix
+++ b/pkgs/development/libraries/cracklib/default.nix
@@ -15,10 +15,10 @@ stdenv.mkDerivation rec {
     hash = "sha256-yosEmjwtOyIloejRXWE3mOvHSOOVA4jtomlN5Qe6YCA=";
   };

-  nativeBuildInputs = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) buildPackages.cracklib;
+  nativeBuildInputs = lib.optional (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) buildPackages.cracklib;
   buildInputs = [ zlib gettext ];

-  postPatch = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
+  postPatch = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
     chmod +x util/cracklib-format
     patchShebangs util

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes against your comment below about using buildPackages in nativeBuildInputs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes against your comment below about using buildPackages in nativeBuildInputs.

Indeed! Nice catch. If this PR were merged CI would have caught that.

The patch above should, in addition to the changes it makes, also delete the buildPackages. before cracklib.

buildInputs = [ zlib gettext ];

postPatch = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
Expand Down
141 changes: 131 additions & 10 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
let

#
# This is a list of pnames of packages that have failed to splice.
# Every one of these is an unfixed bug. Please fix them instead
# of taking shameful behavior, you scoundrel!
#
list-of-shame =
builtins.listToAttrs
(builtins.map
(name: { inherit name; value = true; })
[
# shame on you, python
"pypa-build-hook.sh"
"pypa-install-hook"
"pytest-check-hook"
"python-catch-conflicts-hook"
"python-imports-check-hook.sh"
"python-namespaces-hook.sh"
"python-output-dist-hook"
"python-remove-bin-bytecode-hook"
"python-remove-tests-dir-hook"
"python-remove-tests-dir-hook"
"python3-3.11.5-env"
"setuptools-check-hook"
"setuptools-setup-hook"
"unittest-check-hook"
"wrap-python-hook"
"wrap-python-hook"
"wrap-python-hook"

# shame on you, llvm!
"llvm"
"compiler-rt"
"libcxx"
"libcxxabi"
Comment on lines +32 to +36
Copy link
Member

@Artturin Artturin Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the llvm sets use the normal makeScope and that's why there's no __spliced's in the sets own callPackage

I'm little by little working on making the sets better #253671
once I dedupe more stuff it'll be much easier to dedupe and improve the llvm/*/default.nix'es

Nice list name.

"libunwind"

# shame on you, embedded ARM!
"arm-none-eabi-stage-final-gcc-wrapper"
"arm-none-eabi-binutils-wrapper"

# wasm doesn't care about shamefulness, so I won't bother...
"rustc-wasm32"

# windows
# has overrides which discard splicing
# improvement: convert makeScope to makeScopeWithSplicing'
# may not fix it but it'll improve the set
# https://github.com/NixOS/nixpkgs/blob/53aa767c849b159cdb8c59dce4a5a44f167fc31b/pkgs/os-specific/windows/default.nix#L20
"mcfgthreads"
This conversation was marked as resolved.
Show resolved Hide resolved
"i686-w64-mingw32-stage-final-gcc-wrapper"
"x86_64-w64-mingw32-stage-final-gcc-wrapper"

# other shameful derivations
"git-minimal"
"busybox"
"avr-stage-final-gcc-wrapper"
"boost-build"
"cmake-boot"
"perl" # only for libxcrypt; we should fix this
]);
in

{ lib, config }:

stdenv:
Expand Down Expand Up @@ -283,32 +347,89 @@ else let
references = nativeBuildInputs ++ buildInputs
++ propagatedNativeBuildInputs ++ propagatedBuildInputs;

getSpliced = type: dep:
dep.__spliced or
(let approximate-pname = dep.pname or dep.name; in
assert
(dep?stdenv &&
dep.stdenv.buildPlatform != dep.stdenv.targetPlatform &&

# I can't test on Darwin, so let's just ignore it for now.
!dep.stdenv.buildPlatform.isDarwin &&
!dep.stdenv.hostPlatform.isDarwin &&
!dep.stdenv.targetPlatform.isDarwin &&

!(list-of-shame ? ${approximate-pname})
)

# Hi there! If you're reading this, it's probably
# because the line below caused your PR to fail CI.
# Don't panic! Most likely, what happened is that you
# used one of the following as a dependency:
#
# - `buildPackages.something`
# - `targetPackages.something`
# - `pkgs{Build,Host,Target}{Build,Host,Target}.something`
#
# You can't use those as dependencies (i.e. in a
# `buildInputs`, `nativeBuildInputs`, or
# `deps{Build,Host,Target}{Build,Host,Target}`
# attribute). The reason is a bit obscure, but the fix
# is easy: just use `something` instead! The explicit
# packagesets (the three bullet points above) are mainly
# for when you need to reference a package with string
# interpolation (e.g. "cat blah | ${buildPackages.jq}").
# For dependencies, you control which packageset is used
# by *which attribute you put the dependency in* -- if
# you put it in `depsBuildHost`, it will get pulled from
# `pkgsBuildHost`.
#
# Please take a moment to try to fix your PR. If you
# can't get it fixed, ping @amjoseph-nixpkgs who can
# help you fix it. If this is a crisis situation and
# the future of humanity depends on your PR passing CI
# pronto, you can mute the warning by adding your
# package's `pname` to the `list-of-shame` at the top of
# this file. But please don't do that.
#
-> lib.warn
''derivation ${attrs.pname or "!!no pname!!"}:
unspliced ${type} dependency ${approximate-pname}
build=${dep.stdenv.buildPlatform.config}
host=${dep.stdenv.hostPlatform.config}
target=${dep.stdenv.targetPlatform.config}
For advice on fixing this, read the comment above the lib.warn that produced this message.
'' true;
{});

dependencies = map (map chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs'))
(map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTarget" depsBuildTarget))
(map (drv: (getSpliced "build-build" drv).buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild))
(map (drv: (getSpliced "build-host" drv).buildHost or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs'))
(map (drv: (getSpliced "build-target" drv).buildTarget or drv) (checkDependencyList "depsBuildTarget" depsBuildTarget))
]
[
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHost" depsHostHost))
(map (drv: (getSpliced "host-host" drv).hostHost or drv) (checkDependencyList "depsHostHost" depsHostHost))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "buildInputs" buildInputs'))
#(map (drv: (getSpliced "host-target" drv).hostTarget or drv) (checkDependencyList "buildInputs" buildInputs'))
]
[
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTarget" depsTargetTarget))
(map (drv: (getSpliced "target-target" drv).targetTarget or drv) (checkDependencyList "depsTargetTarget" depsTargetTarget))
]
];
propagatedDependencies = map (map chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuildPropagated" depsBuildBuildPropagated))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "propagatedNativeBuildInputs" propagatedNativeBuildInputs))
(map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTargetPropagated" depsBuildTargetPropagated))
(map (drv: (getSpliced "build-build propagated" drv).buildBuild or drv) (checkDependencyList "depsBuildBuildPropagated" depsBuildBuildPropagated))
(map (drv: (getSpliced "build-host propagated" drv).buildHost or drv) (checkDependencyList "propagatedNativeBuildInputs" propagatedNativeBuildInputs))
(map (drv: (getSpliced "build-target propagated" drv).buildTarget or drv) (checkDependencyList "depsBuildTargetPropagated" depsBuildTargetPropagated))
]
[
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHostPropagated" depsHostHostPropagated))
(map (drv: (getSpliced "host-host propagated" drv).hostHost or drv) (checkDependencyList "depsHostHostPropagated" depsHostHostPropagated))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "propagatedBuildInputs" propagatedBuildInputs))
#(map (drv: (getSpliced "host-target propagated" drv).hostTarget or drv) (checkDependencyList "propagatedBuildInputs" propagatedBuildInputs))
]
[
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTargetPropagated" depsTargetTargetPropagated))
(map (drv: (getSpliced "target-target propagated" drv).targetTarget or drv) (checkDependencyList "depsTargetTargetPropagated" depsTargetTargetPropagated))
]
];

Expand Down
14 changes: 11 additions & 3 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15948,6 +15948,10 @@ with pkgs;
then overrideCC stdenv buildPackages.llvmPackages.clangNoLibc
else gccCrossLibcStdenv;

# This needs to have a top-level entry here in all-packages.nix in
# order to be spliced.
targetPackages_bintools = targetPackages.stdenv.cc.bintools;

# The GCC used to build libc for the target platform. Normal gccs will be
# built with, and use, that cross-compiled libc.
gccWithoutTargetLibc = assert stdenv.targetPlatform != stdenv.hostPlatform; let
Expand All @@ -15961,12 +15965,12 @@ with pkgs;
reproducibleBuild = true;
profiledCompiler = false;

isl = if !stdenv.isDarwin then isl_0_20 else null;
isl = if !stdenv.isDarwin then __splicedPackages.isl_0_20 else null;

withoutTargetLibc = true;
langCC = false;
libcCross = libcCross1;
targetPackages.stdenv.cc.bintools = binutilsNoLibc;
targetPackages_bintools = __splicedPackages.binutilsNoLibc;
enableShared =
stdenv.targetPlatform.hasSharedLibraries

Expand Down Expand Up @@ -16963,6 +16967,7 @@ with pkgs;
};
};
}).overrideAttrs (old: {
pname = "rustc-wasm32";
configureFlags = old.configureFlags ++ ["--set=build.docs=false"];
});

Expand Down Expand Up @@ -18630,7 +18635,10 @@ with pkgs;
enableGold = false;
};
});
binutilsNoLibc = wrapBintoolsWith {
binutilsNoLibc =
# this `if..then null else` is an ugly hack to prevent infinite recursion
if stdenv.hostPlatform == stdenv.targetPlatform then null else
wrapBintoolsWith {
bintools = binutils-unwrapped;
libc = preLibcCrossHeaders;
};
Expand Down
Loading