diff --git a/nixos/modules/installer/tools/nixos-option/nixos-option.cc b/nixos/modules/installer/tools/nixos-option/nixos-option.cc index 01eb0d5ddd18..5886ee6959bd 100644 --- a/nixos/modules/installer/tools/nixos-option/nixos-option.cc +++ b/nixos/modules/installer/tools/nixos-option/nixos-option.cc @@ -1,10 +1,12 @@ #include // for nix/globals.hh's reference to SYSTEM +#include // for exception_ptr, current_exception #include // for function #include // for operator<<, basic_ostream, ostrin... #include // for next #include // for _List_iterator #include // for allocator, unique_ptr, make_unique +#include // for operator new #include // for argvToStrings, UsageError #include // for findAlongAttrPath #include // for Attr, Bindings, Bindings::iterator @@ -166,19 +168,19 @@ std::string const appendPath(std::string const & prefix, std::string const & suf bool forbiddenRecursionName(std::string name) { return (!name.empty() && name[0] == '_') || name == "haskellPackages"; } -void recurse(const std::function)> & f, Context * ctx, +void recurse(const std::function)> & f, Context * ctx, Value v, std::string const & path) { - std::variant evaluated; + std::variant evaluated; try { evaluated = evaluateValue(ctx, &v); - } catch (Error & e) { - evaluated = e; + } catch (Error &) { + evaluated = std::current_exception(); } if (!f(path, evaluated)) { return; } - if (std::holds_alternative(evaluated)) { + if (std::holds_alternative(evaluated)) { return; } Value const & evaluated_value = std::get(evaluated); @@ -197,8 +199,8 @@ void recurse(const std::function & f, Context * ctx, Value root) { recurse( - [f, ctx](std::string const & path, std::variant v) { - bool isOpt = std::holds_alternative(v) || isOption(ctx, std::get(v)); + [f, ctx](std::string const & path, std::variant v) { + bool isOpt = std::holds_alternative(v) || isOption(ctx, std::get(v)); if (isOpt) { f(path); } @@ -228,19 +230,19 @@ void mapOptions(const std::function & f, Context // users.users.nixbld1 = ... .. ... // ... // users.users.systemd-timesync = ... .. ... -void mapConfigValuesInOption(const std::function v)> & f, +void mapConfigValuesInOption(const std::function v)> & f, std::string const & path, Context * ctx) { Value * option; try { option = findAlongAttrPath(*ctx->state, path, *ctx->autoArgs, ctx->config_root); - } catch (Error & e) { - f(path, e); + } catch (Error &) { + f(path, std::current_exception()); return; } recurse( - [f, ctx](std::string const & path, std::variant v) { - bool leaf = std::holds_alternative(v) || std::get(v).type != tAttrs || + [f, ctx](std::string const & path, std::variant v) { + bool leaf = std::holds_alternative(v) || std::get(v).type != tAttrs || ctx->state->isDerivation(std::get(v)); if (!leaf) { return true; // Keep digging @@ -273,7 +275,7 @@ Value parseAndEval(EvalState * state, std::string const & expression, std::strin return v; } -void printValue(Context * ctx, Out & out, std::variant maybe_value, std::string const & path); +void printValue(Context * ctx, Out & out, std::variant maybe_value, std::string const & path); void printList(Context * ctx, Out & out, Value & v) { @@ -331,11 +333,11 @@ void printMultiLineString(Out & out, Value const & v) } } -void printValue(Context * ctx, Out & out, std::variant maybe_value, std::string const & path) +void printValue(Context * ctx, Out & out, std::variant maybe_value, std::string const & path) { try { - if (std::holds_alternative(maybe_value)) { - throw Error{std::get(maybe_value)}; + if (std::holds_alternative(maybe_value)) { + std::rethrow_exception(std::get(maybe_value)); } Value v = evaluateValue(ctx, &std::get(maybe_value)); if (ctx->state->isDerivation(v)) { @@ -366,7 +368,7 @@ void printValue(Context * ctx, Out & out, std::variant maybe_value } } -void printConfigValue(Context * ctx, Out & out, std::string const & path, std::variant v) +void printConfigValue(Context * ctx, Out & out, std::string const & path, std::variant v) { out << path << " = "; printValue(ctx, out, std::move(v), path); @@ -378,7 +380,7 @@ void printAll(Context * ctx, Out & out) mapOptions( [ctx, &out](std::string const & option_path) { mapConfigValuesInOption( - [ctx, &out](std::string const & config_path, std::variant v) { + [ctx, &out](std::string const & config_path, std::variant v) { printConfigValue(ctx, out, config_path, v); }, option_path, ctx);