Skip to content

Commit 26c5803

Browse files
committed
macOS compilation fixes
You need an `extern` dance to access `environ`, and apparently `execvpe` doesn't exist on macOS :(
1 parent 4996d89 commit 26c5803

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/nix/run.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <queue>
2222

23+
extern char ** environ __attribute__((weak));
24+
2325
namespace nix::fs { using namespace std::filesystem; }
2426

2527
using namespace nix;
@@ -88,9 +90,11 @@ void execProgramInStore(ref<Store> store,
8890
linux::setPersonality(*system);
8991
#endif
9092

91-
if (useLookupPath == UseLookupPath::Use)
92-
execvpe(program.c_str(), stringsToCharPtrs(args).data(), envp);
93-
else
93+
if (useLookupPath == UseLookupPath::Use) {
94+
// We have to set `environ` by hand because there is no `execvpe` on macOS.
95+
environ = envp;
96+
execvp(program.c_str(), stringsToCharPtrs(args).data());
97+
} else
9498
execve(program.c_str(), stringsToCharPtrs(args).data(), envp);
9599

96100
throw SysError("unable to execute '%s'", program);

0 commit comments

Comments
 (0)