buildEnv: support pulling in closures of paths

This will become important for Steam.
This commit is contained in:
K900 2024-09-12 13:21:05 +03:00
parent 4e803e9656
commit 4654ea4cc0
2 changed files with 39 additions and 17 deletions

View File

@ -255,6 +255,21 @@ while (scalar(keys %postponed) > 0) {
} }
} }
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. # Create the symlinks.
my $nrLinks = 0; my $nrLinks = 0;

View File

@ -1,7 +1,7 @@
# buildEnv creates a tree of symlinks to the specified paths. This is # buildEnv creates a tree of symlinks to the specified paths. This is
# a fork of the hardcoded buildEnv in the Nix distribution. # a fork of the hardcoded buildEnv in the Nix distribution.
{ buildPackages, runCommand, lib, substituteAll }: { buildPackages, runCommand, lib, substituteAll, writeClosure }:
let let
builder = substituteAll { builder = substituteAll {
@ -23,6 +23,9 @@ lib.makeOverridable
, # Whether to ignore collisions or abort. , # Whether to ignore collisions or abort.
ignoreCollisions ? false ignoreCollisions ? false
, # Whether to include closures of all input paths.
includeClosures ? false
, # If there is a collision, check whether the contents and permissions match , # If there is a collision, check whether the contents and permissions match
# and only if not, throw a collision error. # and only if not, throw a collision error.
checkCollisionContents ? true checkCollisionContents ? true
@ -49,13 +52,8 @@ lib.makeOverridable
, passthru ? {} , passthru ? {}
, meta ? {} , meta ? {}
}: }:
let
runCommand name chosenOutputs = map (drv: {
rec {
inherit manifest ignoreCollisions checkCollisionContents passthru
meta pathsToLink extraPrefix postBuild
nativeBuildInputs buildInputs;
pkgs = builtins.toJSON (map (drv: {
paths = paths =
# First add the usual output(s): respect if user has chosen explicitly, # First add the usual output(s): respect if user has chosen explicitly,
# and otherwise use `meta.outputsToInstall`. The attribute is guaranteed # and otherwise use `meta.outputsToInstall`. The attribute is guaranteed
@ -69,7 +67,16 @@ runCommand name
++ lib.filter (p: p!=null) ++ lib.filter (p: p!=null)
(builtins.map (outName: drv.${outName} or null) extraOutputsToInstall); (builtins.map (outName: drv.${outName} or null) extraOutputsToInstall);
priority = drv.meta.priority or lib.meta.defaultPriority; priority = drv.meta.priority or lib.meta.defaultPriority;
}) paths); }) paths;
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 chosenOutputs;
extraPathsFrom = lib.optional includeClosures (writeClosure pathsForClosure);
preferLocalBuild = true; preferLocalBuild = true;
allowSubstitutes = false; allowSubstitutes = false;
# XXX: The size is somewhat arbitrary # XXX: The size is somewhat arbitrary