1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 06:01:48 +02:00

Tagging release 2.28.1

-----BEGIN PGP SIGNATURE-----
 
 iQFHBAABCAAxFiEEtUHVUwEnDgvPFcpdgXC0cm1xmN4FAmfzku8THGVkb2xzdHJh
 QGdtYWlsLmNvbQAKCRCBcLRybXGY3ngWB/0e5vMSgZtARQXjuyexyJyy2m8JIQzJ
 Stw7dP0/oAvWYWuytez3jX4KC9xztMELblgZzXQhO72wIfzpa/CmxWQXVSaHm6Kq
 zYAWhxXz2HKGEPd8bS6eCFCZcrmChso7UN2WjrROYwB+1HO5S1rtOJtv2K1zvy5C
 xRMoOpSfKVfn63FoODhenW3UWbfeck5Dmb6eirPxvIMUIcDi2FeX5MVlklgNhxum
 351/Ymo5dxyK1pGmm8NrvB/3RSk7rVRUR+R4257lCmrN0g4gvM0G4MvxGm+XHMmC
 d/tmeU+JKPiXKFDSWmuTCmwCenu/q95QRadKST+Wls+qc4gHQLCaXfgn
 =hcKx
 -----END PGP SIGNATURE-----

Merge tag '2.28.1' into sync-2.28.0

Tagging release 2.28.1
This commit is contained in:
Eelco Dolstra 2025-04-07 11:21:07 +02:00
commit 59d1634aab
41 changed files with 208 additions and 208 deletions

View file

@ -1 +1 @@
2.28.0 2.28.1

View file

@ -10,6 +10,7 @@ add_project_arguments(
'-Werror=suggest-override', '-Werror=suggest-override',
'-Werror=switch', '-Werror=switch',
'-Werror=switch-enum', '-Werror=switch-enum',
'-Werror=undef',
'-Werror=unused-result', '-Werror=unused-result',
'-Wignored-qualifiers', '-Wignored-qualifiers',
'-Wimplicit-fallthrough', '-Wimplicit-fallthrough',

View file

@ -5,7 +5,7 @@
#include <memory> #include <memory>
#include <tuple> #include <tuple>
#include <iomanip> #include <iomanip>
#if __APPLE__ #ifdef __APPLE__
#include <sys/time.h> #include <sys/time.h>
#endif #endif
@ -225,7 +225,7 @@ static int main_build_remote(int argc, char * * argv)
break; break;
} }
#if __APPLE__ #ifdef __APPLE__
futimes(bestSlotLock.get(), NULL); futimes(bestSlotLock.get(), NULL);
#else #else
futimens(bestSlotLock.get(), NULL); futimens(bestSlotLock.get(), NULL);

View file

