1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 03:23:16 +02:00

Allow substituting paths when building remotely using ssh-ng://

Until now, it was not possible to substitute missing paths from e.g.
`https://cache.nixos.org` on a remote server when building on it using
the new `ssh-ng` protocol.

This is because every store implementation except legacy `ssh://`
ignores the substitution flag passed to `Store::queryValidPaths` while
the `legacy-ssh-store` substitutes the remote store using
`cmdQueryValidPaths` when the remote store is opened with `nix-store
--serve`.

This patch slightly modifies the daemon protocol to allow passing an
integer value suggesting whether to substitute missing paths during
`wopQueryValidPaths`. To implement this on the daemon-side, the
substitution logic from `nix-store --serve` has been moved into a
protected method named `Store::substitutePaths` which gets currently
called from `LocalStore::queryValidPaths` and `Store::queryValidPaths`
if `maybeSubstitute` is `true`.

Fixes #2770
This commit is contained in:
Maximilian Bosch 2020-10-21 21:31:19 +02:00
parent 387f824cab
commit 3a63fc6cd5
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E
7 changed files with 44 additions and 25 deletions

View file

@ -830,29 +830,8 @@ static void opServe(Strings opFlags, Strings opArgs)
for (auto & path : paths)
store->addTempRoot(path);
/* If requested, substitute missing paths. This
implements nix-copy-closure's --use-substitutes
flag. */
if (substitute && writeAllowed) {
/* Filter out .drv files (we don't want to build anything). */
std::vector<StorePathWithOutputs> paths2;
for (auto & path : paths)
if (!path.isDerivation())
paths2.push_back({path});
uint64_t downloadSize, narSize;
StorePathSet willBuild, willSubstitute, unknown;
store->queryMissing(paths2,
willBuild, willSubstitute, unknown, downloadSize, narSize);
/* FIXME: should use ensurePath(), but it only
does one path at a time. */
if (!willSubstitute.empty())
try {
std::vector<StorePathWithOutputs> subs;
for (auto & p : willSubstitute) subs.push_back({p});
store->buildPaths(subs);
} catch (Error & e) {
logWarning(e.info());
}
store->substitutePaths(paths);
}
worker_proto::write(*store, out, store->queryValidPaths(paths));