2020-10-11 19:17:24 +03:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2020-10-11 19:17:24 +03:00
|
|
|
|
|
|
|
#include "lock.hh"
|
2020-10-12 20:16:25 +03:00
|
|
|
#include "store-api.hh"
|
|
|
|
#include "goal.hh"
|
2009-01-12 18:30:32 +02:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
namespace nix {
|
|
|
|
|
2004-06-18 21:09:32 +03:00
|
|
|
class Worker;
|
2004-05-11 21:05:44 +03:00
|
|
|
|
2020-11-09 14:47:06 +02:00
|
|
|
struct PathSubstitutionGoal : public Goal
|
2004-05-11 21:05:44 +03:00
|
|
|
{
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The store path that should be realised through a substitute.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
StorePath storePath;
|
2019-05-12 23:47:41 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The path the substituter refers to the path as. This will be
|
|
|
|
* different when the stores have different names.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
std::optional<StorePath> subPath;
|
2019-05-12 23:47:41 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The remaining substituters.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
std::list<ref<Store>> subs;
|
2010-08-25 23:44:28 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The current substituter.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
std::shared_ptr<Store> sub;
|
2006-12-08 20:41:48 +02:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Whether a substituter failed.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
bool substituterFailed = false;
|
2006-12-08 20:41:48 +02:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Path info returned by the substituter's query info operation.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
std::shared_ptr<const ValidPathInfo> info;
|
2006-12-08 20:41:48 +02:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Pipe for the substituter's standard output.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
Pipe outPipe;
|
2006-12-08 20:41:48 +02:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The substituter thread.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
std::thread thr;
|
2004-05-11 21:05:44 +03:00
|
|
|
|
2020-10-11 19:17:24 +03:00
|
|
|
std::promise<void> promise;
|
2004-05-11 21:05:44 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Whether to try to repair a valid path.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
RepairFlag repair;
|
2012-11-26 18:15:09 +02:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Location where we're downloading the substitute. Differs from
|
|
|
|
* storePath when doing a repair.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
Path destPath;
|
2012-11-26 18:15:09 +02:00
|
|
|
|
2020-10-11 19:17:24 +03:00
|
|
|
std::unique_ptr<MaintainCount<uint64_t>> maintainExpectedSubstitutions,
|
|
|
|
maintainRunningSubstitutions, maintainExpectedNar, maintainExpectedDownload;
|
2014-11-24 17:44:35 +02:00
|
|
|
|
2020-11-09 14:47:06 +02:00
|
|
|
typedef void (PathSubstitutionGoal::*GoalState)();
|
2020-10-11 19:17:24 +03:00
|
|
|
GoalState state;
|
2003-08-01 17:11:19 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Content address for recomputing store path
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
std::optional<ContentAddress> ca;
|
2004-05-11 21:05:44 +03:00
|
|
|
|
2022-04-06 13:41:18 +03:00
|
|
|
void done(
|
|
|
|
ExitCode result,
|
|
|
|
BuildResult::Status status,
|
|
|
|
std::optional<std::string> errorMsg = {});
|
2022-03-08 20:50:46 +02:00
|
|
|
|
2020-11-09 14:47:06 +02:00
|
|
|
public:
|
|
|
|
PathSubstitutionGoal(const StorePath & storePath, Worker & worker, RepairFlag repair = NoRepair, std::optional<ContentAddress> ca = std::nullopt);
|
|
|
|
~PathSubstitutionGoal();
|
2004-05-11 21:05:44 +03:00
|
|
|
|
2020-10-11 19:17:24 +03:00
|
|
|
void timedOut(Error && ex) override { abort(); };
|
2004-05-11 21:05:44 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* We prepend "a$" to the key name to ensure substitution goals
|
|
|
|
* happen before derivation goals.
|
|
|
|
*/
|
2022-02-25 17:00:00 +02:00
|
|
|
std::string key() override
|
2020-10-11 19:17:24 +03:00
|
|
|
{
|
|
|
|
return "a$" + std::string(storePath.name()) + "$" + worker.store.printStorePath(storePath);
|
2004-06-25 13:21:44 +03:00
|
|
|
}
|
|
|
|
|
2020-10-11 19:17:24 +03:00
|
|
|
void work() override;
|
2003-07-20 22:29:38 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* The states.
|
|
|
|
*/
|
2020-10-11 19:17:24 +03:00
|
|
|
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 18:57:40 +03:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Callback used by the worker to write to the log.
|
|
|
|
*/
|
2022-02-25 17:00:00 +02:00
|
|
|
void handleChildOutput(int fd, std::string_view data) override;
|
2020-10-11 19:17:24 +03:00
|
|
|
void handleEOF(int fd) override;
|
2021-04-07 13:21:31 +03:00
|
|
|
|
2023-08-11 12:58:33 +03:00
|
|
|
/* Called by destructor, can't be overridden */
|
|
|
|
void cleanup() override final;
|
2023-05-08 21:45:46 +03:00
|
|
|
|
2021-03-08 23:24:49 +02:00
|
|
|
JobCategory jobCategory() const override {
|
|
|
|
return JobCategory::Substitution;
|
|
|
|
};
|
2020-10-11 19:17:24 +03: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 18:57:40 +03:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
}
|