forked from lix-project/lix
Fix build on macOS
This commit is contained in:
parent
2fde7e0108
commit
05d258667d
|
@ -659,7 +659,7 @@ void LocalDerivationGoal::startBuilder()
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (useUidRange)
|
if (parsedDrv->useUidRange())
|
||||||
throw Error("feature 'uid-range' is not supported on this platform");
|
throw Error("feature 'uid-range' is not supported on this platform");
|
||||||
if (useSystemdCgroup)
|
if (useSystemdCgroup)
|
||||||
throw Error("feature 'systemd-cgroup' is not supported on this platform");
|
throw Error("feature 'systemd-cgroup' is not supported on this platform");
|
||||||
|
|
|
@ -46,7 +46,13 @@ struct PluginFilesSetting : public BaseSetting<Paths>
|
||||||
void set(const std::string & str, bool append = false) override;
|
void set(const std::string & str, bool append = false) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32_t maxIdsPerBuild = 1 << 16;
|
const uint32_t maxIdsPerBuild =
|
||||||
|
#if __linux__
|
||||||
|
1 << 16
|
||||||
|
#else
|
||||||
|
1
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
class Settings : public Config {
|
class Settings : public Config {
|
||||||
|
|
||||||
|
@ -277,16 +283,26 @@ public:
|
||||||
multi-user settings with untrusted users.
|
multi-user settings with untrusted users.
|
||||||
)"};
|
)"};
|
||||||
|
|
||||||
#if __linux__
|
|
||||||
Setting<bool> autoAllocateUids{this, false, "auto-allocate-uids",
|
Setting<bool> autoAllocateUids{this, false, "auto-allocate-uids",
|
||||||
"Whether to allocate UIDs for builders automatically."};
|
"Whether to allocate UIDs for builders automatically."};
|
||||||
|
|
||||||
Setting<uint32_t> startId{this, 872415232, "start-id",
|
Setting<uint32_t> startId{this,
|
||||||
|
#if __linux__
|
||||||
|
872415232,
|
||||||
|
#else
|
||||||
|
56930,
|
||||||
|
#endif
|
||||||
|
"start-id",
|
||||||
"The first UID and GID to use for dynamic ID allocation."};
|
"The first UID and GID to use for dynamic ID allocation."};
|
||||||
|
|
||||||
Setting<uint32_t> uidCount{this, maxIdsPerBuild * 128, "id-count",
|
Setting<uint32_t> uidCount{this,
|
||||||
|
#if __linux__
|
||||||
|
maxIdsPerBuild * 128,
|
||||||
|
#else
|
||||||
|
128,
|
||||||
|
#endif
|
||||||
|
"id-count",
|
||||||
"The number of UIDs/GIDs to use for dynamic ID allocation."};
|
"The number of UIDs/GIDs to use for dynamic ID allocation."};
|
||||||
#endif
|
|
||||||
|
|
||||||
Setting<bool> impersonateLinux26{this, false, "impersonate-linux-26",
|
Setting<bool> impersonateLinux26{this, false, "impersonate-linux-26",
|
||||||
"Whether to impersonate a Linux 2.6 machine on newer kernels.",
|
"Whether to impersonate a Linux 2.6 machine on newer kernels.",
|
||||||
|
|
|
@ -122,15 +122,16 @@ struct AutoUserLock : UserLock
|
||||||
|
|
||||||
~AutoUserLock()
|
~AutoUserLock()
|
||||||
{
|
{
|
||||||
|
#if __linux__
|
||||||
// Get rid of our cgroup, ignoring errors.
|
// Get rid of our cgroup, ignoring errors.
|
||||||
if (cgroup) rmdir(cgroup->c_str());
|
if (cgroup) rmdir(cgroup->c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void kill() override
|
void kill() override
|
||||||
{
|
{
|
||||||
#if __linux__
|
#if __linux__
|
||||||
if (cgroup) {
|
if (cgroup) {
|
||||||
printError("KILL CGROUP %s", *cgroup);
|
|
||||||
destroyCgroup(*cgroup);
|
destroyCgroup(*cgroup);
|
||||||
if (mkdir(cgroup->c_str(), 0755) == -1)
|
if (mkdir(cgroup->c_str(), 0755) == -1)
|
||||||
throw SysError("creating cgroup '%s'", *cgroup);
|
throw SysError("creating cgroup '%s'", *cgroup);
|
||||||
|
@ -138,7 +139,6 @@ struct AutoUserLock : UserLock
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
assert(firstUid);
|
assert(firstUid);
|
||||||
printError("KILL USER %d", firstUid);
|
|
||||||
killUser(firstUid);
|
killUser(firstUid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,7 @@ struct AutoUserLock : UserLock
|
||||||
lock->firstUid = settings.startId + i * maxIdsPerBuild;
|
lock->firstUid = settings.startId + i * maxIdsPerBuild;
|
||||||
lock->nrIds = nrIds;
|
lock->nrIds = nrIds;
|
||||||
|
|
||||||
|
#if __linux__
|
||||||
if (nrIds > 1) {
|
if (nrIds > 1) {
|
||||||
auto ourCgroups = getCgroups("/proc/self/cgroup");
|
auto ourCgroups = getCgroups("/proc/self/cgroup");
|
||||||
auto ourCgroup = ourCgroups[""];
|
auto ourCgroup = ourCgroups[""];
|
||||||
|
@ -209,20 +210,17 @@ struct AutoUserLock : UserLock
|
||||||
|
|
||||||
auto ourCgroupPath = canonPath("/sys/fs/cgroup/" + ourCgroup);
|
auto ourCgroupPath = canonPath("/sys/fs/cgroup/" + ourCgroup);
|
||||||
|
|
||||||
printError("PARENT CGROUP = %s", ourCgroupPath);
|
|
||||||
|
|
||||||
if (!pathExists(ourCgroupPath))
|
if (!pathExists(ourCgroupPath))
|
||||||
throw Error("expected cgroup directory '%s'", ourCgroupPath);
|
throw Error("expected cgroup directory '%s'", ourCgroupPath);
|
||||||
|
|
||||||
lock->cgroup = fmt("%s/nix-build-%d", ourCgroupPath, lock->firstUid);
|
lock->cgroup = fmt("%s/nix-build-%d", ourCgroupPath, lock->firstUid);
|
||||||
|
|
||||||
printError("CHILD CGROUP = %s", *lock->cgroup);
|
|
||||||
|
|
||||||
/* Record the cgroup in the lock file. This ensures that
|
/* Record the cgroup in the lock file. This ensures that
|
||||||
if we subsequently get executed under a different parent
|
if we subsequently get executed under a different parent
|
||||||
cgroup, we kill the previous cgroup first. */
|
cgroup, we kill the previous cgroup first. */
|
||||||
writeFull(lock->fdUserLock.get(), *lock->cgroup);
|
writeFull(lock->fdUserLock.get(), *lock->cgroup);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return lock;
|
return lock;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
struct UserLock
|
struct UserLock
|
||||||
|
|
Loading…
Reference in a new issue