mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 16:16:16 +02:00
nix dev-shell: Make it possible to enter a profile
For example: $ nix dev-shell --profile /tmp/my-shell dwarffs (later) $ nix dev-shell /tmp/my-shell
This commit is contained in:
parent
731bc65ec0
commit
aa82f8b2d2
3 changed files with 36 additions and 10 deletions
|
@ -64,6 +64,13 @@ struct Installable
|
||||||
{
|
{
|
||||||
throw Error("argument '%s' cannot be evaluated", what());
|
throw Error("argument '%s' cannot be evaluated", what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return a value only if this installable is a store path or a
|
||||||
|
symlink to it. */
|
||||||
|
virtual std::optional<Path> getStorePath()
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EvalCommand : virtual StoreCommand, MixEvalArgs
|
struct EvalCommand : virtual StoreCommand, MixEvalArgs
|
||||||
|
|
|
@ -102,6 +102,11 @@ struct InstallableStorePath : Installable
|
||||||
{
|
{
|
||||||
return {{isDerivation(storePath) ? storePath : "", {{"out", storePath}}}};
|
return {{isDerivation(storePath) ? storePath : "", {{"out", storePath}}}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<Path> getStorePath() override
|
||||||
|
{
|
||||||
|
return storePath;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InstallableValue : Installable
|
struct InstallableValue : Installable
|
||||||
|
|
|
@ -174,8 +174,12 @@ struct Common : InstallableCommand, MixProfile
|
||||||
return {"devShell", "defaultPackage"};
|
return {"devShell", "defaultPackage"};
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildEnvironment getBuildEnvironment(ref<Store> store)
|
Path getShellOutPath(ref<Store> store)
|
||||||
{
|
{
|
||||||
|
auto path = installable->getStorePath();
|
||||||
|
if (path && hasSuffix(*path, "-env"))
|
||||||
|
return *path;
|
||||||
|
else {
|
||||||
auto drvs = toDerivations(store, {installable});
|
auto drvs = toDerivations(store, {installable});
|
||||||
|
|
||||||
if (drvs.size() != 1)
|
if (drvs.size() != 1)
|
||||||
|
@ -184,7 +188,13 @@ struct Common : InstallableCommand, MixProfile
|
||||||
|
|
||||||
auto & drvPath = *drvs.begin();
|
auto & drvPath = *drvs.begin();
|
||||||
|
|
||||||
auto shellOutPath = getDerivationEnvironment(store, store->derivationFromPath(drvPath));
|
return getDerivationEnvironment(store, store->derivationFromPath(drvPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildEnvironment getBuildEnvironment(ref<Store> store)
|
||||||
|
{
|
||||||
|
auto shellOutPath = getShellOutPath(store);
|
||||||
|
|
||||||
updateProfile(shellOutPath);
|
updateProfile(shellOutPath);
|
||||||
|
|
||||||
|
@ -212,7 +222,11 @@ struct CmdDevShell : Common
|
||||||
},
|
},
|
||||||
Example{
|
Example{
|
||||||
"To store the build environment in a profile:",
|
"To store the build environment in a profile:",
|
||||||
"nix dev-shell --profile /tmp/my-shell"
|
"nix dev-shell --profile /tmp/my-shell nixpkgs:hello"
|
||||||
|
},
|
||||||
|
Example{
|
||||||
|
"To use a build environment previously recorded in a profile:",
|
||||||
|
"nix dev-shell /tmp/my-shell"
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue