Skip to content

Commit

Permalink
buildEnv: add includeClosures option (#341371)
Browse files Browse the repository at this point in the history
  • Loading branch information
K900 authored Sep 13, 2024
2 parents dbaedb9 + db09145 commit 6afe0e7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkgs/build-support/build-fhsenv-bubblewrap/buildFHSEnv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ let
chmod u+w -R lib64/
# symlink 32-bit ld-linux.so
ln -Ls ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/
ln -Lsf ${staticUsrProfileTarget}/lib/32/ld-linux.so.2 lib/
'';

setupLibDirs = if isTargetBuild
Expand Down
15 changes: 15 additions & 0 deletions pkgs/build-support/buildenv/builder.pl
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ sub addPkg {
}
}

my $extraPathsFilePath = $ENV{"extraPathsFrom"};
if ($extraPathsFilePath) {
open FILE, $extraPathsFilePath or die "cannot open extra paths file $extraPathsFilePath: $!";

while(my $line = <FILE>) {
chomp $line;
addPkg($line,
$ENV{"ignoreCollisions"} eq "1",
$ENV{"checkCollisionContents"} eq "1",
1000)
if -d $line;
}

close FILE;
}

# Create the symlinks.
my $nrLinks = 0;
Expand Down
41 changes: 24 additions & 17 deletions pkgs/build-support/buildenv/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# buildEnv creates a tree of symlinks to the specified paths. This is
# a fork of the hardcoded buildEnv in the Nix distribution.

{ buildPackages, runCommand, lib, substituteAll }:
{ buildPackages, runCommand, lib, substituteAll, writeClosure }:

let
builder = substituteAll {
Expand All @@ -23,6 +23,9 @@ lib.makeOverridable
, # Whether to ignore collisions or abort.
ignoreCollisions ? false

, # Whether to include closures of all input paths.
includeClosures ? false

, # If there is a collision, check whether the contents and permissions match
# and only if not, throw a collision error.
checkCollisionContents ? true
Expand All @@ -49,27 +52,31 @@ lib.makeOverridable
, passthru ? {}
, meta ? {}
}:
let
chosenOutputs = map (drv: {
paths =
# First add the usual output(s): respect if user has chosen explicitly,
# and otherwise use `meta.outputsToInstall`. The attribute is guaranteed
# to exist in mkDerivation-created cases. The other cases (e.g. runCommand)
# aren't expected to have multiple outputs.
(if (! drv ? outputSpecified || ! drv.outputSpecified)
&& drv.meta.outputsToInstall or null != null
then map (outName: drv.${outName}) drv.meta.outputsToInstall
else [ drv ])
# Add any extra outputs specified by the caller of `buildEnv`.
++ lib.filter (p: p!=null)
(builtins.map (outName: drv.${outName} or null) extraOutputsToInstall);
priority = drv.meta.priority or lib.meta.defaultPriority;
}) paths;

runCommand name
pathsForClosure = lib.flatten (map (p: p.paths) chosenOutputs);
in runCommand name
rec {
inherit manifest ignoreCollisions checkCollisionContents passthru
meta pathsToLink extraPrefix postBuild
nativeBuildInputs buildInputs;
pkgs = builtins.toJSON (map (drv: {
paths =
# First add the usual output(s): respect if user has chosen explicitly,
# and otherwise use `meta.outputsToInstall`. The attribute is guaranteed
# to exist in mkDerivation-created cases. The other cases (e.g. runCommand)
# aren't expected to have multiple outputs.
(if (! drv ? outputSpecified || ! drv.outputSpecified)
&& drv.meta.outputsToInstall or null != null
then map (outName: drv.${outName}) drv.meta.outputsToInstall
else [ drv ])
# Add any extra outputs specified by the caller of `buildEnv`.
++ lib.filter (p: p!=null)
(builtins.map (outName: drv.${outName} or null) extraOutputsToInstall);
priority = drv.meta.priority or lib.meta.defaultPriority;
}) paths);
pkgs = builtins.toJSON chosenOutputs;
extraPathsFrom = lib.optional includeClosures (writeClosure pathsForClosure);
preferLocalBuild = true;
allowSubstitutes = false;
# XXX: The size is somewhat arbitrary
Expand Down

0 comments on commit 6afe0e7

Please sign in to comment.