Skip to content

Commit

Permalink
Recursively collect which attributes derivations depend on
Browse files Browse the repository at this point in the history
Exposes $out/nix-support/attribute-deps, containing all inputs of the
derivation recursively as attribute paths
  • Loading branch information
infinisil committed Mar 19, 2021
1 parent 857efbc commit d33a27b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d33a27b

Please sign in to comment.