@ -14,7 +14,7 @@ int main (int argc, char **argv) {
// Disable build hook. We won't be testing remote builds in these unit tests. If we do, fix the above build hook. // Disable build hook. We won't be testing remote builds in these unit tests. If we do, fix the above build hook.
settings.buildHook = {}; settings.buildHook = {};
#if __linux__ // should match the conditional around sandboxBuildDir declaration. #ifdef __linux__ // should match the conditional around sandboxBuildDir declaration.
// When building and testing nix within the host's Nix sandbox, our store dir will be located in the host's sandboxBuildDir, e.g.: // When building and testing nix within the host's Nix sandbox, our store dir will be located in the host's sandboxBuildDir, e.g.:
// Host // Host
@ -27,7 +27,7 @@ int main (int argc, char **argv) {
settings.sandboxBuildDir = "/test-build-dir-instead-of-usual-build-dir"; settings.sandboxBuildDir = "/test-build-dir-instead-of-usual-build-dir";
#endif #endif
#if __APPLE__ #ifdef __APPLE__
// Avoid this error, when already running in a sandbox: // Avoid this error, when already running in a sandbox:
// sandbox-exec: sandbox_apply: Operation not permitted // sandbox-exec: sandbox_apply: Operation not permitted
settings.sandboxMode = smDisabled; settings.sandboxMode = smDisabled;

View file

@ -10,7 +10,7 @@
#if NIX_USE_BOEHMGC #if NIX_USE_BOEHMGC
# include <pthread.h> # include <pthread.h>
# if __FreeBSD__ # ifdef __FreeBSD__
# include <pthread_np.h> # include <pthread_np.h>
# endif # endif

View file

@ -108,8 +108,13 @@ LockFile::LockFile(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
std::string_view contents, std::string_view path) std::string_view contents, std::string_view path)
{ {
auto json = nlohmann::json::parse(contents); auto json = [=] {
try {
return nlohmann::json::parse(contents);
} catch (const nlohmann::json::parse_error & e) {
throw Error("Could not parse '%s': %s", path, e.what());
}
}();
auto version = json.value("version", 0); auto version = json.value("version", 0);
if (version < 5 || version > 7) if (version < 5 || version > 7)
throw Error("lock file '%s' has unsupported version %d", path, version); throw Error("lock file '%s' has unsupported version %d", path, version);

View file

@ -21,6 +21,10 @@ deps_private_maybe_subproject = [
deps_public_maybe_subproject = [ deps_public_maybe_subproject = [
dependency('nix-util'), dependency('nix-util'),
dependency('nix-store'), dependency('nix-store'),
# FIXME: This is only here for the NIX_USE_BOEHMGC macro dependency
# Removing nix-expr will make the build more concurrent and is
# architecturally nice, perhaps.
dependency('nix-expr'),
] ]
subdir('nix-meson-build-support/subprojects') subdir('nix-meson-build-support/subprojects')

View file

@ -6,6 +6,7 @@
nix-util, nix-util,
nix-store, nix-store,
nix-expr,
# Configuration Options # Configuration Options
@ -33,6 +34,10 @@ mkMesonLibrary (finalAttrs: {
]; ];
propagatedBuildInputs = [ propagatedBuildInputs = [
# FIXME: This is only here for the NIX_USE_BOEHMGC macro dependency
# Removing nix-expr will make the build more concurrent and is
# architecturally nice, perhaps.
nix-expr
nix-util nix-util
nix-store nix-store
openssl openssl

View file

@ -26,7 +26,7 @@
#include "nix/util/strings.hh" #include "nix/util/strings.hh"
#include "main-config-private.hh" #include "main-config-private.hh"
#include "nix/expr/config.hh"
namespace nix { namespace nix {
@ -144,7 +144,7 @@ void initNix(bool loadConfig)
if (sigaction(SIGUSR1, &act, 0)) throw SysError("handling SIGUSR1"); if (sigaction(SIGUSR1, &act, 0)) throw SysError("handling SIGUSR1");
#endif #endif
#if __APPLE__ #ifdef __APPLE__
/* HACK: on darwin, we need cant use sigprocmask with SIGWINCH. /* HACK: on darwin, we need cant use sigprocmask with SIGWINCH.
* Instead, add a dummy sigaction handler, and signalHandlerThread * Instead, add a dummy sigaction handler, and signalHandlerThread
* can handle the rest. */ * can handle the rest. */

View file

@ -40,6 +40,8 @@ deps_private += gtest
configdata = configuration_data() configdata = configuration_data()
configdata.set_quoted('PACKAGE_VERSION', meson.project_version()) configdata.set_quoted('PACKAGE_VERSION', meson.project_version())
configdata.set_quoted('NIX_STORE_DIR', nix_store.get_variable('storedir'))
config_priv_h = configure_file( config_priv_h = configure_file(
configuration : configdata, configuration : configdata,
output : 'store-tests-config.hh', output : 'store-tests-config.hh',
@ -89,7 +91,6 @@ this_exe = executable(
include_directories : include_dirs, include_directories : include_dirs,
# TODO: -lrapidcheck, see ../libutil-support/build.meson # TODO: -lrapidcheck, see ../libutil-support/build.meson
link_args: linker_export_flags + ['-lrapidcheck'], link_args: linker_export_flags + ['-lrapidcheck'],
cpp_args : [ '-DNIX_STORE_DIR="' + nix_store.get_variable('storedir') + '"' ],
# get main from gtest # get main from gtest
install : true, install : true,
) )

View file

@ -1,9 +1,9 @@
#if ENABLE_S3 #include "nix/store/s3-binary-cache-store.hh"
#if NIX_WITH_S3_SUPPORT
# include <gtest/gtest.h> # include <gtest/gtest.h>
# include "nix/store/s3-binary-cache-store.hh"
namespace nix { namespace nix {
TEST(S3BinaryCacheStore, constructConfig) TEST(S3BinaryCacheStore, constructConfig)

View file

@ -8,11 +8,12 @@
#include "nix/util/callback.hh" #include "nix/util/callback.hh"
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#if ENABLE_S3 #include "store-config-private.hh"
#if NIX_WITH_S3_SUPPORT
#include <aws/core/client/ClientConfiguration.h> #include <aws/core/client/ClientConfiguration.h>
#endif #endif
#if __linux__ #ifdef __linux__
# include "nix/util/namespaces.hh" # include "nix/util/namespaces.hh"
#endif #endif
@ -623,7 +624,7 @@ struct curlFileTransfer : public FileTransfer
}); });
#endif #endif
#if __linux__ #ifdef __linux__
try { try {
tryUnshareFilesystem(); tryUnshareFilesystem();
} catch (nix::Error & e) { } catch (nix::Error & e) {
@ -757,7 +758,7 @@ struct curlFileTransfer : public FileTransfer
#endif #endif
} }
#if ENABLE_S3 #if NIX_WITH_S3_SUPPORT
std::tuple<std::string, std::string, Store::Params> parseS3Uri(std::string uri) std::tuple<std::string, std::string, Store::Params> parseS3Uri(std::string uri)
{ {
auto [path, params] = splitUriAndParams(uri); auto [path, params] = splitUriAndParams(uri);
@ -780,7 +781,7 @@ struct curlFileTransfer : public FileTransfer
if (hasPrefix(request.uri, "s3://")) { if (hasPrefix(request.uri, "s3://")) {
// FIXME: do this on a worker thread // FIXME: do this on a worker thread
try { try {
#if ENABLE_S3 #if NIX_WITH_S3_SUPPORT
auto [bucketName, key, params] = parseS3Uri(request.uri); auto [bucketName, key, params] = parseS3Uri(request.uri);
std::string profile = getOr(params, "profile", ""); std::string profile = getOr(params, "profile", "");

View file

@ -335,7 +335,7 @@ static std::string quoteRegexChars(const std::string & raw)
return std::regex_replace(raw, specialRegex, R"(\$&)"); return std::regex_replace(raw, specialRegex, R"(\$&)");
} }
#if __linux__ #ifdef __linux__
static void readFileRoots(const std::filesystem::path & path, UncheckedRoots & roots) static void readFileRoots(const std::filesystem::path & path, UncheckedRoots & roots)
{ {
try { try {
@ -427,7 +427,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
} }
#endif #endif
#if __linux__ #ifdef __linux__
readFileRoots("/proc/sys/kernel/modprobe", unchecked); readFileRoots("/proc/sys/kernel/modprobe", unchecked);
readFileRoots("/proc/sys/kernel/fbsplash", unchecked); readFileRoots("/proc/sys/kernel/fbsplash", unchecked);
readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked); readFileRoots("/proc/sys/kernel/poweroff_cmd", unchecked);

View file

@ -25,7 +25,7 @@
# include <dlfcn.h> # include <dlfcn.h>
#endif #endif
#if __APPLE__ #ifdef __APPLE__
# include "nix/util/processes.hh" # include "nix/util/processes.hh"
#endif #endif
@ -90,7 +90,7 @@ Settings::Settings()
#endif #endif
/* chroot-like behavior from Apple's sandbox */ /* chroot-like behavior from Apple's sandbox */
#if __APPLE__ #ifdef __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
@ -151,7 +151,7 @@ unsigned int Settings::getDefaultCores()
return concurrency; return concurrency;
} }
#if __APPLE__ #ifdef __APPLE__
static bool hasVirt() { static bool hasVirt() {
int hasVMM; int hasVMM;
@ -181,16 +181,16 @@ StringSet Settings::getDefaultSystemFeatures()
actually require anything special on the machines. */ actually require anything special on the machines. */
StringSet features{"nixos-test", "benchmark", "big-parallel"}; StringSet features{"nixos-test", "benchmark", "big-parallel"};
#if __linux__ #ifdef __linux__
features.insert("uid-range"); features.insert("uid-range");
#endif #endif
#if __linux__ #ifdef __linux__
if (access("/dev/kvm", R_OK | W_OK) == 0) if (access("/dev/kvm", R_OK | W_OK) == 0)
features.insert("kvm"); features.insert("kvm");
#endif #endif
#if __APPLE__ #ifdef __APPLE__
if (hasVirt()) if (hasVirt())
features.insert("apple-virt"); features.insert("apple-virt");
#endif #endif
@ -205,11 +205,11 @@ StringSet Settings::getDefaultExtraPlatforms()
if (std::string{NIX_LOCAL_SYSTEM} == "x86_64-linux" && !isWSL1()) if (std::string{NIX_LOCAL_SYSTEM} == "x86_64-linux" && !isWSL1())
extraPlatforms.insert("i686-linux"); extraPlatforms.insert("i686-linux");
#if __linux__ #ifdef __linux__
StringSet levels = computeLevels(); StringSet levels = computeLevels();
for (auto iter = levels.begin(); iter != levels.end(); ++iter) for (auto iter = levels.begin(); iter != levels.end(); ++iter)
extraPlatforms.insert(*iter + "-linux"); extraPlatforms.insert(*iter + "-linux");
#elif __APPLE__ #elif defined(__APPLE__)
// Rosetta 2 emulation layer can run x86_64 binaries on aarch64 // Rosetta 2 emulation layer can run x86_64 binaries on aarch64
// machines. Note that we cant force processes from executing // machines. Note that we cant force processes from executing
// x86_64 in aarch64 environments or vice versa since they can // x86_64 in aarch64 environments or vice versa since they can
@ -224,7 +224,7 @@ StringSet Settings::getDefaultExtraPlatforms()
bool Settings::isWSL1() bool Settings::isWSL1()
{ {
#if __linux__ #ifdef __linux__
struct utsname utsbuf; struct utsname utsbuf;
uname(&utsbuf); uname(&utsbuf);
// WSL1 uses -Microsoft suffix // WSL1 uses -Microsoft suffix
@ -376,7 +376,7 @@ void initLibStore(bool loadConfig) {
[1] https://github.com/apple-oss-distributions/objc4/blob/01edf1705fbc3ff78a423cd21e03dfc21eb4d780/runtime/objc-initialize.mm#L614-L636 [1] https://github.com/apple-oss-distributions/objc4/blob/01edf1705fbc3ff78a423cd21e03dfc21eb4d780/runtime/objc-initialize.mm#L614-L636
*/ */
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
#if __APPLE__ #ifdef __APPLE__
/* On macOS, don't use the per-session TMPDIR (as set e.g. by /* On macOS, don't use the per-session TMPDIR (as set e.g. by
sshd). This breaks build users because they don't have access sshd). This breaks build users because they don't have access
to the TMPDIR, in particular in nix-store --serve. */ to the TMPDIR, in particular in nix-store --serve. */

View file

@ -34,7 +34,7 @@ struct MaxBuildJobsSetting : public BaseSetting<unsigned int>
}; };
const uint32_t maxIdsPerBuild = const uint32_t maxIdsPerBuild =
#if __linux__ #ifdef __linux__
1 << 16 1 << 16
#else #else
1 1
@ -467,7 +467,7 @@ public:
)", {}, true, Xp::AutoAllocateUids}; )", {}, true, Xp::AutoAllocateUids};
Setting<uint32_t> startId{this, Setting<uint32_t> startId{this,
#if __linux__ #ifdef __linux__
0x34000000, 0x34000000,
#else #else
56930, 56930,
@ -476,7 +476,7 @@ public:
"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, Setting<uint32_t> uidCount{this,
#if __linux__ #ifdef __linux__
maxIdsPerBuild * 128, maxIdsPerBuild * 128,
#else #else
128, 128,
@ -484,7 +484,7 @@ public:
"id-count", "id-count",
"The number of UIDs/GIDs to use for dynamic ID allocation."}; "The number of UIDs/GIDs to use for dynamic ID allocation."};
#if __linux__ #ifdef __linux__
Setting<bool> useCgroups{ Setting<bool> useCgroups{
this, false, "use-cgroups", this, false, "use-cgroups",
R"( R"(
@ -596,7 +596,7 @@ public:
Setting<SandboxMode> sandboxMode{ Setting<SandboxMode> sandboxMode{
this, this,
#if __linux__ #ifdef __linux__
smEnabled smEnabled
#else #else
smDisabled smDisabled
@ -671,7 +671,7 @@ public:
)"}; )"};
#endif #endif
#if __linux__ #ifdef __linux__
Setting<std::string> sandboxShmSize{ Setting<std::string> sandboxShmSize{
this, "50%", "sandbox-dev-shm-size", this, "50%", "sandbox-dev-shm-size",
R"( R"(
@ -708,7 +708,7 @@ public:
Setting<PathSet> allowedImpureHostPrefixes{this, {}, "allowed-impure-host-deps", Setting<PathSet> allowedImpureHostPrefixes{this, {}, "allowed-impure-host-deps",
"Which prefixes to allow derivations to ask for access to (primarily for Darwin)."}; "Which prefixes to allow derivations to ask for access to (primarily for Darwin)."};
#if __APPLE__ #ifdef __APPLE__
Setting<bool> darwinLogSandboxViolations{this, false, "darwin-log-sandbox-violations", Setting<bool> darwinLogSandboxViolations{this, false, "darwin-log-sandbox-violations",
"Whether to log Darwin sandbox access violations to the system log."}; "Whether to log Darwin sandbox access violations to the system log."};
#endif #endif
@ -1066,7 +1066,7 @@ public:
// Don't document the machine-specific default value // Don't document the machine-specific default value
false}; false};
#if __linux__ #ifdef __linux__
Setting<bool> filterSyscalls{ Setting<bool> filterSyscalls{
this, true, "filter-syscalls", this, true, "filter-syscalls",
R"( R"(

View file

@ -1,9 +1,13 @@
#pragma once #pragma once
///@file ///@file
#include "nix/store/binary-cache-store.hh" #include "nix/store/config.hh"
#include <atomic> #if NIX_WITH_S3_SUPPORT
# include "nix/store/binary-cache-store.hh"
# include <atomic>
namespace nix { namespace nix {
@ -125,3 +129,5 @@ public:
}; };
} }
#endif

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
///@file ///@file
#include "store-config-private.hh"
#if ENABLE_S3 #if NIX_WITH_S3_SUPPORT
#include "nix/util/ref.hh" #include "nix/util/ref.hh"

View file

@ -38,7 +38,7 @@
# include <grp.h> # include <grp.h>
#endif #endif
#if __linux__ #ifdef __linux__
# include <sched.h> # include <sched.h>
# include <sys/statvfs.h> # include <sys/statvfs.h>
# include <sys/mount.h> # include <sys/mount.h>
@ -575,7 +575,7 @@ void LocalStore::upgradeDBSchema(State & state)
bind mount. So make the Nix store writable for this process. */ bind mount. So make the Nix store writable for this process. */
void LocalStore::makeStoreWritable() void LocalStore::makeStoreWritable()
{ {
#if __linux__ #ifdef __linux__
if (!isRootUser()) return; if (!isRootUser()) return;
/* Check if /nix/store is on a read-only mount. */ /* Check if /nix/store is on a read-only mount. */
struct statvfs stat; struct statvfs stat;

View file

@ -130,7 +130,8 @@ deps_private += sqlite
# AWS C++ SDK has bad pkg-config. See # AWS C++ SDK has bad pkg-config. See
# https://github.com/aws/aws-sdk-cpp/issues/2673 for details. # https://github.com/aws/aws-sdk-cpp/issues/2673 for details.
aws_s3 = dependency('aws-cpp-sdk-s3', required : false) aws_s3 = dependency('aws-cpp-sdk-s3', required : false)
configdata_priv.set('ENABLE_S3', aws_s3.found().to_int()) # The S3 store definitions in the header will be hidden based on this variables.
configdata_pub.set('NIX_WITH_S3_SUPPORT', aws_s3.found().to_int())
if aws_s3.found() if aws_s3.found()
aws_s3 = declare_dependency( aws_s3 = declare_dependency(
include_directories: include_directories(aws_s3.get_variable('includedir')), include_directories: include_directories(aws_s3.get_variable('includedir')),
@ -157,12 +158,15 @@ endforeach
busybox = find_program(get_option('sandbox-shell'), required : false) busybox = find_program(get_option('sandbox-shell'), required : false)
configdata_priv.set('HAVE_EMBEDDED_SANDBOX_SHELL', get_option('embedded-sandbox-shell').to_int())
if get_option('embedded-sandbox-shell')
configdata_priv.set_quoted('SANDBOX_SHELL', '__embedded_sandbox_shell__')
elif busybox.found()
configdata_priv.set_quoted('SANDBOX_SHELL', busybox.full_path())
endif
if get_option('embedded-sandbox-shell') if get_option('embedded-sandbox-shell')
# This one goes in config.h
# The path to busybox is passed as a -D flag when compiling this_library.
# This solution is inherited from the old make buildsystem
# TODO: do this differently?
configdata_priv.set('HAVE_EMBEDDED_SANDBOX_SHELL', 1)
hexdump = find_program('hexdump', native : true) hexdump = find_program('hexdump', native : true)
embedded_sandbox_shell_gen = custom_target( embedded_sandbox_shell_gen = custom_target(
'embedded-sandbox-shell.gen.hh', 'embedded-sandbox-shell.gen.hh',
@ -180,6 +184,64 @@ if get_option('embedded-sandbox-shell')
generated_headers += embedded_sandbox_shell_gen generated_headers += embedded_sandbox_shell_gen
endif endif
prefix = get_option('prefix')
# For each of these paths, assume that it is relative to the prefix unless
# it is already an absolute path (which is the default for store-dir, localstatedir, and log-dir).
path_opts = [
# Meson built-ins.
'datadir',
'mandir',
'libdir',
'includedir',
'libexecdir',
# Homecooked Nix directories.
'store-dir',
'localstatedir',
'log-dir',
]
# For your grepping pleasure, this loop sets the following variables that aren't mentioned
# literally above:
# store_dir
# localstatedir
# log_dir
# profile_dir
foreach optname : path_opts
varname = optname.replace('-', '_')
path = get_option(optname)
if fs.is_absolute(path)
set_variable(varname, path)
else
set_variable(varname, prefix / path)
endif
endforeach
# sysconfdir doesn't get anything installed to directly, and is only used to
# tell Nix where to look for nix.conf, so it doesn't get appended to prefix.
sysconfdir = get_option('sysconfdir')
if not fs.is_absolute(sysconfdir)
sysconfdir = '/' / sysconfdir
endif
# Aside from prefix itself, each of these was made into an absolute path
# by joining it with prefix, unless it was already an absolute path
# (which is the default for store-dir, localstatedir, and log-dir).
configdata_priv.set_quoted('NIX_PREFIX', prefix)
configdata_priv.set_quoted('NIX_STORE_DIR', store_dir)
configdata_priv.set_quoted('NIX_DATA_DIR', datadir)
configdata_priv.set_quoted('NIX_STATE_DIR', localstatedir / 'nix')
configdata_priv.set_quoted('NIX_LOG_DIR', log_dir)
configdata_priv.set_quoted('NIX_CONF_DIR', sysconfdir / 'nix')
configdata_priv.set_quoted('NIX_MAN_DIR', mandir)
lsof = find_program('lsof', required : false)
configdata_priv.set_quoted(
'LSOF',
lsof.found()
? lsof.full_path()
# Just look up on the PATH
: 'lsof',
)
config_priv_h = configure_file( config_priv_h = configure_file(
configuration : configdata_priv, configuration : configdata_priv,
output : 'store-config-private.hh', output : 'store-config-private.hh',
@ -267,87 +329,6 @@ else
subdir('unix') subdir('unix')
endif endif
prefix = get_option('prefix')
# For each of these paths, assume that it is relative to the prefix unless
# it is already an absolute path (which is the default for store-dir, localstatedir, and log-dir).
path_opts = [
# Meson built-ins.
'datadir',
'mandir',
'libdir',
'includedir',
'libexecdir',
# Homecooked Nix directories.
'store-dir',
'localstatedir',
'log-dir',
]
# For your grepping pleasure, this loop sets the following variables that aren't mentioned
# literally above:
# store_dir
# localstatedir
# log_dir
# profile_dir
foreach optname : path_opts
varname = optname.replace('-', '_')
path = get_option(optname)
if fs.is_absolute(path)
set_variable(varname, path)
else
set_variable(varname, prefix / path)
endif
endforeach
# sysconfdir doesn't get anything installed to directly, and is only used to
# tell Nix where to look for nix.conf, so it doesn't get appended to prefix.
sysconfdir = get_option('sysconfdir')
if not fs.is_absolute(sysconfdir)
sysconfdir = '/' / sysconfdir
endif
lsof = find_program('lsof', required : false)
# Aside from prefix itself, each of these was made into an absolute path
# by joining it with prefix, unless it was already an absolute path
# (which is the default for store-dir, localstatedir, and log-dir).
cpp_str_defines = {
'NIX_PREFIX': prefix,
'NIX_STORE_DIR': store_dir,
'NIX_DATA_DIR': datadir,
'NIX_STATE_DIR': localstatedir / 'nix',
'NIX_LOG_DIR': log_dir,
'NIX_CONF_DIR': sysconfdir / 'nix',
'NIX_MAN_DIR': mandir,
}
if lsof.found()
lsof_path = lsof.full_path()
else
# Just look up on the PATH
lsof_path = 'lsof'
endif
cpp_str_defines += {
'LSOF': lsof_path
}
if get_option('embedded-sandbox-shell')
cpp_str_defines += {
'SANDBOX_SHELL': '__embedded_sandbox_shell__'
}
elif busybox.found()
cpp_str_defines += {
'SANDBOX_SHELL': busybox.full_path()
}
endif
cpp_args = []
foreach name, value : cpp_str_defines
cpp_args += [
'-D' + name + '=' + '"' + value + '"'
]
endforeach
subdir('nix-meson-build-support/export-all-symbols') subdir('nix-meson-build-support/export-all-symbols')
subdir('nix-meson-build-support/windows-version') subdir('nix-meson-build-support/windows-version')
@ -358,7 +339,6 @@ this_library = library(
config_priv_h, config_priv_h,
dependencies : deps_public + deps_private + deps_other, dependencies : deps_public + deps_private + deps_other,
include_directories : include_dirs, include_directories : include_dirs,
cpp_args : cpp_args,
link_args: linker_export_flags, link_args: linker_export_flags,
prelink : true, # For C++ static initializers prelink : true, # For C++ static initializers
install : true, install : true,

View file

@ -13,6 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <regex> #include <regex>
#include "store-config-private.hh"
namespace nix { namespace nix {
@ -96,7 +97,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
auto st = lstat(path); auto st = lstat(path);
#if __APPLE__ #ifdef __APPLE__
/* HFS/macOS has some undocumented security feature disabling hardlinking for /* HFS/macOS has some undocumented security feature disabling hardlinking for
special files within .app dirs. Known affected paths include special files within .app dirs. Known affected paths include
*.app/Contents/{PkgInfo,Resources/\*.lproj,_CodeSignature} and .DS_Store. *.app/Contents/{PkgInfo,Resources/\*.lproj,_CodeSignature} and .DS_Store.

View file

@ -58,7 +58,7 @@ static void canonicalisePathMetaData_(
{ {
checkInterrupt(); checkInterrupt();
#if __APPLE__ #ifdef __APPLE__
/* Remove flags, in particular UF_IMMUTABLE which would prevent /* Remove flags, in particular UF_IMMUTABLE which would prevent
the file from being garbage-collected. FIXME: Use the file from being garbage-collected. FIXME: Use
setattrlist() to remove other attributes as well. */ setattrlist() to remove other attributes as well. */

View file

@ -1,9 +1,10 @@
#if ENABLE_S3 #include "nix/store/s3-binary-cache-store.hh"
#if NIX_WITH_S3_SUPPORT
#include <assert.h> #include <assert.h>
#include "nix/store/s3.hh" #include "nix/store/s3.hh"
#include "nix/store/s3-binary-cache-store.hh"
#include "nix/store/nar-info.hh" #include "nix/store/nar-info.hh"
#include "nix/store/nar-info-disk-cache.hh" #include "nix/store/nar-info-disk-cache.hh"
#include "nix/store/globals.hh" #include "nix/store/globals.hh"

View file

@ -1300,7 +1300,7 @@ ref<Store> openStore(StoreReference && storeURI)
return std::make_shared<LocalStore>(params); return std::make_shared<LocalStore>(params);
else if (pathExists(settings.nixDaemonSocketFile)) else if (pathExists(settings.nixDaemonSocketFile))
return std::make_shared<UDSRemoteStore>(params); return std::make_shared<UDSRemoteStore>(params);
#if __linux__ #ifdef __linux__
else if (!pathExists(stateDir) else if (!pathExists(stateDir)
&& params.empty() && params.empty()
&& !isRootUser() && !isRootUser()

View file

@ -41,7 +41,7 @@
#endif #endif
/* Includes required for chroot support. */ /* Includes required for chroot support. */
#if __linux__ #ifdef __linux__
# include "nix/store/fchmodat2-compat.hh" # include "nix/store/fchmodat2-compat.hh"
# include <sys/ioctl.h> # include <sys/ioctl.h>
# include <net/if.h> # include <net/if.h>
@ -60,7 +60,7 @@
# include "nix/store/personality.hh" # include "nix/store/personality.hh"
#endif #endif
#if __APPLE__ #ifdef __APPLE__
#include <spawn.h> #include <spawn.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sandbox.h> #include <sandbox.h>
@ -76,6 +76,8 @@ extern "C" int sandbox_init_with_parameters(const char *profile, uint64_t flags,
#include "nix/util/strings.hh" #include "nix/util/strings.hh"
#include "nix/util/signals.hh" #include "nix/util/signals.hh"
#include "store-config-private.hh"
namespace nix { namespace nix {
void handleDiffHook( void handleDiffHook(
@ -127,7 +129,7 @@ LocalDerivationGoal::~LocalDerivationGoal()
inline bool LocalDerivationGoal::needsHashRewrite() inline bool LocalDerivationGoal::needsHashRewrite()
{ {
#if __linux__ #ifdef __linux__
return !useChroot; return !useChroot;
#else #else
/* Darwin requires hash rewriting even when sandboxing is enabled. */ /* Darwin requires hash rewriting even when sandboxing is enabled. */
@ -168,7 +170,7 @@ void LocalDerivationGoal::killChild()
void LocalDerivationGoal::killSandbox(bool getStats) void LocalDerivationGoal::killSandbox(bool getStats)
{ {
if (cgroup) { if (cgroup) {
#if __linux__ #ifdef __linux__
auto stats = destroyCgroup(*cgroup); auto stats = destroyCgroup(*cgroup);
if (getStats) { if (getStats) {
buildResult.cpuUser = stats.cpuUser; buildResult.cpuUser = stats.cpuUser;
@ -205,7 +207,7 @@ Goal::Co LocalDerivationGoal::tryLocalBuild()
if (drvOptions->noChroot) if (drvOptions->noChroot)
throw Error("derivation '%s' has '__noChroot' set, " throw Error("derivation '%s' has '__noChroot' set, "
"but that's not allowed when 'sandbox' is 'true'", worker.store.printStorePath(drvPath)); "but that's not allowed when 'sandbox' is 'true'", worker.store.printStorePath(drvPath));
#if __APPLE__ #ifdef __APPLE__
if (drvOptions->additionalSandboxProfile != "") if (drvOptions->additionalSandboxProfile != "")
throw Error("derivation '%s' specifies a sandbox profile, " throw Error("derivation '%s' specifies a sandbox profile, "
"but this is only allowed when 'sandbox' is 'relaxed'", worker.store.printStorePath(drvPath)); "but this is only allowed when 'sandbox' is 'relaxed'", worker.store.printStorePath(drvPath));
@ -220,14 +222,14 @@ Goal::Co LocalDerivationGoal::tryLocalBuild()
auto & localStore = getLocalStore(); auto & localStore = getLocalStore();
if (localStore.storeDir != localStore.realStoreDir.get()) { if (localStore.storeDir != localStore.realStoreDir.get()) {
#if __linux__ #ifdef __linux__
useChroot = true; useChroot = true;
#else #else
throw Error("building using a diverted store is not supported on this platform"); throw Error("building using a diverted store is not supported on this platform");
#endif #endif
} }
#if __linux__ #ifdef __linux__
if (useChroot) { if (useChroot) {
if (!mountAndPidNamespacesSupported()) { if (!mountAndPidNamespacesSupported()) {
if (!settings.sandboxFallback) if (!settings.sandboxFallback)
@ -403,7 +405,7 @@ void LocalDerivationGoal::cleanupPostOutputsRegisteredModeNonCheck()
cleanupPostOutputsRegisteredModeCheck(); cleanupPostOutputsRegisteredModeCheck();
} }
#if __linux__ #ifdef __linux__
static void doBind(const Path & source, const Path & target, bool optional = false) { static void doBind(const Path & source, const Path & target, bool optional = false) {
debug("bind mounting '%1%' to '%2%'", source, target); debug("bind mounting '%1%' to '%2%'", source, target);
@ -476,12 +478,12 @@ static void handleChildException(bool sendException)
void LocalDerivationGoal::startBuilder() void LocalDerivationGoal::startBuilder()
{ {
if ((buildUser && buildUser->getUIDCount() != 1) if ((buildUser && buildUser->getUIDCount() != 1)
#if __linux__ #ifdef __linux__
|| settings.useCgroups || settings.useCgroups
#endif #endif
) )
{ {
#if __linux__ #ifdef __linux__
experimentalFeatureSettings.require(Xp::Cgroups); experimentalFeatureSettings.require(Xp::Cgroups);
/* If we're running from the daemon, then this will return the /* If we're running from the daemon, then this will return the
@ -548,7 +550,7 @@ void LocalDerivationGoal::startBuilder()
/* Create a temporary directory where the build will take /* Create a temporary directory where the build will take
place. */ place. */
topTmpDir = createTempDir(settings.buildDir.get().value_or(""), "nix-build-" + std::string(drvPath.name()), false, false, 0700); topTmpDir = createTempDir(settings.buildDir.get().value_or(""), "nix-build-" + std::string(drvPath.name()), false, false, 0700);
#if __APPLE__ #ifdef __APPLE__
if (false) { if (false) {
#else #else
if (useChroot) { if (useChroot) {
@ -727,7 +729,7 @@ void LocalDerivationGoal::startBuilder()
pathsInChroot[i] = {i, true}; pathsInChroot[i] = {i, true};
} }
#if __linux__ #ifdef __linux__
/* Create a temporary directory in which we set up the chroot /* Create a temporary directory in which we set up the chroot
environment using bind-mounts. We put it in the Nix store environment using bind-mounts. We put it in the Nix store
so that the build outputs can be moved efficiently from the so that the build outputs can be moved efficiently from the
@ -826,7 +828,7 @@ void LocalDerivationGoal::startBuilder()
#else #else
if (drvOptions->useUidRange(*drv)) if (drvOptions->useUidRange(*drv))
throw Error("feature 'uid-range' is not supported on this platform"); throw Error("feature 'uid-range' is not supported on this platform");
#if __APPLE__ #ifdef __APPLE__
/* We don't really have any parent prep work to do (yet?) /* We don't really have any parent prep work to do (yet?)
All work happens in the child, instead. */ All work happens in the child, instead. */
#else #else
@ -906,7 +908,7 @@ void LocalDerivationGoal::startBuilder()
if (chown(slaveName.c_str(), buildUser->getUID(), 0)) if (chown(slaveName.c_str(), buildUser->getUID(), 0))
throw SysError("changing owner of pseudoterminal slave"); throw SysError("changing owner of pseudoterminal slave");
} }
#if __APPLE__ #ifdef __APPLE__
else { else {
if (grantpt(builderOut.get())) if (grantpt(builderOut.get()))
throw SysError("granting access to pseudoterminal slave"); throw SysError("granting access to pseudoterminal slave");
@ -941,7 +943,7 @@ void LocalDerivationGoal::startBuilder()
/* Fork a child to build the package. */ /* Fork a child to build the package. */
#if __linux__ #ifdef __linux__
if (useChroot) { if (useChroot) {
/* Set up private namespaces for the build: /* Set up private namespaces for the build:
@ -1141,7 +1143,7 @@ void LocalDerivationGoal::initTmpDir()
{ {
/* In a sandbox, for determinism, always use the same temporary /* In a sandbox, for determinism, always use the same temporary
directory. */ directory. */
#if __linux__ #ifdef __linux__
tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir; tmpDirInSandbox = useChroot ? settings.sandboxBuildDir : tmpDir;
#else #else
tmpDirInSandbox = tmpDir; tmpDirInSandbox = tmpDir;
@ -1644,7 +1646,7 @@ void LocalDerivationGoal::addDependency(const StorePath & path)
debug("materialising '%s' in the sandbox", worker.store.printStorePath(path)); debug("materialising '%s' in the sandbox", worker.store.printStorePath(path));
#if __linux__ #ifdef __linux__
Path source = worker.store.Store::toRealPath(path); Path source = worker.store.Store::toRealPath(path);
Path target = chrootRootDir + worker.store.printStorePath(path); Path target = chrootRootDir + worker.store.printStorePath(path);
@ -1694,7 +1696,7 @@ void LocalDerivationGoal::chownToBuilder(const Path & path)
void setupSeccomp() void setupSeccomp()
{ {
#if __linux__ #ifdef __linux__
if (!settings.filterSyscalls) return; if (!settings.filterSyscalls) return;
#if HAVE_SECCOMP #if HAVE_SECCOMP
scmp_filter_ctx ctx; scmp_filter_ctx ctx;
@ -1814,7 +1816,7 @@ void LocalDerivationGoal::runChild()
} catch (SystemError &) { } } catch (SystemError &) { }
} }
#if __linux__ #ifdef __linux__
if (useChroot) { if (useChroot) {
userNamespaceSync.writeSide = -1; userNamespaceSync.writeSide = -1;
@ -2048,7 +2050,7 @@ void LocalDerivationGoal::runChild()
/* Close all other file descriptors. */ /* Close all other file descriptors. */
unix::closeExtraFDs(); unix::closeExtraFDs();
#if __linux__ #ifdef __linux__
linux::setPersonality(drv->platform); linux::setPersonality(drv->platform);
#endif #endif
@ -2087,7 +2089,7 @@ void LocalDerivationGoal::runChild()
throw SysError("setuid failed"); throw SysError("setuid failed");
} }
#if __APPLE__ #ifdef __APPLE__
/* This has to appear before import statements. */ /* This has to appear before import statements. */
std::string sandboxProfile = "(version 1)\n"; std::string sandboxProfile = "(version 1)\n";
@ -2258,7 +2260,7 @@ void LocalDerivationGoal::runChild()
for (auto & i : drv->args) for (auto & i : drv->args)
args.push_back(rewriteStrings(i, inputRewrites)); args.push_back(rewriteStrings(i, inputRewrites));
#if __APPLE__ #ifdef __APPLE__
posix_spawnattr_t attrp; posix_spawnattr_t attrp;
if (posix_spawnattr_init(&attrp)) if (posix_spawnattr_init(&attrp))

View file

@ -10,7 +10,7 @@
namespace nix { namespace nix {
#if __linux__ #ifdef __linux__
static std::vector<gid_t> get_group_list(const char *username, gid_t group_id) static std::vector<gid_t> get_group_list(const char *username, gid_t group_id)
{ {
@ -94,7 +94,7 @@ struct SimpleUserLock : UserLock
if (lock->uid == getuid() || lock->uid == geteuid()) if (lock->uid == getuid() || lock->uid == geteuid())
throw Error("the Nix user should not be a member of '%s'", settings.buildUsersGroup); throw Error("the Nix user should not be a member of '%s'", settings.buildUsersGroup);
#if __linux__ #ifdef __linux__
/* Get the list of supplementary groups of this user. This is /* Get the list of supplementary groups of this user. This is
* usually either empty or contains a group such as "kvm". */ * usually either empty or contains a group such as "kvm". */
@ -193,10 +193,10 @@ std::unique_ptr<UserLock> acquireUserLock(uid_t nrIds, bool useUserNamespace)
bool useBuildUsers() bool useBuildUsers()
{ {
#if __linux__ #ifdef __linux__
static bool b = (settings.buildUsersGroup != "" || settings.autoAllocateUids) && isRootUser(); static bool b = (settings.buildUsersGroup != "" || settings.autoAllocateUids) && isRootUser();
return b; return b;
#elif __APPLE__ #elif defined(__APPLE__)
static bool b = settings.buildUsersGroup != "" && isRootUser(); static bool b = settings.buildUsersGroup != "" && isRootUser();
return b; return b;
#else #else

View file

@ -17,7 +17,7 @@ namespace nix {
struct ArchiveSettings : Config struct ArchiveSettings : Config
{ {
Setting<bool> useCaseHack{this, Setting<bool> useCaseHack{this,
#if __APPLE__ #ifdef __APPLE__
true, true,
#else #else
false, false,

View file

@ -13,7 +13,7 @@
# include <mach-o/dyld.h> # include <mach-o/dyld.h>
#endif #endif
#if __linux__ #ifdef __linux__
# include <mutex> # include <mutex>
# include "nix/util/cgroup.hh" # include "nix/util/cgroup.hh"
# include "nix/util/namespaces.hh" # include "nix/util/namespaces.hh"
@ -23,7 +23,7 @@ namespace nix {
unsigned int getMaxCPU() unsigned int getMaxCPU()
{ {
#if __linux__ #ifdef __linux__
try { try {
auto cgroupFS = getCgroupFS(); auto cgroupFS = getCgroupFS();
if (!cgroupFS) return 0; if (!cgroupFS) return 0;
@ -82,7 +82,7 @@ void restoreProcessContext(bool restoreMounts)
unix::restoreSignals(); unix::restoreSignals();
#endif #endif
if (restoreMounts) { if (restoreMounts) {
#if __linux__ #ifdef __linux__
restoreMountNamespace(); restoreMountNamespace();
#endif #endif
} }
@ -106,9 +106,9 @@ std::optional<Path> getSelfExe()
{ {
static auto cached = []() -> std::optional<Path> static auto cached = []() -> std::optional<Path>
{ {
#if __linux__ || __GNU__ #if defined(__linux__) || defined(__GNU__)
return readLink("/proc/self/exe"); return readLink("/proc/self/exe");
#elif __APPLE__ #elif defined(__APPLE__)
char buf[1024]; char buf[1024];
uint32_t size = sizeof(buf); uint32_t size = sizeof(buf);
if (_NSGetExecutablePath(buf, &size) == 0) if (_NSGetExecutablePath(buf, &size) == 0)

View file

@ -98,7 +98,7 @@ void AutoCloseFD::fsync() const
result = result =
#ifdef _WIN32 #ifdef _WIN32
::FlushFileBuffers(fd) ::FlushFileBuffers(fd)
#elif __APPLE__ #elif defined(__APPLE__)
::fcntl(fd, F_FULLFSYNC) ::fcntl(fd, F_FULLFSYNC)
#else #else
::fsync(fd) ::fsync(fd)
@ -113,7 +113,7 @@ void AutoCloseFD::fsync() const
void AutoCloseFD::startFsync() const void AutoCloseFD::startFsync() const
{ {
#if __linux__ #ifdef __linux__
if (fd != -1) { if (fd != -1) {
/* Ignore failure, since fsync must be run later anyway. This is just a performance optimization. */ /* Ignore failure, since fsync must be run later anyway. This is just a performance optimization. */
::sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE); ::sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE);

View file

@ -574,7 +574,7 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix,
, mode , mode
#endif #endif
) == 0) { ) == 0) {
#if __FreeBSD__ #ifdef __FreeBSD__
/* Explicitly set the group of the directory. This is to /* Explicitly set the group of the directory. This is to
work around around problems caused by BSD's group work around around problems caused by BSD's group
ownership semantics (directories inherit the group of ownership semantics (directories inherit the group of

View file

@ -4,7 +4,7 @@
#include "nix/util/config-global.hh" #include "nix/util/config-global.hh"
#include "nix/util/fs-sink.hh" #include "nix/util/fs-sink.hh"
#if _WIN32 #ifdef _WIN32
# include <fileapi.h> # include <fileapi.h>
# include "nix/util/file-path.hh" # include "nix/util/file-path.hh"
# include "nix/util/windows-error.hh" # include "nix/util/windows-error.hh"

View file

@ -18,7 +18,7 @@ struct Source;
* Operating System capability * Operating System capability
*/ */
using Descriptor = using Descriptor =
#if _WIN32 #ifdef _WIN32
HANDLE HANDLE
#else #else
int int
@ -26,7 +26,7 @@ using Descriptor =
; ;
const Descriptor INVALID_DESCRIPTOR = const Descriptor INVALID_DESCRIPTOR =
#if _WIN32 #ifdef _WIN32
INVALID_HANDLE_VALUE INVALID_HANDLE_VALUE
#else #else
-1 -1

View file

@ -2,7 +2,7 @@
#include "nix/util/environment-variables.hh" #include "nix/util/environment-variables.hh"
#include "nix/util/sync.hh" #include "nix/util/sync.hh"
#if _WIN32 #ifdef _WIN32
# include <io.h> # include <io.h>
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <windows.h> # include <windows.h>

View file

@ -163,7 +163,7 @@ void Pipe::create()
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#if __linux__ || __FreeBSD__ #if defined(__linux__) || defined(__FreeBSD__)
static int unix_close_range(unsigned int first, unsigned int last, int flags) static int unix_close_range(unsigned int first, unsigned int last, int flags)
{ {
#if !HAVE_CLOSE_RANGE #if !HAVE_CLOSE_RANGE
@ -179,7 +179,7 @@ void unix::closeExtraFDs()
constexpr int MAX_KEPT_FD = 2; constexpr int MAX_KEPT_FD = 2;
static_assert(std::max({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) == MAX_KEPT_FD); static_assert(std::max({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO}) == MAX_KEPT_FD);
#if __linux__ || __FreeBSD__ #if defined(__linux__) || defined(__FreeBSD__)
// first try to close_range everything we don't care about. if this // first try to close_range everything we don't care about. if this
// returns an error with these parameters we're running on a kernel // returns an error with these parameters we're running on a kernel
// that does not implement close_range (i.e. pre 5.9) and fall back // that does not implement close_range (i.e. pre 5.9) and fall back
@ -189,7 +189,7 @@ void unix::closeExtraFDs()
} }
#endif #endif
#if __linux__ #ifdef __linux__
try { try {
for (auto & s : std::filesystem::directory_iterator{"/proc/self/fd"}) { for (auto & s : std::filesystem::directory_iterator{"/proc/self/fd"}) {
checkInterrupt(); checkInterrupt();

View file

@ -78,7 +78,7 @@ int Pid::kill()
/* On BSDs, killing a process group will return EPERM if all /* On BSDs, killing a process group will return EPERM if all
processes in the group are zombies (or something like processes in the group are zombies (or something like
that). So try to detect and ignore that situation. */ that). So try to detect and ignore that situation. */
#if __FreeBSD__ || __APPLE__ #if defined(__FreeBSD__) || defined(__APPLE__)
if (errno != EPERM || ::kill(pid, 0) != 0) if (errno != EPERM || ::kill(pid, 0) != 0)
#endif #endif
logError(SysError("killing process %d", pid).info()); logError(SysError("killing process %d", pid).info());
@ -190,7 +190,7 @@ static pid_t doFork(bool allowVfork, ChildWrapperFunction & fun)
} }
#if __linux__ #ifdef __linux__
static int childEntry(void * arg) static int childEntry(void * arg)
{ {
auto & fun = *reinterpret_cast<ChildWrapperFunction*>(arg); auto & fun = *reinterpret_cast<ChildWrapperFunction*>(arg);
@ -213,7 +213,7 @@ pid_t startProcess(std::function<void()> fun, const ProcessOptions & options)
logger = makeSimpleLogger(); logger = makeSimpleLogger();
} }
try { try {
#if __linux__ #ifdef __linux__
if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1) if (options.dieWithParent && prctl(PR_SET_PDEATHSIG, SIGKILL) == -1)
throw SysError("setting death signal"); throw SysError("setting death signal");
#endif #endif

View file

@ -105,7 +105,7 @@ void unix::setChildSignalMask(sigset_t * sigs)
{ {
assert(sigs); // C style function, but think of sigs as a reference assert(sigs); // C style function, but think of sigs as a reference
#if _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE #if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE) || (defined(_POSIX_SOURCE) && _POSIX_SOURCE)
sigemptyset(&savedSignalMask); sigemptyset(&savedSignalMask);
// There's no "assign" or "copy" function, so we rely on (math) idempotence // There's no "assign" or "copy" function, so we rely on (math) idempotence
// of the or operator: a or a = a. // of the or operator: a or a = a.

View file

@ -8,7 +8,7 @@
#include <sstream> #include <sstream>
// Darwin and FreeBSD stdenv do not define _GNU_SOURCE but do have _Unwind_Backtrace. // Darwin and FreeBSD stdenv do not define _GNU_SOURCE but do have _Unwind_Backtrace.
#if __APPLE__ || __FreeBSD__ #if defined(__APPLE__) || defined(__FreeBSD__)
# define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED # define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
#endif #endif

View file

@ -37,7 +37,7 @@
# include <netinet/in.h> # include <netinet/in.h>
#endif #endif
#if __linux__ #ifdef __linux__
# include "nix/util/namespaces.hh" # include "nix/util/namespaces.hh"
#endif #endif
@ -382,7 +382,7 @@ void mainWrapped(int argc, char * * argv)
"__build-remote", "__build-remote",
}); });
#if __linux__ #ifdef __linux__
if (isRootUser()) { if (isRootUser()) {
try { try {
saveMountNamespace(); saveMountNamespace();

View file

@ -1,4 +1,5 @@
#include "man-pages.hh" #include "man-pages.hh"
#include "cli-config-private.hh"
#include "nix/util/file-system.hh" #include "nix/util/file-system.hh"
#include "nix/util/current-process.hh" #include "nix/util/current-process.hh"
#include "nix/util/environment-variables.hh" #include "nix/util/environment-variables.hh"

View file

@ -39,13 +39,16 @@ configdata = configuration_data()
configdata.set_quoted('NIX_CLI_VERSION', meson.project_version()) configdata.set_quoted('NIX_CLI_VERSION', meson.project_version())
fs = import('fs') fs = import('fs')
prefix = get_option('prefix')
bindir = get_option('bindir') bindir = get_option('bindir')
if not fs.is_absolute(bindir) bindir = fs.is_absolute(bindir) ? bindir : prefix / bindir
bindir = get_option('prefix') / bindir
endif
configdata.set_quoted('NIX_BIN_DIR', bindir) configdata.set_quoted('NIX_BIN_DIR', bindir)
mandir = get_option('mandir')
mandir = fs.is_absolute(mandir) ? mandir : prefix / mandir
configdata.set_quoted('NIX_MAN_DIR', mandir)
config_priv_h = configure_file( config_priv_h = configure_file(
configuration : configdata, configuration : configdata,
output : 'cli-config-private.hh', output : 'cli-config-private.hh',
@ -174,16 +177,6 @@ if host_machine.system() != 'windows'
] ]
endif endif
fs = import('fs')
prefix = get_option('prefix')
mandir = get_option('mandir')
mandir = fs.is_absolute(mandir) ? mandir : prefix / mandir
cpp_args= [
'-DNIX_MAN_DIR="@0@"'.format(mandir)
]
include_dirs = [include_directories('.')] include_dirs = [include_directories('.')]
this_exe = executable( this_exe = executable(
@ -191,7 +184,6 @@ this_exe = executable(
sources, sources,
dependencies : deps_private_subproject + deps_private + deps_other, dependencies : deps_private_subproject + deps_private + deps_other,
include_directories : include_dirs, include_directories : include_dirs,
cpp_args : cpp_args,
link_args: linker_export_flags, link_args: linker_export_flags,
install : true, install : true,
) )

View file

@ -12,7 +12,7 @@
#include "nix/expr/eval.hh" #include "nix/expr/eval.hh"
#include <filesystem> #include <filesystem>
#if __linux__ #ifdef __linux__
# include <sys/mount.h> # include <sys/mount.h>
# include "nix/store/personality.hh" # include "nix/store/personality.hh"
#endif #endif
@ -59,7 +59,7 @@ void execProgramInStore(ref<Store> store,
throw SysError("could not execute chroot helper"); throw SysError("could not execute chroot helper");
} }
#if __linux__ #ifdef __linux__
if (system) if (system)
linux::setPersonality(*system); linux::setPersonality(*system);
#endif #endif
@ -153,7 +153,7 @@ void chrootHelper(int argc, char * * argv)
while (p < argc) while (p < argc)
args.push_back(argv[p++]); args.push_back(argv[p++]);
#if __linux__ #ifdef __linux__
uid_t uid = getuid(); uid_t uid = getuid();
uid_t gid = getgid(); uid_t gid = getgid();
@ -212,7 +212,7 @@ void chrootHelper(int argc, char * * argv)
writeFile(fs::path{"/proc/self/uid_map"}, fmt("%d %d %d", uid, uid, 1)); writeFile(fs::path{"/proc/self/uid_map"}, fmt("%d %d %d", uid, uid, 1));
writeFile(fs::path{"/proc/self/gid_map"}, fmt("%d %d %d", gid, gid, 1)); writeFile(fs::path{"/proc/self/gid_map"}, fmt("%d %d %d", gid, gid, 1));
#if __linux__ #ifdef __linux__
if (system != "") if (system != "")
linux::setPersonality(system); linux::setPersonality(system);
#endif #endif

View file

@ -34,11 +34,11 @@
#include <grp.h> #include <grp.h>
#include <fcntl.h> #include <fcntl.h>
#if __linux__ #ifdef __linux__
#include "nix/util/cgroup.hh" #include "nix/util/cgroup.hh"
#endif #endif
#if __APPLE__ || __FreeBSD__ #if defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/ucred.h> #include <sys/ucred.h>
#endif #endif
@ -317,7 +317,7 @@ static void daemonLoop(std::optional<TrustedFlag> forceTrustClientOpt)
// Get rid of children automatically; don't let them become zombies. // Get rid of children automatically; don't let them become zombies.
setSigChldAction(true); setSigChldAction(true);
#if __linux__ #ifdef __linux__
if (settings.useCgroups) { if (settings.useCgroups) {
experimentalFeatureSettings.require(Xp::Cgroups); experimentalFeatureSettings.require(Xp::Cgroups);