2012-01-05 20:33:46 +00:00
|
|
|
|
#! @perl@ -w @perlFlags@
|
2008-07-12 18:58:24 +00:00
|
|
|
|
|
2014-08-20 15:00:17 +00:00
|
|
|
|
use utf8;
|
2008-07-12 18:58:24 +00:00
|
|
|
|
use strict;
|
|
|
|
|
use File::Basename;
|
2008-08-02 12:54:35 +00:00
|
|
|
|
use IO::Handle;
|
|
|
|
|
|
2008-11-20 15:44:59 +00:00
|
|
|
|
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
|
|
|
|
|
|
|
|
|
2008-08-02 12:54:35 +00:00
|
|
|
|
STDOUT->autoflush(1);
|
2015-01-15 16:56:56 +00:00
|
|
|
|
binmode STDERR, ":encoding(utf8)";
|
2008-07-12 18:58:24 +00:00
|
|
|
|
|
2008-07-18 13:05:10 +00:00
|
|
|
|
my @remoteStoresAll = split ':', ($ENV{"NIX_OTHER_STORES"} or "");
|
2008-07-12 18:58:24 +00:00
|
|
|
|
|
2008-07-18 13:05:10 +00:00
|
|
|
|
my @remoteStores;
|
|
|
|
|
foreach my $dir (@remoteStoresAll) {
|
|
|
|
|
push @remoteStores, glob($dir);
|
|
|
|
|
}
|
2008-07-12 18:58:24 +00:00
|
|
|
|
|
2013-06-20 09:55:15 +00:00
|
|
|
|
exit if scalar @remoteStores == 0;
|
|
|
|
|
print "\n";
|
|
|
|
|
|
2008-07-12 18:58:24 +00:00
|
|
|
|
|
2010-04-26 13:39:55 +00:00
|
|
|
|
$ENV{"NIX_REMOTE"} = "";
|
|
|
|
|
|
|
|
|
|
|
2008-07-12 18:58:24 +00:00
|
|
|
|
sub findStorePath {
|
|
|
|
|
my $storePath = shift;
|
|
|
|
|
foreach my $store (@remoteStores) {
|
2010-04-26 13:39:55 +00:00
|
|
|
|
my $sourcePath = "$store/store/" . basename $storePath;
|
|
|
|
|
next unless -e $sourcePath || -l $sourcePath;
|
|
|
|
|
$ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
|
|
|
|
|
return ($store, $sourcePath) if
|
2013-07-01 11:30:28 +00:00
|
|
|
|
system("$binDir/nix-store --check-validity $storePath") == 0;
|
2008-07-12 18:58:24 +00:00
|
|
|
|
}
|
2010-04-26 13:39:55 +00:00
|
|
|
|
return undef;
|
2008-07-12 18:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-08-02 12:54:35 +00:00
|
|
|
|
if ($ARGV[0] eq "--query") {
|
2008-07-12 18:58:24 +00:00
|
|
|
|
|
2008-08-02 12:54:35 +00:00
|
|
|
|
while (<STDIN>) {
|
2012-07-11 22:52:09 +00:00
|
|
|
|
chomp;
|
|
|
|
|
my ($cmd, @args) = split " ", $_;
|
2008-07-12 18:58:24 +00:00
|
|
|
|
|
2008-08-02 12:54:35 +00:00
|
|
|
|
if ($cmd eq "have") {
|
2012-07-11 22:52:09 +00:00
|
|
|
|
foreach my $storePath (@args) {
|
|
|
|
|
print "$storePath\n" if defined findStorePath($storePath);
|
|
|
|
|
}
|
|
|
|
|
print "\n";
|
2008-08-02 12:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elsif ($cmd eq "info") {
|
2012-07-11 22:52:09 +00:00
|
|
|
|
foreach my $storePath (@args) {
|
|
|
|
|
my ($store, $sourcePath) = findStorePath($storePath);
|
|
|
|
|
next unless defined $store;
|
2008-08-02 12:54:35 +00:00
|
|
|
|
|
2012-07-11 22:52:09 +00:00
|
|
|
|
$ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
|
2012-07-27 16:16:02 +00:00
|
|
|
|
|
2013-07-01 11:30:28 +00:00
|
|
|
|
my $deriver = `$binDir/nix-store --query --deriver $storePath`;
|
2014-08-20 15:00:17 +00:00
|
|
|
|
die "cannot query deriver of ‘$storePath’" if $? != 0;
|
2012-07-11 22:52:09 +00:00
|
|
|
|
chomp $deriver;
|
|
|
|
|
$deriver = "" if $deriver eq "unknown-deriver";
|
|
|
|
|
|
|
|
|
|
my @references = split "\n",
|
2013-07-01 11:30:28 +00:00
|
|
|
|
`$binDir/nix-store --query --references $storePath`;
|
2014-08-20 15:00:17 +00:00
|
|
|
|
die "cannot query references of ‘$storePath’" if $? != 0;
|
2012-07-11 22:52:09 +00:00
|
|
|
|
|
2013-07-01 11:30:28 +00:00
|
|
|
|
my $narSize = `$binDir/nix-store --query --size $storePath`;
|
2014-08-20 15:00:17 +00:00
|
|
|
|
die "cannot query size of ‘$storePath’" if $? != 0;
|
2012-07-11 22:52:09 +00:00
|
|
|
|
chomp $narSize;
|
|
|
|
|
|
|
|
|
|
print "$storePath\n";
|
|
|
|
|
print "$deriver\n";
|
|
|
|
|
print scalar @references, "\n";
|
|
|
|
|
print "$_\n" foreach @references;
|
2013-07-01 11:29:59 +00:00
|
|
|
|
print "0\n";
|
2012-07-11 22:52:09 +00:00
|
|
|
|
print "$narSize\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print "\n";
|
2008-07-12 18:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 15:00:17 +00:00
|
|
|
|
else { die "unknown command ‘$cmd’"; }
|
2008-07-12 18:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elsif ($ARGV[0] eq "--substitute") {
|
2012-10-02 18:08:59 +00:00
|
|
|
|
die unless scalar @ARGV == 3;
|
2008-07-12 18:58:24 +00:00
|
|
|
|
my $storePath = $ARGV[1];
|
2012-10-02 18:08:59 +00:00
|
|
|
|
my $destPath = $ARGV[2];
|
2010-04-26 13:39:55 +00:00
|
|
|
|
my ($store, $sourcePath) = findStorePath $storePath;
|
|
|
|
|
die unless $store;
|
2014-08-20 15:00:17 +00:00
|
|
|
|
print STDERR "\n*** Copying ‘$storePath’ from ‘$sourcePath’\n\n";
|
2012-10-02 18:08:59 +00:00
|
|
|
|
system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $destPath") == 0
|
2014-08-20 15:00:17 +00:00
|
|
|
|
or die "cannot copy ‘$sourcePath’ to ‘$storePath’";
|
2012-07-27 16:16:02 +00:00
|
|
|
|
print "\n"; # no hash to verify
|
2008-07-12 18:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else { die; }
|