From d7fe36116e029a714aaf0594e06e5d056f70f7d5 Mon Sep 17 00:00:00 2001 From: Matthew Kenigsberg Date: Thu, 19 Aug 2021 15:42:13 -0500 Subject: [PATCH] nix develop --phase: chdir to flake directory For git+file and path flakes, chdir to flake directory so that phases that expect to be in the flake directory can run Fixes https://github.com/NixOS/nix/issues/3976 --- src/nix/develop.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 55023545d..40e9d98b0 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -9,6 +9,7 @@ #include "progress-bar.hh" #include "run.hh" +#include #include 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(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); } };