2008-07-12 20:58:24 +02:00
|
|
|
#! @perl@ -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use File::Basename;
|
2008-08-02 14:54:35 +02:00
|
|
|
use IO::Handle;
|
|
|
|
|
2008-11-20 16:44:59 +01:00
|
|
|
my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";
|
|
|
|
|
|
|
|
|
2008-08-02 14:54:35 +02:00
|
|
|
STDOUT->autoflush(1);
|
2008-07-12 20:58:24 +02:00
|
|
|
|
2008-07-18 15:05:10 +02:00
|
|
|
my @remoteStoresAll = split ':', ($ENV{"NIX_OTHER_STORES"} or "");
|
2008-07-12 20:58:24 +02:00
|
|
|
|
2008-07-18 15:05:10 +02:00
|
|
|
my @remoteStores;
|
|
|
|
foreach my $dir (@remoteStoresAll) {
|
|
|
|
push @remoteStores, glob($dir);
|
|
|
|
}
|
2008-07-12 20:58:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
sub findStorePath {
|
|
|
|
my $storePath = shift;
|
|
|
|
|
|
|
|
my $storePathName = basename $storePath;
|
|
|
|
|
|
|
|
foreach my $store (@remoteStores) {
|
|
|
|
# Determine whether $storePath exists by looking for the
|
|
|
|
# existence of the info file, and if so, get store path info
|
|
|
|
# from that file. This rather breaks abstraction: we should
|
|
|
|
# be using `nix-store' for that. But right now there is no
|
|
|
|
# good way to tell nix-store to access a store mounted under a
|
|
|
|
# different location (there's $NIX_STORE, but that only works
|
|
|
|
# if the remote store is mounted under its "real" location).
|
|
|
|
my $infoFile = "$store/var/nix/db/info/$storePathName";
|
|
|
|
my $storePath2 = "$store/store/$storePathName";
|
|
|
|
if (-f $infoFile && -e $storePath2) {
|
|
|
|
return ($infoFile, $storePath2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-02 14:54:35 +02:00
|
|
|
if ($ARGV[0] eq "--query") {
|
2008-07-12 20:58:24 +02:00
|
|
|
|
2008-08-02 14:54:35 +02:00
|
|
|
while (<STDIN>) {
|
|
|
|
my $cmd = $_; chomp $cmd;
|
2008-07-12 20:58:24 +02:00
|
|
|
|
2008-08-02 14:54:35 +02:00
|
|
|
if ($cmd eq "have") {
|
|
|
|
my $storePath = <STDIN>; chomp $storePath;
|
|
|
|
(my $infoFile) = findStorePath $storePath;
|
|
|
|
print STDOUT ($infoFile ? "1\n" : "0\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
elsif ($cmd eq "info") {
|
|
|
|
my $storePath = <STDIN>; chomp $storePath;
|
|
|
|
(my $infoFile) = findStorePath $storePath;
|
|
|
|
if (!$infoFile) {
|
|
|
|
print "0\n";
|
|
|
|
next; # not an error
|
|
|
|
}
|
|
|
|
print "1\n";
|
|
|
|
|
|
|
|
my $deriver = "";
|
|
|
|
my @references = ();
|
|
|
|
|
|
|
|
open INFO, "<$infoFile" or die "cannot read info file $infoFile\n";
|
|
|
|
while (<INFO>) {
|
|
|
|
chomp;
|
|
|
|
/^([\w-]+): (.*)$/ or die "bad info file";
|
|
|
|
my $key = $1;
|
|
|
|
my $value = $2;
|
|
|
|
if ($key eq "Deriver") { $deriver = $value; }
|
|
|
|
elsif ($key eq "References") { @references = split ' ', $value; }
|
|
|
|
}
|
|
|
|
close INFO;
|
|
|
|
|
|
|
|
print "$deriver\n";
|
|
|
|
print scalar @references, "\n";
|
|
|
|
print "$_\n" foreach @references;
|
2008-08-04 15:15:47 +02:00
|
|
|
print "0\n"; # !!! showing size not supported (yet)
|
2008-07-12 20:58:24 +02:00
|
|
|
}
|
|
|
|
|
2008-08-02 14:54:35 +02:00
|
|
|
else { die "unknown command `$cmd'"; }
|
2008-07-12 20:58:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
elsif ($ARGV[0] eq "--substitute") {
|
|
|
|
die unless scalar @ARGV == 2;
|
|
|
|
my $storePath = $ARGV[1];
|
|
|
|
(my $infoFile, my $sourcePath) = findStorePath $storePath;
|
2008-07-18 15:05:10 +02:00
|
|
|
die unless $infoFile;
|
2008-07-12 20:58:24 +02:00
|
|
|
print "\n*** Copying `$storePath' from `$sourcePath'\n\n";
|
2008-11-20 16:44:59 +01:00
|
|
|
system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $storePath") == 0
|
2008-07-12 20:58:24 +02:00
|
|
|
or die "cannot copy `$sourcePath' to `$storePath'";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else { die; }
|