Commit a07dd748 authored by Jade Lovelace's avatar Jade Lovelace
Browse files

nixos-option: update to nix 2.18

This utility has horrendous code quality, partially due to nix's fault,
and really desperately needs to be rewritten, hopefully to not use the
nix C++ API. Either use the Python bindings to the Nix C API when the
Nix team merges the C API, or just write a clever bit of Nix script to
extract the data from a config, turn it into json, then process it into
good output in a CLI wrapper.

It currently does not support flakes and has many other issues.
(in my testing it did not accept -I nixos-path, it exploded due to
having plugins in /etc/nix/nix.conf with no way to override that, among
other breakage that simply does not exist in the Nix CLI).
parent e09d2ff9
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -368,20 +368,20 @@ std::string describeError(const Error & e) { return "«error: " + e.msg() + "»"
void describeDerivation(Context & ctx, Out & out, Value v)
{
    // Copy-pasted from nix/src/nix/repl.cc  :(
    out << "«derivation ";
    Bindings::iterator i = v.attrs->find(ctx.state.sDrvPath);
    PathSet pathset;
    try {
        Path drvPath = i != v.attrs->end() ? ctx.state.coerceToPath(i->pos, *i->value, pathset, "while evaluating the drvPath of a derivation") : "???";
        out << "«derivation " << drvPath << "»";
    } catch (Error & e) {
        out << describeError(e);
    }
    nix::NixStringContext strContext;
    if (i != v.attrs->end())
        out << ctx.state.store->printStorePath(ctx.state.coerceToStorePath(i->pos, *i->value, strContext, "while evaluating the drvPath of a derivation"));
    else
        out << "???";
    out << "»";
}

Value parseAndEval(EvalState & state, const std::string & expression, const std::string & path)
{
    Value v{};
    state.eval(state.parseExprFromString(expression, absPath(path)), v);
    state.eval(state.parseExprFromString(expression, nix::SourcePath(nix::CanonPath::fromCwd(path))), v);
    return v;
}

+1 −1
Original line number Diff line number Diff line
@@ -40368,7 +40368,7 @@ with pkgs;
  nix-melt = callPackage ../tools/nix/nix-melt { };
  nixos-option = callPackage ../tools/nix/nixos-option {
    nix = nixVersions.nix_2_15;
    nix = nixVersions.nix_2_18;
  };
  nix-pin = callPackage ../tools/package-management/nix-pin { };