aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-07-12 16:16:27 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-07-12 16:16:27 +0200
commit731bc65ec04900834ca5e5b8e9dae1aa8c2c1027 (patch)
treea0174b44de8c1ebfdad441d43f776a02377aac07 /src
parent7ba928116ef1677b7403525df9e8abb49001820e (diff)
Refactor a bit
Diffstat (limited to 'src')
-rw-r--r--src/nix/shell.cc47
1 files changed, 21 insertions, 26 deletions
diff --git a/src/nix/shell.cc b/src/nix/shell.cc
index 4c7b701dc..442835d38 100644
--- a/src/nix/shell.cc
+++ b/src/nix/shell.cc
@@ -104,7 +104,7 @@ Path getDerivationEnvironment(ref<Store> store, Derivation drv)
return shellOutPath;
}
-struct Common : InstallableCommand
+struct Common : InstallableCommand, MixProfile
{
/*
std::set<string> keepVars{
@@ -173,9 +173,26 @@ struct Common : InstallableCommand
{
return {"devShell", "defaultPackage"};
}
+
+ BuildEnvironment getBuildEnvironment(ref<Store> store)
+ {
+ auto drvs = toDerivations(store, {installable});
+
+ if (drvs.size() != 1)
+ throw Error("'%s' needs to evaluate to a single derivation, but it evaluated to %d derivations",
+ installable->what(), drvs.size());
+
+ auto & drvPath = *drvs.begin();
+
+ auto shellOutPath = getDerivationEnvironment(store, store->derivationFromPath(drvPath));
+
+ updateProfile(shellOutPath);
+
+ return readEnvironment(shellOutPath);
+ }
};
-struct CmdDevShell : Common, MixProfile
+struct CmdDevShell : Common
{
std::string description() override
{
@@ -202,19 +219,7 @@ struct CmdDevShell : Common, MixProfile
void run(ref<Store> store) override
{
- auto drvs = toDerivations(store, {installable});
-
- if (drvs.size() != 1)
- throw Error("'%s' needs to evaluate to a single derivation, but it evaluated to %d derivations",
- installable->what(), drvs.size());
-
- auto & drvPath = *drvs.begin();
-
- auto shellOutPath = getDerivationEnvironment(store, store->derivationFromPath(drvPath));
-
- updateProfile(shellOutPath);
-
- auto buildEnvironment = readEnvironment(shellOutPath);
+ auto buildEnvironment = getBuildEnvironment(store);
auto [rcFileFd, rcFilePath] = createTempFile("nix-shell");
@@ -259,17 +264,7 @@ struct CmdPrintDevEnv : Common
void run(ref<Store> store) override
{
- auto drvs = toDerivations(store, {installable});
-
- if (drvs.size() != 1)
- throw Error("'%s' needs to evaluate to a single derivation, but it evaluated to %d derivations",
- installable->what(), drvs.size());
-
- auto & drvPath = *drvs.begin();
-
- auto buildEnvironment = readEnvironment(
- getDerivationEnvironment(store,
- store->derivationFromPath(drvPath)));
+ auto buildEnvironment = getBuildEnvironment(store);
stopProgressBar();