Skip to content

Commit e1c0bf9

Browse files
committed
Don't crash when copying realisations to a non-ca remote
Rather throw a proper exception, and catch&log it on the client side
1 parent 8ac4133 commit e1c0bf9

4 files changed

Lines changed: 34 additions & 8 deletions

File tree

src/libstore/globals.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,15 @@ bool Settings::isExperimentalFeatureEnabled(const std::string & name)
159159
return std::find(f.begin(), f.end(), name) != f.end();
160160
}
161161

162+
MissingExperimentalFeature::MissingExperimentalFeature(std::string feature)
163+
: Error("experimental Nix feature '%1%' is disabled; use '--experimental-features %1%' to override", feature)
164+
, missingFeature(feature)
165+
{}
166+
162167
void Settings::requireExperimentalFeature(const std::string & name)
163168
{
164169
if (!isExperimentalFeatureEnabled(name))
165-
throw Error("experimental Nix feature '%1%' is disabled; use '--experimental-features %1%' to override", name);
170+
throw MissingExperimentalFeature(name);
166171
}
167172

168173
bool Settings::isWSL1()

src/libstore/globals.hh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
2828
void set(const std::string & str, bool append = false) override;
2929
};
3030

31+
/* MakeError(MissingExperimentalFeature, Error); */
32+
class MissingExperimentalFeature: public Error
33+
{
34+
public:
35+
std::string missingFeature;
36+
37+
MissingExperimentalFeature(std::string feature);
38+
virtual const char* sname() const override { return "MissingExperimentalFeature"; }
39+
};
40+
3141
class Settings : public Config {
3242

3343
unsigned int getDefaultCores();
@@ -615,7 +625,7 @@ public:
615625
is `root`.
616626
617627
> **Warning**
618-
>
628+
>
619629
> Adding a user to `trusted-users` is essentially equivalent to
620630
> giving that user root access to the system. For example, the user
621631
> can set `sandbox-paths` and thereby obtain read access to
@@ -672,7 +682,7 @@ public:
672682
send a series of commands to modify various settings to stdout. The
673683
currently recognized commands are:
674684
675-
- `extra-sandbox-paths`
685+
- `extra-sandbox-paths`
676686
Pass a list of files and directories to be included in the
677687
sandbox for this build. One entry per line, terminated by an
678688
empty line. Entries have the same format as `sandbox-paths`.
@@ -705,13 +715,13 @@ public:
705715
The program executes with no arguments. The program's environment
706716
contains the following environment variables:
707717
708-
- `DRV_PATH`
718+
- `DRV_PATH`
709719
The derivation for the built paths.
710720
711721
Example:
712722
`/nix/store/5nihn1a7pa8b25l9zafqaqibznlvvp3f-bash-4.4-p23.drv`
713723
714-
- `OUT_PATHS`
724+
- `OUT_PATHS`
715725
Output paths of the built derivation, separated by a space
716726
character.
717727
@@ -742,7 +752,7 @@ public:
742752
documentation](https://ec.haxx.se/usingcurl-netrc.html).
743753
744754
> **Note**
745-
>
755+
>
746756
> This must be an absolute path, and `~` is not resolved. For
747757
> example, `~/.netrc` won't resolve to your home directory's
748758
> `.netrc`.

src/libstore/local-store.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat
655655

656656
void LocalStore::registerDrvOutput(const Realisation & info)
657657
{
658+
settings.requireExperimentalFeature("ca-derivations");
658659
auto state(_state.lock());
659660
retrySQLite<void>([&]() {
660661
state->stmts->RegisterRealisedOutput.use()

src/libstore/store-api.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,18 @@ std::map<StorePath, StorePath> copyPaths(ref<Store> srcStore, ref<Store> dstStor
794794
realisations.insert(*realisation);
795795
}
796796
auto pathsMap = copyPaths(srcStore, dstStore, storePaths, repair, checkSigs, substitute);
797-
for (auto& realisation : realisations) {
798-
dstStore->registerDrvOutput(realisation);
797+
try {
798+
for (auto& realisation : realisations) {
799+
dstStore->registerDrvOutput(realisation);
800+
}
801+
} catch (MissingExperimentalFeature & e) {
802+
// Don't fail if the remote doesn't support CA derivations is it might
803+
// not be whithin our control to change that, and we might still want
804+
// to at least copy the output paths.
805+
if (e.missingFeature == "ca-derivations")
806+
ignoreException();
807+
else
808+
throw;
799809
}
800810

801811
return pathsMap;

0 commit comments

Comments
 (0)