forked from lix-project/lix
Merge pull request #6709 from edolstra/fix-static-build-hook
Fix build-remote in nix-static
This commit is contained in:
commit
eafa2721ca
|
@ -7,6 +7,22 @@ HookInstance::HookInstance()
|
||||||
{
|
{
|
||||||
debug("starting build hook '%s'", settings.buildHook);
|
debug("starting build hook '%s'", settings.buildHook);
|
||||||
|
|
||||||
|
auto buildHookArgs = tokenizeString<std::list<std::string>>(settings.buildHook.get());
|
||||||
|
|
||||||
|
if (buildHookArgs.empty())
|
||||||
|
throw Error("'build-hook' setting is empty");
|
||||||
|
|
||||||
|
auto buildHook = buildHookArgs.front();
|
||||||
|
buildHookArgs.pop_front();
|
||||||
|
|
||||||
|
Strings args;
|
||||||
|
|
||||||
|
for (auto & arg : buildHookArgs)
|
||||||
|
args.push_back(arg);
|
||||||
|
|
||||||
|
args.push_back(std::string(baseNameOf(settings.buildHook.get())));
|
||||||
|
args.push_back(std::to_string(verbosity));
|
||||||
|
|
||||||
/* Create a pipe to get the output of the child. */
|
/* Create a pipe to get the output of the child. */
|
||||||
fromHook.create();
|
fromHook.create();
|
||||||
|
|
||||||
|
@ -36,14 +52,9 @@ HookInstance::HookInstance()
|
||||||
if (dup2(builderOut.readSide.get(), 5) == -1)
|
if (dup2(builderOut.readSide.get(), 5) == -1)
|
||||||
throw SysError("dupping builder's stdout/stderr");
|
throw SysError("dupping builder's stdout/stderr");
|
||||||
|
|
||||||
Strings args = {
|
execv(buildHook.c_str(), stringsToCharPtrs(args).data());
|
||||||
std::string(baseNameOf(settings.buildHook.get())),
|
|
||||||
std::to_string(verbosity),
|
|
||||||
};
|
|
||||||
|
|
||||||
execv(settings.buildHook.get().c_str(), stringsToCharPtrs(args).data());
|
throw SysError("executing '%s'", buildHook);
|
||||||
|
|
||||||
throw SysError("executing '%s'", settings.buildHook);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pid.setSeparatePG(true);
|
pid.setSeparatePG(true);
|
||||||
|
|
|
@ -36,7 +36,6 @@ Settings::Settings()
|
||||||
, nixStateDir(canonPath(getEnv("NIX_STATE_DIR").value_or(NIX_STATE_DIR)))
|
, nixStateDir(canonPath(getEnv("NIX_STATE_DIR").value_or(NIX_STATE_DIR)))
|
||||||
, nixConfDir(canonPath(getEnv("NIX_CONF_DIR").value_or(NIX_CONF_DIR)))
|
, nixConfDir(canonPath(getEnv("NIX_CONF_DIR").value_or(NIX_CONF_DIR)))
|
||||||
, nixUserConfFiles(getUserConfigFiles())
|
, nixUserConfFiles(getUserConfigFiles())
|
||||||
, nixLibexecDir(canonPath(getEnv("NIX_LIBEXEC_DIR").value_or(NIX_LIBEXEC_DIR)))
|
|
||||||
, nixBinDir(canonPath(getEnv("NIX_BIN_DIR").value_or(NIX_BIN_DIR)))
|
, nixBinDir(canonPath(getEnv("NIX_BIN_DIR").value_or(NIX_BIN_DIR)))
|
||||||
, nixManDir(canonPath(NIX_MAN_DIR))
|
, nixManDir(canonPath(NIX_MAN_DIR))
|
||||||
, nixDaemonSocketFile(canonPath(getEnv("NIX_DAEMON_SOCKET_PATH").value_or(nixStateDir + DEFAULT_SOCKET_PATH)))
|
, nixDaemonSocketFile(canonPath(getEnv("NIX_DAEMON_SOCKET_PATH").value_or(nixStateDir + DEFAULT_SOCKET_PATH)))
|
||||||
|
@ -67,12 +66,13 @@ Settings::Settings()
|
||||||
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL);
|
sandboxPaths = tokenizeString<StringSet>("/bin/sh=" SANDBOX_SHELL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* chroot-like behavior from Apple's sandbox */
|
||||||
/* chroot-like behavior from Apple's sandbox */
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
sandboxPaths = tokenizeString<StringSet>("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib");
|
sandboxPaths = tokenizeString<StringSet>("/System/Library/Frameworks /System/Library/PrivateFrameworks /bin/sh /bin/bash /private/tmp /private/var/tmp /usr/lib");
|
||||||
allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh");
|
allowedImpureHostPrefixes = tokenizeString<StringSet>("/System/Library /usr/lib /dev /bin/sh");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
buildHook = getSelfExe().value_or("nix") + " __build-remote";
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadConfFile()
|
void loadConfFile()
|
||||||
|
|
|
@ -79,9 +79,6 @@ public:
|
||||||
/* A list of user configuration files to load. */
|
/* A list of user configuration files to load. */
|
||||||
std::vector<Path> nixUserConfFiles;
|
std::vector<Path> nixUserConfFiles;
|
||||||
|
|
||||||
/* The directory where internal helper programs are stored. */
|
|
||||||
Path nixLibexecDir;
|
|
||||||
|
|
||||||
/* The directory where the main programs are stored. */
|
/* The directory where the main programs are stored. */
|
||||||
Path nixBinDir;
|
Path nixBinDir;
|
||||||
|
|
||||||
|
@ -195,7 +192,7 @@ public:
|
||||||
)",
|
)",
|
||||||
{"build-timeout"}};
|
{"build-timeout"}};
|
||||||
|
|
||||||
PathSetting buildHook{this, true, nixLibexecDir + "/nix/build-remote", "build-hook",
|
PathSetting buildHook{this, true, "", "build-hook",
|
||||||
"The path of the helper program that executes builds to remote machines."};
|
"The path of the helper program that executes builds to remote machines."};
|
||||||
|
|
||||||
Setting<std::string> builders{
|
Setting<std::string> builders{
|
||||||
|
|
|
@ -39,7 +39,6 @@ libstore_CXXFLAGS += \
|
||||||
-DNIX_STATE_DIR=\"$(localstatedir)/nix\" \
|
-DNIX_STATE_DIR=\"$(localstatedir)/nix\" \
|
||||||
-DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
|
-DNIX_LOG_DIR=\"$(localstatedir)/log/nix\" \
|
||||||
-DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \
|
-DNIX_CONF_DIR=\"$(sysconfdir)/nix\" \
|
||||||
-DNIX_LIBEXEC_DIR=\"$(libexecdir)\" \
|
|
||||||
-DNIX_BIN_DIR=\"$(bindir)\" \
|
-DNIX_BIN_DIR=\"$(bindir)\" \
|
||||||
-DNIX_MAN_DIR=\"$(mandir)\" \
|
-DNIX_MAN_DIR=\"$(mandir)\" \
|
||||||
-DLSOF=\"$(lsof)\"
|
-DLSOF=\"$(lsof)\"
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
@ -633,6 +634,27 @@ Path getDataDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::optional<Path> getSelfExe()
|
||||||
|
{
|
||||||
|
static auto cached = []() -> std::optional<Path>
|
||||||
|
{
|
||||||
|
#if __linux__
|
||||||
|
return readLink("/proc/self/exe");
|
||||||
|
#elif __APPLE__
|
||||||
|
char buf[1024];
|
||||||
|
uint32_t size = sizeof(buf);
|
||||||
|
if (_NSGetExecutablePath(buf, &size) == 0)
|
||||||
|
return buf;
|
||||||
|
else
|
||||||
|
return std::nullopt;
|
||||||
|
#else
|
||||||
|
return std::nullopt;
|
||||||
|
#endif
|
||||||
|
}();
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Paths createDirs(const Path & path)
|
Paths createDirs(const Path & path)
|
||||||
{
|
{
|
||||||
Paths created;
|
Paths created;
|
||||||
|
|
|
@ -149,10 +149,14 @@ std::vector<Path> getConfigDirs();
|
||||||
/* Return $XDG_DATA_HOME or $HOME/.local/share. */
|
/* Return $XDG_DATA_HOME or $HOME/.local/share. */
|
||||||
Path getDataDir();
|
Path getDataDir();
|
||||||
|
|
||||||
|
/* Return the path of the current executable. */
|
||||||
|
std::optional<Path> getSelfExe();
|
||||||
|
|
||||||
/* Create a directory and all its parents, if necessary. Returns the
|
/* Create a directory and all its parents, if necessary. Returns the
|
||||||
list of created directories, in order of creation. */
|
list of created directories, in order of creation. */
|
||||||
Paths createDirs(const Path & path);
|
Paths createDirs(const Path & path);
|
||||||
inline Paths createDirs(PathView path) {
|
inline Paths createDirs(PathView path)
|
||||||
|
{
|
||||||
return createDirs(Path(path));
|
return createDirs(Path(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,6 +266,11 @@ void mainWrapped(int argc, char * * argv)
|
||||||
programPath = argv[0];
|
programPath = argv[0];
|
||||||
auto programName = std::string(baseNameOf(programPath));
|
auto programName = std::string(baseNameOf(programPath));
|
||||||
|
|
||||||
|
if (argc > 0 && std::string_view(argv[0]) == "__build-remote") {
|
||||||
|
programName = "build-remote";
|
||||||
|
argv++; argc--;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto legacy = (*RegisterLegacyCommand::commands)[programName];
|
auto legacy = (*RegisterLegacyCommand::commands)[programName];
|
||||||
if (legacy) return legacy(argc, argv);
|
if (legacy) return legacy(argc, argv);
|
||||||
|
|
|
@ -47,7 +47,7 @@ void runProgramInStore(ref<Store> store,
|
||||||
Strings helperArgs = { chrootHelperName, store->storeDir, store2->getRealStoreDir(), program };
|
Strings helperArgs = { chrootHelperName, store->storeDir, store2->getRealStoreDir(), program };
|
||||||
for (auto & arg : args) helperArgs.push_back(arg);
|
for (auto & arg : args) helperArgs.push_back(arg);
|
||||||
|
|
||||||
execv(readLink("/proc/self/exe").c_str(), stringsToCharPtrs(helperArgs).data());
|
execv(getSelfExe().value_or("nix").c_str(), stringsToCharPtrs(helperArgs).data());
|
||||||
|
|
||||||
throw SysError("could not execute chroot helper");
|
throw SysError("could not execute chroot helper");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue