From 70f99a5e185ee61609a5c64fbbc87916a42e9909 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 25 Jun 2025 14:36:16 +0100 Subject: [PATCH] Add macos-vram helpers --- machines/irnbru/configuration.nix | 4 ++++ modules/base/default.nix | 1 + modules/base/macos-vram.nix | 36 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 modules/base/macos-vram.nix diff --git a/machines/irnbru/configuration.nix b/machines/irnbru/configuration.nix index c7cc6f5..1f1f28a 100644 --- a/machines/irnbru/configuration.nix +++ b/machines/irnbru/configuration.nix @@ -4,6 +4,10 @@ imports = [ ]; modules = { + vram = { + wiredLimit = 8; + wiredLowWatermark = 20; + }; server = { enable = true; sshd.enable = true; diff --git a/modules/base/default.nix b/modules/base/default.nix index 2825c01..a067035 100644 --- a/modules/base/default.nix +++ b/modules/base/default.nix @@ -7,5 +7,6 @@ ./shell.nix ./linux.nix ./macos.nix + ./macos-vram.nix ]; } diff --git a/modules/base/macos-vram.nix b/modules/base/macos-vram.nix new file mode 100644 index 0000000..362b46b --- /dev/null +++ b/modules/base/macos-vram.nix @@ -0,0 +1,36 @@ +{ lib, config, helpers, ... }: + +with lib; +let + cfg = config.modules.vram; +in helpers.darwinAttrs { + options.modules.vram = { + wiredLimit = mkOption { + default = null; + description = "Wired Memory Limit in GBs"; + type = types.nullOr (types.ints.between 2 512); + }; + + wiredLowWatermark = mkOption { + default = null; + description = "Wired LWM (Low Watermark) in GBs"; + type = types.nullOr (types.ints.between 2 512); + }; + }; + + config = mkIf (cfg.wiredLimit != null || cfg.wiredLowWatermark != null) { + system.activationScripts.postActivation.text = let + setWiredLimitMb = optionalString (cfg.wiredLimit != null) '' + wired_memsize_mb=$(($(sysctl -n hw.memsize) / 1024 / 1024)) + sysctl -w iogpu.wired_limit_mb="$((wired_memsize_mb - ${toString (cfg.wiredLimit * 1024)}))" + ''; + setWiredLowWaterMarkMb = optionalString (cfg.wiredLowWatermark != null) '' + sysctl -w iogpu.wired_lwm_mb="$((${toString (cfg.wiredLowWatermark * 1024)}))" + ''; + in '' + ${setWiredLimitMb} + ${setWiredLowWaterMarkMb} + ''; + }; +} + -- 2.51.2