2020-10-11 16:17:24 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "lock.hh"
|
2020-10-12 17:16:25 +00:00
|
|
|
#include "store-api.hh"
|
|
|
|
#include "goal.hh"
|
2009-01-12 16:30:32 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
namespace nix {
|
|
|
|
|
2004-06-18 18:09:32 +00:00
|
|
|
class Worker;
|
2004-05-11 18:05:44 +00:00
|
|
|
|
2020-11-09 12:47:06 +00:00
|
|
|
struct PathSubstitutionGoal : public Goal
|
2004-05-11 18:05:44 +00:00
|
|
|
{
|
2020-10-11 16:17:24 +00:00
|
|
|
/* The store path that should be realised through a substitute. */
|
|
|
|
StorePath storePath;
|
2019-05-12 20:47:41 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* The path the substituter refers to the path as. This will be
|
2021-04-07 10:21:31 +00:00
|
|
|
different when the stores have different names. */
|
2020-10-11 16:17:24 +00:00
|
|
|
std::optional<StorePath> subPath;
|
2019-05-12 20:47:41 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* The remaining substituters. */
|
|
|
|
std::list<ref<Store>> subs;
|
2010-08-25 20:44:28 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* The current substituter. */
|
|
|
|
std::shared_ptr<Store> sub;
|
2006-12-08 18:41:48 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* Whether a substituter failed. */
|
|
|
|
bool substituterFailed = false;
|
2006-12-08 18:41:48 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* Path info returned by the substituter's query info operation. */
|
|
|
|
std::shared_ptr<const ValidPathInfo> info;
|
2006-12-08 18:41:48 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* Pipe for the substituter's standard output. */
|
|
|
|
Pipe outPipe;
|
2006-12-08 18:41:48 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* The substituter thread. */
|
|
|
|
std::thread thr;
|
2004-05-11 18:05:44 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
std::promise<void> promise;
|
2004-05-11 18:05:44 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* Whether to try to repair a valid path. */
|
|
|
|
RepairFlag repair;
|
2012-11-26 16:15:09 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* Location where we're downloading the substitute. Differs from
|
|
|
|
storePath when doing a repair. */
|
|
|
|
Path destPath;
|
2012-11-26 16:15:09 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
std::unique_ptr<MaintainCount<uint64_t>> maintainExpectedSubstitutions,
|
|
|
|
maintainRunningSubstitutions, maintainExpectedNar, maintainExpectedDownload;
|
2014-11-24 15:44:35 +00:00
|
|
|
|
2020-11-09 12:47:06 +00:00
|
|
|
typedef void (PathSubstitutionGoal::*GoalState)();
|
2020-10-11 16:17:24 +00:00
|
|
|
GoalState state;
|
2003-08-01 14:11:19 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* Content address for recomputing store path */
|
|
|
|
std::optional<ContentAddress> ca;
|
2004-05-11 18:05:44 +00:00
|
|
|
|
2022-04-06 10:41:18 +00:00
|
|
|
void done(
|
|
|
|
ExitCode result,
|
|
|
|
BuildResult::Status status,
|
|
|
|
std::optional<std::string> errorMsg = {});
|
2022-03-08 18:50:46 +00:00
|
|
|
|
2020-11-09 12:47:06 +00:00
|
|
|
public:
|
|
|
|
PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
|
|
|
|
~PathSubstitutionGoal();
|
2004-05-11 18:05:44 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
void timedOut(Error && ex) override { abort(); };
|
2004-05-11 18:05:44 +00:00
|
|
|
|
2022-02-25 15:00:00 +00:00
|
|
|
std::string key() override
|
2020-10-11 16:17:24 +00:00
|
|
|
{
|
|
|
|
/* "a$" ensures substitution goals happen before derivation
|
|
|
|
goals. */
|
|
|
|
return "a$" + std::string(storePath.name()) + "$" + worker.store.printStorePath(storePath);
|
2004-06-25 10:21:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
void work() override;
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* The states. */
|
|
|
|
void init();
|
|
|
|
void tryNext();
|
|
|
|
void gotInfo();
|
|
|
|
void referencesValid();
|
|
|
|
void tryToRun();
|
|
|
|
void finished();
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 15:57:40 +00:00
|
|
|
|
2020-10-11 16:17:24 +00:00
|
|
|
/* Callback used by the worker to write to the log. */
|
2022-02-25 15:00:00 +00:00
|
|
|
void handleChildOutput(int fd, std::string_view data) override;
|
2020-10-11 16:17:24 +00:00
|
|
|
void handleEOF(int fd) override;
|
2021-04-07 10:21:31 +00:00
|
|
|
|
|
|
|
void cleanup() override;
|
2020-10-11 16:17:24 +00:00
|
|
|
};
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 15:57:40 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|