mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
* Added a command ‘nix-store --print-env $drvpath’ that prints out the
environment of the given derivation in a format that can be sourced by the shell, e.g. $ eval "$(nix-store --print-env $(nix-instantiate /etc/nixos/nixpkgs -A pkg))" $ NIX_BUILD_TOP=/tmp $ source $stdenv/setup This is especially useful to reproduce the environment used to build a package outside of its builder for development purposes. TODO: add a nix-build option to do the above and fetch the dependencies of the derivation as well.
This commit is contained in:
parent
2a3f4110c5
commit
4e624849b6
2 changed files with 39 additions and 0 deletions
|
@ -44,6 +44,10 @@
|
||||||
<para>TODO: <command>nix-store --verify-path</command> command.</para>
|
<para>TODO: <command>nix-store --verify-path</command> command.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
|
<listitem>
|
||||||
|
<para>TODO: <command>nix-store --print-env</command> command.</para>
|
||||||
|
</listitem>
|
||||||
|
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -382,6 +382,39 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static string shellEscape(const string & s)
|
||||||
|
{
|
||||||
|
string r;
|
||||||
|
foreach (string::const_iterator, i, s)
|
||||||
|
if (*i == '\'') r += "'\\''"; else r += *i;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void opPrintEnv(Strings opFlags, Strings opArgs)
|
||||||
|
{
|
||||||
|
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||||
|
if (opArgs.size() != 1) throw UsageError("`--print-env' requires one derivation store path");
|
||||||
|
|
||||||
|
Path drvPath = opArgs.front();
|
||||||
|
Derivation drv = derivationFromPath(*store, drvPath);
|
||||||
|
|
||||||
|
/* Print each environment variable in the derivation in a format
|
||||||
|
that can be sourced by the shell. */
|
||||||
|
foreach (StringPairs::iterator, i, drv.env)
|
||||||
|
cout << format("export %1%; %1%='%2%'\n") % i->first % shellEscape(i->second);
|
||||||
|
|
||||||
|
/* Also output the arguments. This doesn't preserve whitespace in
|
||||||
|
arguments. */
|
||||||
|
cout << "export _args; _args='";
|
||||||
|
foreach (Strings::iterator, i, drv.args) {
|
||||||
|
if (i != drv.args.begin()) cout << ' ';
|
||||||
|
cout << shellEscape(*i);
|
||||||
|
}
|
||||||
|
cout << "'\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void opReadLog(Strings opFlags, Strings opArgs)
|
static void opReadLog(Strings opFlags, Strings opArgs)
|
||||||
{
|
{
|
||||||
if (!opFlags.empty()) throw UsageError("unknown flag");
|
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||||
|
@ -754,6 +787,8 @@ void run(Strings args)
|
||||||
op = opDelete;
|
op = opDelete;
|
||||||
else if (arg == "--query" || arg == "-q")
|
else if (arg == "--query" || arg == "-q")
|
||||||
op = opQuery;
|
op = opQuery;
|
||||||
|
else if (arg == "--print-env")
|
||||||
|
op = opPrintEnv;
|
||||||
else if (arg == "--read-log" || arg == "-l")
|
else if (arg == "--read-log" || arg == "-l")
|
||||||
op = opReadLog;
|
op = opReadLog;
|
||||||
else if (arg == "--dump-db")
|
else if (arg == "--dump-db")
|
||||||
|
|
Loading…
Reference in a new issue