aboutsummaryrefslogtreecommitdiff
path: root/src/nix/develop.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-09-08 14:43:12 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-09-08 14:43:12 +0200
commitb71428c90780850733b86e6f7d0d0669898b0528 (patch)
tree0ef824bb11633698fc1280a9321a07bf6d546535 /src/nix/develop.cc
parent3c56f62093601143838af923195f630d8ffae2d4 (diff)
parentd7fe36116e029a714aaf0594e06e5d056f70f7d5 (diff)
Merge branch 'fix-3976' of https://github.com/mkenigs/nix
Diffstat (limited to 'src/nix/develop.cc')
-rw-r--r--src/nix/develop.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index c823f16c8..c20b9f272 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -9,6 +9,7 @@
#include "progress-bar.hh"
#include "run.hh"
+#include <memory>
#include <nlohmann/json.hpp>
using namespace nix;
@@ -505,6 +506,20 @@ struct CmdDevelop : Common, MixEnvironment
auto args = phase || !command.empty() ? Strings{std::string(baseNameOf(shell)), rcFilePath}
: Strings{std::string(baseNameOf(shell)), "--rcfile", rcFilePath};
+ // Need to chdir since phases assume in flake directory
+ if (phase) {
+ // chdir if installable is a flake of type git+file or path
+ auto installableFlake = std::dynamic_pointer_cast<InstallableFlake>(installable);
+ if (installableFlake) {
+ auto sourcePath = installableFlake->getLockedFlake()->flake.resolvedRef.input.getSourcePath();
+ if (sourcePath) {
+ if (chdir(sourcePath->c_str()) == -1) {
+ throw SysError("chdir to '%s' failed", *sourcePath);
+ }
+ }
+ }
+ }
+
runProgramInStore(store, shell, args);
}
};