Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libstore: Add apple-virt to system features when available #9187

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.

- 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).

- `builtins.fetchTree` is now marked as stable.
31 changes: 31 additions & 0 deletions src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

#include "config-impl.hh"

#ifdef __APPLE__
#include <sys/sysctl.h>
#endif

namespace nix {

Expand Down Expand Up @@ -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
Expand All @@ -170,6 +196,11 @@ StringSet Settings::getDefaultSystemFeatures()
features.insert("kvm");
#endif

#if __APPLE__
if (hasVirt())
features.insert("apple-virt");
#endif

return features;
}

Expand Down
6 changes: 5 additions & 1 deletion src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,13 @@ public:

System features are user-defined, but Nix sets the following defaults:

- `apple-virt`

Included on darwin if virtualization is available.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Included on darwin if virtualization is available.
Included on Darwin if virtualization is available.


- `kvm`

Included by default if `/dev/kvm` is accessible.
Included on Linux if `/dev/kvm` is accessible.

- `nixos-test`, `benchmark`, `big-parallel`

Expand Down
Loading