From d33a27b272a68752e67b54b2f09912d4786ae480 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Fri, 19 Mar 2021 15:54:25 +0100 Subject: [PATCH] Recursively collect which attributes derivations depend on Exposes $out/nix-support/attribute-deps, containing all inputs of the derivation recursively as attribute paths --- pkgs/stdenv/generic/make-derivation.nix | 17 +++++++++++++++++ pkgs/stdenv/generic/setup.sh | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 13a7a03d6a8b89f..57b5dd74467c8bc 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -115,6 +115,22 @@ in rec { else lib.subtractLists hardeningDisable (defaultHardeningFlags ++ hardeningEnable); # hardeningDisable additionally supports "all". erroneousHardeningFlags = lib.subtractLists supportedHardeningFlags (hardeningEnable ++ lib.remove "all" hardeningDisable); + + allDeps = depsBuildBuild + ++ depsBuildBuildPropagated + ++ nativeBuildInputs + ++ propagatedNativeBuildInputs + ++ depsBuildTarget + ++ depsBuildTargetPropagated + ++ depsHostHost + ++ depsHostHostPropagated + ++ buildInputs + ++ propagatedBuildInputs + ++ depsTargetTarget + ++ depsTargetTargetPropagated; + + attributeDeps = map (d: lib.concatStringsSep "." d.__path) (lib.filter (d: d ? __path) allDeps); + in if builtins.length erroneousHardeningFlags != 0 then abort ("mkDerivation was called with unsupported hardening flags: " + lib.generators.toPretty {} { inherit erroneousHardeningFlags hardeningDisable hardeningEnable supportedHardeningFlags; @@ -200,6 +216,7 @@ in rec { builder = attrs.realBuilder or stdenv.shell; args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; inherit stdenv; + inherit attributeDeps; # The `system` attribute of a derivation has special meaning to Nix. # Derivations set it to choose what sort of machine could be used to diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 7168ce4084c87b3..bfc78c7344e0811 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -334,6 +334,7 @@ declare -a propagatedDepFilesVars=( # Platform offsets: build = -1, host = 0, target = 1 declare -a allPlatOffsets=(-1 0 1) +declare -a attributeDepsArr=($attributeDeps) # Mutually-recursively find all build inputs. See the dependency section of the # stdenv chapter of the Nixpkgs manual for the specification this algorithm @@ -427,6 +428,12 @@ findInputs() { done done done + + if [[ -f "$pkg"/nix-support/attribute-deps ]]; then + for p in $(cat "$pkg/nix-support/attribute-deps"); do + attributeDepsArr+=("$p") + done + fi } # Make sure all are at least defined as empty @@ -1160,6 +1167,13 @@ fixupPhase() { substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook" fi + for a in "${attributeDepsArr[@]}"; do + for output in $outputs; do + mkdir -p "${!output}/nix-support" + echo "$a" >> "${!output}/nix-support/attribute-deps" + done + done + # TODO(@Ericson2314): Remove after https://github.com/NixOS/nixpkgs/pull/31414 if [ -n "${setupHooks:-}" ]; then mkdir -p "${!outputDev}/nix-support"