aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstore/globals.cc31
-rw-r--r--src/libstore/globals.hh1
2 files changed, 32 insertions, 0 deletions
diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc
index 5a4cb1824..9c25d9868 100644
--- a/src/libstore/globals.cc
+++ b/src/libstore/globals.cc
@@ -24,6 +24,9 @@
#include "config-impl.hh"
+#ifdef __APPLE__
+#include <sys/sysctl.h>
+#endif
namespace nix {
@@ -154,6 +157,29 @@ unsigned int Settings::getDefaultCores()
return concurrency;
}
+#if __APPLE__
+static bool hasVirt() {
+
+ int hasVMM;
+ int hvSupport;
+ size_t size;
+
+ size = sizeof(hasVMM);
+ if (sysctlbyname("kern.hv_vmm_present", &hasVMM, &size, NULL, 0) == 0) {
+ if (hasVMM)
+ return false;
+ }
+
+ // whether the kernel and hardware supports virt
+ size = sizeof(hvSupport);
+ if (sysctlbyname("kern.hv_support", &hvSupport, &size, NULL, 0) == 0) {
+ return hvSupport == 1;
+ } else {
+ return false;
+ }
+}
+#endif
+
StringSet Settings::getDefaultSystemFeatures()
{
/* For backwards compatibility, accept some "features" that are
@@ -170,6 +196,11 @@ StringSet Settings::getDefaultSystemFeatures()
features.insert("kvm");
#endif
+ #if __APPLE__
+ if (hasVirt())
+ features.insert("apple-virt");
+ #endif
+
return features;
}
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index cf10edebd..dba7d78ef 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -708,6 +708,7 @@ public:
`kvm` feature.
This setting by default includes `kvm` if `/dev/kvm` is accessible,
+ `apple-virt` if hardware virtualization is available on macOS,
and the pseudo-features `nixos-test`, `benchmark` and `big-parallel`
that are used in Nixpkgs to route builds to specific machines.
)", {}, false};