forked from lix-project/lix
* New operation `nix-env --set' which sets a user environment to a
single derivation specified by the argument. This is useful when we want to have a profile for a single derivation, such as a server configuration. Then we can just say (e.g.) $ nix-env -p /.../server-profile -f server.nix --set -A server We can't do queries or upgrades on such a profile, but we can do rollbacks. The advantage over -i is that we don't have to worry about other packages having been installed in the profile previously; --set gets rid of them.
This commit is contained in:
parent
1a7e88bbd9
commit
7ace29dae7
|
@ -45,6 +45,9 @@
|
|||
configuration setting
|
||||
<literal>build-max-silent-time</literal>.</para></listitem>
|
||||
|
||||
|
||||
<listitem><para>TODO: <command>nix-env</command>
|
||||
<option>--set</option>.</para></listitem>
|
||||
|
||||
|
||||
</itemizedlist>
|
||||
|
|
|
@ -6,6 +6,7 @@ Operations:
|
|||
|
||||
--install / -i: add derivations to the user environment
|
||||
--upgrade / -u: upgrade derivation in the user environment
|
||||
--set: create a user environment containing a single derivation
|
||||
--uninstall / -e: remove derivations from the user environment
|
||||
--query / -q: perform a query on an environment or Nix expression
|
||||
|
||||
|
|
|
@ -596,6 +596,31 @@ static void opUpgrade(Globals & globals,
|
|||
}
|
||||
|
||||
|
||||
static void opSet(Globals & globals,
|
||||
Strings opFlags, Strings opArgs)
|
||||
{
|
||||
if (opFlags.size() > 0)
|
||||
throw UsageError(format("unknown flag `%1%'") % opFlags.front());
|
||||
|
||||
DrvInfos elems;
|
||||
queryInstSources(globals.state, globals.instSource, opArgs, elems, true);
|
||||
|
||||
if (elems.size() != 1)
|
||||
throw Error("--set requires exactly one derivation");
|
||||
|
||||
DrvInfo & drv(elems.front());
|
||||
|
||||
if (drv.queryDrvPath(globals.state) != "")
|
||||
store->buildDerivations(singleton<PathSet>(drv.queryDrvPath(globals.state)));
|
||||
else
|
||||
store->ensurePath(drv.queryOutPath(globals.state));
|
||||
|
||||
debug(format("switching to new user environment"));
|
||||
Path generation = createGeneration(globals.profile, drv.queryOutPath(globals.state));
|
||||
switchLink(globals.profile, generation);
|
||||
}
|
||||
|
||||
|
||||
static void uninstallDerivations(Globals & globals, DrvNames & selectors,
|
||||
Path & profile)
|
||||
{
|
||||
|
@ -1152,6 +1177,8 @@ void run(Strings args)
|
|||
op = opUninstall;
|
||||
else if (arg == "--upgrade" || arg == "-u")
|
||||
op = opUpgrade;
|
||||
else if (arg == "--set")
|
||||
op = opSet;
|
||||
else if (arg == "--query" || arg == "-q")
|
||||
op = opQuery;
|
||||
else if (arg == "--import" || arg == "-I") /* !!! bad name */
|
||||
|
|
Loading…
Reference in a new issue