aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-04 07:21:01 +0100
committereldritch horrors <pennae@lix.systems>2024-03-04 07:21:01 +0100
commit7614aa97975f3e6e36b6ffbd9fec34462021ab39 (patch)
treeebb2521607d7b5a30fadcc13e0af889159d5af2e /src
parent64a269ef73b111d49037812bd899b5cb883158ef (diff)
Merge pull request #4093 from matthewbauer/eval-system
Add eval-system option (cherry picked from commit 071dbbee33af9f27338c3e53e4ea067dbfa14010) Change-Id: Ia81358c8cfb60241da07a4d0e84b9ee62a18a53f
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval-settings.cc6
-rw-r--r--src/libexpr/eval-settings.hh20
-rw-r--r--src/libexpr/primops.cc11
-rw-r--r--src/libstore/globals.hh6
4 files changed, 38 insertions, 5 deletions
diff --git a/src/libexpr/eval-settings.cc b/src/libexpr/eval-settings.cc
index 93b4a5289..89ca198d8 100644
--- a/src/libexpr/eval-settings.cc
+++ b/src/libexpr/eval-settings.cc
@@ -88,6 +88,12 @@ std::string EvalSettings::resolvePseudoUrl(std::string_view url)
return std::string(url);
}
+const std::string & EvalSettings::getCurrentSystem()
+{
+ const auto & evalSystem = currentSystem.get();
+ return evalSystem != "" ? evalSystem : settings.thisSystem.get();
+}
+
EvalSettings evalSettings;
static GlobalConfig::Register rEvalSettings(&evalSettings);
diff --git a/src/libexpr/eval-settings.hh b/src/libexpr/eval-settings.hh
index 19122bc31..049f42e70 100644
--- a/src/libexpr/eval-settings.hh
+++ b/src/libexpr/eval-settings.hh
@@ -25,6 +25,26 @@ struct EvalSettings : Config
[`builtins.nixPath`](@docroot@/language/builtin-constants.md#builtins-nixPath).
)"};
+ Setting<std::string> currentSystem{
+ this, "", "eval-system",
+ R"(
+ This option defines
+ [`builtins.currentSystem`](@docroot@/language/builtin-constants.md#builtins-currentSystem)
+ in the Nix language if it is set as a non-empty string.
+ Otherwise, if it is defined as the empty string (the default), the value of the
+ [`system` ](#conf-system)
+ configuration setting is used instead.
+
+ Unlike `system`, this setting does not change what kind of derivations can be built locally.
+ This is useful for evaluating Nix code on one system to produce derivations to be built on another type of system.
+ )"};
+
+ /**
+ * Implements the `eval-system` vs `system` defaulting logic
+ * described for `eval-system`.
+ */
+ const std::string & getCurrentSystem();
+
Setting<bool> restrictEval{
this, false, "restrict-eval",
R"(
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index b906e7747..005a38319 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -4288,13 +4288,16 @@ void EvalState::createBaseEnv()
.impureOnly = true,
});
- if (!evalSettings.pureEval) {
- v.mkString(settings.thisSystem.get());
- }
+ if (!evalSettings.pureEval)
+ v.mkString(evalSettings.getCurrentSystem());
addConstant("__currentSystem", v, {
.type = nString,
.doc = R"(
- The value of the [`system` configuration option](@docroot@/command-ref/conf-file.md#conf-pure-eval).
+ The value of the
+ [`eval-system`](@docroot@/command-ref/conf-file.md#conf-eval-system)
+ or else
+ [`system`](@docroot@/command-ref/conf-file.md#conf-system)
+ configuration option.
It can be used to set the `system` attribute for [`builtins.derivation`](@docroot@/language/derivations.md) such that the resulting derivation can be built on the same system that evaluates the Nix expression:
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index 229f1a96a..1fb9ec746 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -210,7 +210,11 @@ public:
In general, you do not have to modify this setting.
While you can force Nix to run a Darwin-specific `builder` executable on a Linux machine, the result would obviously be wrong.
- This value is available in the Nix language as [`builtins.currentSystem`](@docroot@/language/builtin-constants.md#builtins-currentSystem).
+ This value is available in the Nix language as
+ [`builtins.currentSystem`](@docroot@/language/builtin-constants.md#builtins-currentSystem)
+ if the
+ [`eval-system`](#conf-eval-system)
+ configuration option is set as the empty string.
)"};
Setting<time_t> maxSilentTime{