diff options
-rw-r--r-- | scripts/nix-build.in | 4 | ||||
-rw-r--r-- | src/libstore/gc.cc | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in index 08201f85761d..bce4a80078f9 100644 --- a/scripts/nix-build.in +++ b/scripts/nix-build.in @@ -122,7 +122,7 @@ foreach my $expr (@exprs) { close DRVPATHS or exit 1; foreach my $drvPath (@drvPaths) { - my $target = readlink $drvPath; + my $target = readlink $drvPath or die "cannot read symlink `$drvPath'"; print STDERR "store derivation is $target\n"; } @@ -134,7 +134,7 @@ foreach my $expr (@exprs) { close OUTPATHS or exit 1; foreach my $outPath (@outPaths) { - my $target = readlink $outPath; + my $target = readlink $outPath or die "cannot read symlink `$outPath'"; print "$target\n"; } } diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index e04e9c1071cb..2ad52d8bf4ea 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -97,6 +97,11 @@ Path addPermRoot(const Path & _storePath, const Path & _gcRoot, Path gcRoot(canonPath(_gcRoot)); assertStorePath(storePath); + if (isInStore(gcRoot)) + throw Error(format( + "creating a garbage collector root (%1%) in the Nix store is forbidden " + "(are you running nix-build inside the store?)") % gcRoot); + if (indirect) { createSymlink(gcRoot, storePath, true); store->addIndirectRoot(gcRoot); @@ -114,7 +119,6 @@ Path addPermRoot(const Path & _storePath, const Path & _gcRoot, } createSymlink(gcRoot, storePath, false); - } /* Check that the root can be found by the garbage collector. */ |