-
Notifications
You must be signed in to change notification settings - Fork 0
/
relocatable.patch
78 lines (67 loc) · 2.73 KB
/
relocatable.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 0531aad9f..3c4cbb1d9 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -23,6 +23,29 @@ namespace nix {
must be deleted and recreated on startup.) */
#define DEFAULT_SOCKET_PATH "/daemon-socket/socket"
+static const std::string SELF{canonPath(readLink("/proc/self/exe"))};
+
+#undef NIX_PREFIX
+#undef NIX_DATA_DIR
+#undef NIX_LIBEXEC_DIR
+#undef NIX_BIN_DIR
+#undef NIX_MAN_DIR
+#undef SANDBOX_SHELL
+
+static const std::string NIX_PREFIX{canonPath(dirOf(dirOf(SELF)))};
+static const std::string NIX_DATA_DIR{NIX_PREFIX + "/share"};
+static const std::string NIX_LIBEXEC_DIR{NIX_PREFIX + "/libexec"};
+static const std::string NIX_BIN_DIR{NIX_PREFIX + "/bin"};
+static const std::string NIX_MAN_DIR{NIX_PREFIX + "/share/man"};
+static const std::string SANDBOX_SHELL{NIX_PREFIX + "/libexec/nix/bash"};
+
+#define NIX_PREFIX (NIX_PREFIX)
+#define NIX_DATA_DIR (NIX_DATA_DIR)
+#define NIX_LIBEXEC_DIR (NIX_LIBEXEC_DIR)
+#define NIX_BIN_DIR (NIX_BIN_DIR)
+#define NIX_MAN_DIR (NIX_MAN_DIR)
+#define SANDBOX_SHELL (SANDBOX_SHELL)
+
Settings settings;
static GlobalConfig::Register rSettings(&settings);
@@ -63,7 +86,7 @@ Settings::Settings()
}
#if defined(__linux__) && defined(SANDBOX_SHELL)
- sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL);
+ sandboxPaths = tokenizeString<StringSet>("/bin/sh=" + std::string(SANDBOX_SHELL));
#endif
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 89f7b58f8..36e49e572 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -39,6 +39,14 @@ extern char * * environ __attribute__((weak));
namespace nix {
+#undef NIX_PREFIX
+#undef NIX_LIBEXEC_DIR
+static const std::string SELF{canonPath(readLink("/proc/self/exe"))};
+static const std::string NIX_PREFIX{canonPath(dirOf(dirOf(SELF)))};
+static const std::string NIX_LIBEXEC_DIR{NIX_PREFIX + "/libexec"};
+#define NIX_PREFIX (NIX_PREFIX)
+#define NIX_LIBEXEC_DIR (NIX_LIBEXEC_DIR)
+
std::optional<std::string> getEnv(const std::string & key)
{
@@ -1111,10 +1119,14 @@ void runProgram2(const RunOptions & options)
restoreSignals();
- if (options.searchPath)
+ if (options.searchPath){
+ auto unixPath = tokenizeString<Strings>(getEnv("PATH").value_or(""),":");
+ unixPath.push_front(std::string(NIX_LIBEXEC_DIR) + "/nix");
+ setenv("PATH", concatStringsSep(":", unixPath).c_str(), 1);
execvp(options.program.c_str(), stringsToCharPtrs(args_).data());
// This allows you to refer to a program with a pathname relative
// to the PATH variable.
+ }
else
execv(options.program.c_str(), stringsToCharPtrs(args_).data());