diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-06-02T13·08+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-06-02T14·02+0200 |
commit | 4494000e04122f24558e1436e66d20d89028b4bd (patch) | |
tree | 4d8bb49449aa6f8611a05c96bc9d7342430232f2 /scripts/copy-from-other-stores.pl.in | |
parent | 064816ab98e7a230b6e9f4071353f5172e70cf03 (diff) |
LocalStore: Allow the physical and logical store directories to differ
This is primarily to subsume the functionality of the copy-from-other-stores substituter. For example, in the NixOS installer, we can now do (assuming we're in the target chroot, and the Nix store of the installation CD is bind-mounted on /tmp/nix): $ nix-build ... --option substituters 'local?state=/tmp/nix/var&real=/tmp/nix/store' However, unlike copy-from-other-stores, this also allows write access to such a store. One application might be fetching substitutes for /nix/store in a situation where the user doesn't have sufficient privileges to create /nix, e.g.: $ NIX_REMOTE="local?state=/home/alice/nix/var&real=/home/alice/nix/store" nix-build ...
Diffstat (limited to 'scripts/copy-from-other-stores.pl.in')
-rwxr-xr-x | scripts/copy-from-other-stores.pl.in | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/scripts/copy-from-other-stores.pl.in b/scripts/copy-from-other-stores.pl.in deleted file mode 100755 index 9b0615fe1a10..000000000000 --- a/scripts/copy-from-other-stores.pl.in +++ /dev/null @@ -1,103 +0,0 @@ -#! @perl@ -w @perlFlags@ - -use utf8; -use strict; -use File::Basename; -use IO::Handle; - -my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@"; - - -STDOUT->autoflush(1); -binmode STDERR, ":encoding(utf8)"; - -my @remoteStoresAll = split ':', ($ENV{"NIX_OTHER_STORES"} or ""); - -my @remoteStores; -foreach my $dir (@remoteStoresAll) { - push @remoteStores, glob($dir); -} - -exit if scalar @remoteStores == 0; -print "\n"; - - -$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 "0\n"; - print "$narSize\n"; - } - - print "\n"; - } - - else { die "unknown command ‘$cmd’"; } - } -} - - -elsif ($ARGV[0] eq "--substitute") { - die unless scalar @ARGV == 3; - my $storePath = $ARGV[1]; - my $destPath = $ARGV[2]; - my ($store, $sourcePath) = findStorePath $storePath; - die unless $store; - print STDERR "\n*** Copying ‘$storePath’ from ‘$sourcePath’\n\n"; - system("@coreutils@/cp", "-rpd", $sourcePath, $destPath) == 0 - or die "cannot copy ‘$sourcePath’ to ‘$storePath’"; - print "\n"; # no hash to verify -} - - -else { die; } |