-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix-shell as root cd's to / #6083
Comments
|
I did a small bit of testing, and found that it was introduced between 2.4 and 2.5.0. I then bisected it to fcb8af5 (by testing git bisect log
cc @yorickvP -- do you have any idea how to fix this? |
Since I'm not going to have time to continue on this during the next few days: The fix is to Here is my WIP commit message for anyone who wants to work on this:
edit: Note the |
Here's the diff with the preliminary fix, use it with a grain of salt because I wasn't sure whether we can actually use diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 70eaf4f9c..654c16e4a 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -10,6 +10,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <filesystem>
#include <future>
#include <iostream>
#include <mutex>
@@ -1690,13 +1691,17 @@ void setStackSize(size_t stackSize)
#endif
}
+#if __linux__
static AutoCloseFD fdSavedMountNamespace;
+std::optional<std::filesystem::path> savedCwd;
+#endif
void saveMountNamespace()
{
#if __linux__
static std::once_flag done;
std::call_once(done, []() {
+ savedCwd.emplace(std::filesystem::current_path());
AutoCloseFD fd = open("/proc/self/ns/mnt", O_RDONLY);
if (!fd)
throw SysError("saving parent mount namespace");
@@ -1714,6 +1719,12 @@ void restoreMountNamespace()
} catch (Error & e) {
debug(e.msg());
}
+ try {
+ if (savedCwd)
+ std::filesystem::current_path(*savedCwd);
+ } catch (std::filesystem::filesystem_error const &e) {
+ debug(e.what());
+ }
#endif
}
|
I've opened #6348 with your patch (and also my follow-up patch which removes the |
Describe the bug
Running
nix-shell
ornix develop
ornix shell
as root drops you into/
instead of staying in the current directory.Steps To Reproduce
nix shell
examplenix-shell
examplenix develop
exampleExpected behavior
Drops you into a shell in the current directory.
Additional context
nix (Nix) 2.7.0pre20220210_5b809f9
First noticed on 52f5231.
We worked around it for now using
env -C "$PWD"
.The text was updated successfully, but these errors were encountered: