aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-02-26 12:20:42 +0100
committerGitHub <noreply@github.com>2021-02-26 12:20:42 +0100
commitd2803406b527fdabc893e09c7167a3cdf5a5fc08 (patch)
tree5880471cd6c4ac82194e005ee7bcf48a4253ad76 /src/libstore
parent5edab777d110ca0fb6dd0516089e09a69c1e54d7 (diff)
parentc43f446f4e3a1a8d91560b6ebbcc7d4fbbbf71c4 (diff)
Merge pull request #4487 from NixOS/ca/copy-drv-outputs
Copy ca derivation outputs
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/globals.cc7
-rw-r--r--src/libstore/globals.hh17
-rw-r--r--src/libstore/local-store.cc1
-rw-r--r--src/libstore/store-api.cc43
-rw-r--r--src/libstore/store-api.hh9
5 files changed, 53 insertions, 24 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 2780e0bf5..8d44003f4 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -165,10 +165,15 @@ bool Settings::isExperimentalFeatureEnabled(const std::string & name)
return std::find(f.begin(), f.end(), name) != f.end();
}
+MissingExperimentalFeature::MissingExperimentalFeature(std::string feature)
+ : Error("experimental Nix feature '%1%' is disabled; use '--experimental-features %1%' to override", feature)
+ , missingFeature(feature)
+ {}
+
void Settings::requireExperimentalFeature(const std::string & name)
{
if (!isExperimentalFeatureEnabled(name))
- throw Error("experimental Nix feature '%1%' is disabled; use '--experimental-features %1%' to override", name);
+ throw MissingExperimentalFeature(name);
}
bool Settings::isWSL1()
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index df61d6417..a51d9c2f1 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -45,6 +45,15 @@ struct PluginFilesSetting : public BaseSetting<Paths>
void set(const std::string & str, bool append = false) override;
};
+class MissingExperimentalFeature: public Error
+{
+public:
+ std::string missingFeature;
+
+ MissingExperimentalFeature(std::string feature);
+ virtual const char* sname() const override { return "MissingExperimentalFeature"; }
+};
+
class Settings : public Config {
unsigned int getDefaultCores();
@@ -632,7 +641,7 @@ public:
is `root`.
> **Warning**
- >
+ >
> Adding a user to `trusted-users` is essentially equivalent to
> giving that user root access to the system. For example, the user
> can set `sandbox-paths` and thereby obtain read access to
@@ -722,13 +731,13 @@ public:
The program executes with no arguments. The program's environment
contains the following environment variables:
- - `DRV_PATH`
+ - `DRV_PATH`
The derivation for the built paths.
Example:
`/nix/store/5nihn1a7pa8b25l9zafqaqibznlvvp3f-bash-4.4-p23.drv`
- - `OUT_PATHS`
+ - `OUT_PATHS`
Output paths of the built derivation, separated by a space
character.
@@ -759,7 +768,7 @@ public:
documentation](https://ec.haxx.se/usingcurl-netrc.html).
> **Note**
- >
+ >
> This must be an absolute path, and `~` is not resolved. For
> example, `~/.netrc` won't resolve to your home directory's
> `.netrc`.
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 0962418dd..90fb4a4bd 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -655,6 +655,7 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat
void LocalStore::registerDrvOutput(const Realisation & info)
{
+ settings.requireExperimentalFeature("ca-derivations");
auto state(_state.lock());
retrySQLite<void>([&]() {
state->stmts->RegisterRealisedOutput.use()
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 2658f7617..77c310988 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -783,6 +783,36 @@ void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
}
+std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStore, const RealisedPath::Set & paths,
+ RepairFlag repair, CheckSigsFlag checkSigs, SubstituteFlag substitute)
+{
+ StorePathSet storePaths;
+ std::set<Realisation> realisations;
+ for (auto & path : paths) {
+ storePaths.insert(path.path());
+ if (auto realisation = std::get_if<Realisation>(&path.raw)) {
+ settings.requireExperimentalFeature("ca-derivations");
+ realisations.insert(*realisation);
+ }
+ }
+ auto pathsMap = copyPaths(srcStore, dstStore, storePaths, repair, checkSigs, substitute);
+ try {
+ for (auto & realisation : realisations) {
+ dstStore->registerDrvOutput(realisation);
+ }
+ } catch (MissingExperimentalFeature & e) {
+ // Don't fail if the remote doesn't support CA derivations is it might
+ // not be within our control to change that, and we might still want
+ // to at least copy the output paths.
+ if (e.missingFeature == "ca-derivations")
+ ignoreException();
+ else
+ throw;
+ }
+
+ return pathsMap;
+}
+
std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStore, const StorePathSet & storePaths,
RepairFlag repair, CheckSigsFlag checkSigs, SubstituteFlag substitute)
{
@@ -796,7 +826,6 @@ std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStor
for (auto & path : storePaths)
pathsMap.insert_or_assign(path, path);
- if (missing.empty()) return pathsMap;
Activity act(*logger, lvlInfo, actCopyPaths, fmt("copying %d paths", missing.size()));
@@ -871,21 +900,9 @@ std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStor
nrDone++;
showProgress();
});
-
return pathsMap;
}
-
-void copyClosure(ref<Store> srcStore, ref<Store> dstStore,
- const StorePathSet & storePaths, RepairFlag repair, CheckSigsFlag checkSigs,
- SubstituteFlag substitute)
-{
- StorePathSet closure;
- srcStore->computeFSClosure(storePaths, closure);
- copyPaths(srcStore, dstStore, closure, repair, checkSigs, substitute);
-}
-
-
std::optional<ValidPathInfo> decodeValidPathInfo(const Store & store, std::istream & str, std::optional<HashResult> hashGiven)
{
std::string path;
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 6dcd43ed1..742cd18db 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -752,15 +752,12 @@ void copyStorePath(ref<Store> srcStore, ref<Store> dstStore,
that. Returns a map of what each path was copied to the dstStore
as. */
std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStore,
- const StorePathSet & storePaths,
+ const RealisedPath::Set &,
RepairFlag repair = NoRepair,
CheckSigsFlag checkSigs = CheckSigs,
SubstituteFlag substitute = NoSubstitute);
-
-
-/* Copy the closure of the specified paths from one store to another. */
-void copyClosure(ref<Store> srcStore, ref<Store> dstStore,
- const StorePathSet & storePaths,
+std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStore,
+ const StorePathSet& paths,
RepairFlag repair = NoRepair,
CheckSigsFlag checkSigs = CheckSigs,
SubstituteFlag substitute = NoSubstitute);