mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 05:56:15 +02:00
Implement nix-copy-closure --from via nix-store --serve
This commit is contained in:
parent
62309a2c56
commit
03103c0a36
4 changed files with 23 additions and 30 deletions
|
@ -272,7 +272,8 @@ if ($res != 0) {
|
||||||
# Copy the output from the build machine.
|
# Copy the output from the build machine.
|
||||||
my @outputs2 = grep { !isValidPath($_) } @outputs;
|
my @outputs2 = grep { !isValidPath($_) } @outputs;
|
||||||
if (scalar @outputs2 > 0) {
|
if (scalar @outputs2 > 0) {
|
||||||
writeInt(5, $to) or die; # == cmdExportPaths
|
writeInt(5, $to); # == cmdExportPaths
|
||||||
|
writeInt(0, $to); # don't sign
|
||||||
writeStrings(\@outputs2, $to);
|
writeStrings(\@outputs2, $to);
|
||||||
$ENV{'NIX_HELD_LOCKS'} = "@outputs2"; # FIXME: ugly
|
$ENV{'NIX_HELD_LOCKS'} = "@outputs2"; # FIXME: ugly
|
||||||
importPaths(fileno($from));
|
importPaths(fileno($from));
|
||||||
|
|
|
@ -89,42 +89,22 @@ if ($toMode) { # Copy TO the remote machine.
|
||||||
|
|
||||||
else { # Copy FROM the remote machine.
|
else { # Copy FROM the remote machine.
|
||||||
|
|
||||||
openSSHConnection $sshHost or die "$0: unable to start SSH\n";
|
my ($from, $to) = connectToRemoteNix($sshHost, [ @sshOpts ]);
|
||||||
|
|
||||||
# Query the closure of the given store paths on the remote
|
# Query the closure of the given store paths on the remote
|
||||||
# machine. Paths are assumed to be store paths; there is no
|
# machine. Paths are assumed to be store paths; there is no
|
||||||
# resolution (following of symlinks).
|
# resolution (following of symlinks).
|
||||||
my $extraOpts = $includeOutputs ? "--include-outputs" : "";
|
syswrite($to, pack("L<x4L<x4", 7, $includeOutputs ? 1 : 0)) or die;
|
||||||
my $pid = open(READ,
|
writeStrings(\@storePaths, $to);
|
||||||
"set -f; ssh @sshOpts $sshHost nix-store --query --requisites $extraOpts @storePaths|") or die;
|
my @missing = grep { !isValidPath($_) } readStrings($from);
|
||||||
|
|
||||||
while (<READ>) {
|
|
||||||
chomp;
|
|
||||||
die "bad: $_" unless /^\//;
|
|
||||||
push @missing, $_ unless isValidPath($_);
|
|
||||||
}
|
|
||||||
|
|
||||||
close READ or die "nix-store on remote machine `$sshHost' failed: $?";
|
|
||||||
|
|
||||||
my $missingSize = 0;
|
|
||||||
if ($progressViewer ne "") {
|
|
||||||
$missingSize = sum (split ' ', `set -f; ssh @sshOpts $sshHost nix-store -q --size @missing`) or die;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Export the store paths on the remote machine and import them locally.
|
# Export the store paths on the remote machine and import them locally.
|
||||||
if (scalar @missing > 0) {
|
if (scalar @missing > 0) {
|
||||||
print STDERR "copying ", scalar @missing, " missing paths from ‘$sshHost’...\n";
|
print STDERR "copying ", scalar @missing, " missing paths from ‘$sshHost’...\n";
|
||||||
unless ($dryRun) {
|
writeInt(5, $to); # == cmdExportPaths
|
||||||
if ($useSubstitutes) {
|
writeInt($sign ? 1 : 0, $to);
|
||||||
system "$Nix::Config::binDir/nix-store -r --ignore-unknown @missing";
|
writeStrings(\@missing, $to);
|
||||||
}
|
importPaths(fileno($from));
|
||||||
$compressor = "| $compressor" if $compressor ne "";
|
|
||||||
$decompressor = "$decompressor |" if $decompressor ne "";
|
|
||||||
$progressViewer = "$progressViewer -s $missingSize |" if $progressViewer ne "";
|
|
||||||
my $extraOpts = $sign ? "--sign" : "";
|
|
||||||
system("set -f; ssh $sshHost @sshOpts 'nix-store --export $extraOpts @missing $compressor' | $decompressor $progressViewer $Nix::Config::binDir/nix-store --import > /dev/null") == 0
|
|
||||||
or die "copying store paths from remote machine `$sshHost' failed: $?";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -993,9 +993,10 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
case cmdExportPaths: {
|
case cmdExportPaths: {
|
||||||
|
bool sign = readInt(in);
|
||||||
Paths sorted = topoSortPaths(*store, readStorePaths<PathSet>(in));
|
Paths sorted = topoSortPaths(*store, readStorePaths<PathSet>(in));
|
||||||
reverse(sorted.begin(), sorted.end());
|
reverse(sorted.begin(), sorted.end());
|
||||||
exportPaths(*store, sorted, false, out);
|
exportPaths(*store, sorted, sign, out);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1025,6 +1026,16 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case cmdQueryClosure: {
|
||||||
|
bool includeOutputs = readInt(in);
|
||||||
|
PathSet paths = readStorePaths<PathSet>(in);
|
||||||
|
PathSet closure;
|
||||||
|
for (auto & i : paths)
|
||||||
|
computeFSClosure(*store, i, closure, false, includeOutputs);
|
||||||
|
writeStrings(closure, out);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw Error(format("unknown serve command %1%") % cmd);
|
throw Error(format("unknown serve command %1%") % cmd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ typedef enum {
|
||||||
cmdImportPaths = 4,
|
cmdImportPaths = 4,
|
||||||
cmdExportPaths = 5,
|
cmdExportPaths = 5,
|
||||||
cmdBuildPaths = 6,
|
cmdBuildPaths = 6,
|
||||||
|
cmdQueryClosure = 7,
|
||||||
} ServeCommand;
|
} ServeCommand;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue