mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-29 17:16:15 +02:00
libstore: Add apple-virt to system features when available
I'm sure that we'll adjust the implementation over time, but this at least discerns between an apple silicon bare metal machine and a tart VM.
This commit is contained in:
parent
9bc7b4f463
commit
9277eb276b
3 changed files with 37 additions and 0 deletions
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
- Introduce new flake installable syntax `flakeref#.attrPath` where the "." prefix denotes no searching of default attribute prefixes like `packages.<SYSTEM>` or `legacyPackages.<SYSTEM>`.
|
- Introduce new flake installable syntax `flakeref#.attrPath` where the "." prefix denotes no searching of default attribute prefixes like `packages.<SYSTEM>` or `legacyPackages.<SYSTEM>`.
|
||||||
|
|
||||||
|
- Nix adds `apple-virt` to the default system features on macOS systems that support virtualization. This is similar to what's done for the `kvm` system feature on Linux hosts.
|
||||||
|
|
||||||
- Introduce a new built-in function [`builtins.convertHash`](@docroot@/language/builtins.md#builtins-convertHash).
|
- Introduce a new built-in function [`builtins.convertHash`](@docroot@/language/builtins.md#builtins-convertHash).
|
||||||
|
|
||||||
- `builtins.fetchTree` is now marked as stable.
|
- `builtins.fetchTree` is now marked as stable.
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
|
|
||||||
#include "config-impl.hh"
|
#include "config-impl.hh"
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -154,6 +157,29 @@ unsigned int Settings::getDefaultCores()
|
||||||
return concurrency;
|
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()
|
StringSet Settings::getDefaultSystemFeatures()
|
||||||
{
|
{
|
||||||
/* For backwards compatibility, accept some "features" that are
|
/* For backwards compatibility, accept some "features" that are
|
||||||
|
@ -170,6 +196,11 @@ StringSet Settings::getDefaultSystemFeatures()
|
||||||
features.insert("kvm");
|
features.insert("kvm");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __APPLE__
|
||||||
|
if (hasVirt())
|
||||||
|
features.insert("apple-virt");
|
||||||
|
#endif
|
||||||
|
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -714,6 +714,10 @@ public:
|
||||||
|
|
||||||
System features are user-defined, but Nix sets the following defaults:
|
System features are user-defined, but Nix sets the following defaults:
|
||||||
|
|
||||||
|
- `apple-virt`
|
||||||
|
|
||||||
|
Included on darwin if virtualization is available.
|
||||||
|
|
||||||
- `kvm`
|
- `kvm`
|
||||||
|
|
||||||
Included by default if `/dev/kvm` is accessible.
|
Included by default if `/dev/kvm` is accessible.
|
||||||
|
|
Loading…
Reference in a new issue