mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 00:06:16 +02:00
73acb8b836
Since SubstitutionGoal::finished() in build.cc computes the hash anyway, we can prevent the inefficiency of computing the hash twice by letting the substituter tell Nix about the expected hash, which can then verify it.
97 lines
2.7 KiB
Perl
Executable file
97 lines
2.7 KiB
Perl
Executable file
#! @perl@ -w @perlFlags@
|
|
|
|
use strict;
|
|
use File::Basename;
|
|
use IO::Handle;
|
|
|
|
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
|
|
|
|
STDOUT->autoflush(1);
|
|
|
|
my @remoteStoresAll = split ':', ($ENV{"NIX_OTHER_STORES"} or "");
|
|
|
|
my @remoteStores;
|
|
foreach my $dir (@remoteStoresAll) {
|
|
push @remoteStores, glob($dir);
|
|
}
|
|
|
|
|
|
$ENV{"NIX_REMOTE"} = "";
|
|
|
|
|
|
sub findStorePath {
|
|
my $storePath = shift;
|
|
foreach my $store (@remoteStores) {
|
|
my $sourcePath = "$store/store/" . basename $storePath;
|
|
next unless -e $sourcePath || -l $sourcePath;
|
|
$ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
|
|
return ($store, $sourcePath) if
|
|
system("@bindir@/nix-store --check-validity $storePath") == 0;
|
|
}
|
|
return undef;
|
|
}
|
|
|
|
|
|
if ($ARGV[0] eq "--query") {
|
|
|
|
while (<STDIN>) {
|
|
chomp;
|
|
my ($cmd, @args) = split " ", $_;
|
|
|
|
if ($cmd eq "have") {
|
|
foreach my $storePath (@args) {
|
|
print "$storePath\n" if defined findStorePath($storePath);
|
|
}
|
|
print "\n";
|
|
}
|
|
|
|
elsif ($cmd eq "info") {
|
|
foreach my $storePath (@args) {
|
|
my ($store, $sourcePath) = findStorePath($storePath);
|
|
next unless defined $store;
|
|
|
|
$ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
|
|
|
|
my $deriver = `@bindir@/nix-store --query --deriver $storePath`;
|
|
die "cannot query deriver of `$storePath'" if $? != 0;
|
|
chomp $deriver;
|
|
$deriver = "" if $deriver eq "unknown-deriver";
|
|
|
|
my @references = split "\n",
|
|
`@bindir@/nix-store --query --references $storePath`;
|
|
die "cannot query references of `$storePath'" if $? != 0;
|
|
|
|
my $narSize = `@bindir@/nix-store --query --size $storePath`;
|
|
die "cannot query size of `$storePath'" if $? != 0;
|
|
chomp $narSize;
|
|
|
|
print "$storePath\n";
|
|
print "$deriver\n";
|
|
print scalar @references, "\n";
|
|
print "$_\n" foreach @references;
|
|
print "$narSize\n";
|
|
print "$narSize\n";
|
|
}
|
|
|
|
print "\n";
|
|
}
|
|
|
|
else { die "unknown command `$cmd'"; }
|
|
}
|
|
}
|
|
|
|
|
|
elsif ($ARGV[0] eq "--substitute") {
|
|
die unless scalar @ARGV == 2;
|
|
my $storePath = $ARGV[1];
|
|
my ($store, $sourcePath) = findStorePath $storePath;
|
|
die unless $store;
|
|
print STDERR "\n*** Copying `$storePath' from `$sourcePath'\n\n";
|
|
system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $storePath") == 0
|
|
or die "cannot copy `$sourcePath' to `$storePath'";
|
|
print "\n"; # no hash to verify
|
|
}
|
|
|
|
|
|
else { die; }
|