From 6bacc2fc97d7399b1fe61053960de43086ef9741 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 28 Oct 2024 13:56:33 +0800 Subject: [PATCH] buildEnv: support ignoreFileOutputs Add option to ignore single-file output instead of failing. --- pkgs/build-support/buildenv/builder.pl | 23 ++++++++++++++--------- pkgs/build-support/buildenv/default.nix | 5 ++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pkgs/build-support/buildenv/builder.pl b/pkgs/build-support/buildenv/builder.pl index 12d922770a8f08..46576477220421 100755 --- a/pkgs/build-support/buildenv/builder.pl +++ b/pkgs/build-support/buildenv/builder.pl @@ -77,7 +77,7 @@ sub isStorePath { sub findFiles; sub findFilesInDir { - my ($relName, $target, $ignoreCollisions, $checkCollisionContents, $priority) = @_; + my ($relName, $target, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority) = @_; opendir DIR, "$target" or die "cannot open `$target': $!"; my @names = readdir DIR or die; @@ -85,7 +85,7 @@ sub findFilesInDir { foreach my $name (@names) { next if $name eq "." || $name eq ".."; - findFiles("$relName/$name", "$target/$name", $name, $ignoreCollisions, $checkCollisionContents, $priority); + findFiles("$relName/$name", "$target/$name", $name, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority); } } @@ -115,11 +115,16 @@ sub prependDangling { } sub findFiles { - my ($relName, $target, $baseName, $ignoreCollisions, $checkCollisionContents, $priority) = @_; + my ($relName, $target, $baseName, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority) = @_; - # The store path must not be a file + # The store path must not be a file when not ignoreFileOutputs if (-f $target && isStorePath $target) { - die "The store path $target is a file and can't be merged into an environment using pkgs.buildEnv!"; + if ($ignoreFileOutputs) { + warn "The store path $target is a file and can't be merged into an environment using pkgs.buildEnv"; + return; + } else { + die "The store path $target is a file and can't be merged into an environment using pkgs.buildEnv!"; + } } # Urgh, hacky... @@ -188,8 +193,8 @@ sub findFiles { } } - findFilesInDir($relName, $oldTarget, $ignoreCollisions, $checkCollisionContents, $oldPriority) unless $oldTarget eq ""; - findFilesInDir($relName, $target, $ignoreCollisions, $checkCollisionContents, $priority); + findFilesInDir($relName, $oldTarget, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $oldPriority) unless $oldTarget eq ""; + findFilesInDir($relName, $target, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority); $symlinks{$relName} = ["", $priority]; # denotes directory } @@ -199,12 +204,12 @@ sub findFiles { my %postponed; sub addPkg { - my ($pkgDir, $ignoreCollisions, $checkCollisionContents, $priority) = @_; + my ($pkgDir, $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority) = @_; return if (defined $done{$pkgDir}); $done{$pkgDir} = 1; - findFiles("", $pkgDir, "", $ignoreCollisions, $checkCollisionContents, $priority); + findFiles("", $pkgDir, "", $ignoreCollisions, $ignoreFileOutputs, $checkCollisionContents, $priority); my $propagatedFN = "$pkgDir/nix-support/propagated-user-env-packages"; if (-e $propagatedFN) { diff --git a/pkgs/build-support/buildenv/default.nix b/pkgs/build-support/buildenv/default.nix index ecd633fdbe43ca..910a3017587026 100644 --- a/pkgs/build-support/buildenv/default.nix +++ b/pkgs/build-support/buildenv/default.nix @@ -23,6 +23,9 @@ lib.makeOverridable , # Whether to ignore collisions or abort. ignoreCollisions ? false + # Whether to outputs that is a single file instead of a directory. +, ignoreFileOutputs ? false + , # Whether to include closures of all input paths. includeClosures ? false @@ -78,7 +81,7 @@ let ]; in runCommand name (rec { - inherit manifest ignoreCollisions checkCollisionContents passthru + inherit manifest ignoreCollisions checkCollisionContents ignoreFileOutputs passthru meta pathsToLink extraPrefix postBuild nativeBuildInputs buildInputs; pkgs = builtins.toJSON chosenOutputs;