Personal Nix setup
at main 1.1 kB view raw
1{ lib, config, helpers, ... }: 2 3with lib; 4let 5 cfg = config.modules.vram; 6in helpers.darwinAttrs { 7 options.modules.vram = { 8 wiredLimit = mkOption { 9 default = null; 10 description = "Wired Memory Limit in GBs"; 11 type = types.nullOr (types.ints.between 2 512); 12 }; 13 14 wiredLowWatermark = mkOption { 15 default = null; 16 description = "Wired LWM (Low Watermark) in GBs"; 17 type = types.nullOr (types.ints.between 2 512); 18 }; 19 }; 20 21 config = mkIf (cfg.wiredLimit != null || cfg.wiredLowWatermark != null) { 22 system.activationScripts.postActivation.text = let 23 setWiredLimitMb = optionalString (cfg.wiredLimit != null) '' 24 wired_memsize_mb=$(($(sysctl -n hw.memsize) / 1024 / 1024)) 25 sysctl -w iogpu.wired_limit_mb="$((wired_memsize_mb - ${toString (cfg.wiredLimit * 1024)}))" 26 ''; 27 setWiredLowWaterMarkMb = optionalString (cfg.wiredLowWatermark != null) '' 28 sysctl -w iogpu.wired_lwm_mb="$((${toString (cfg.wiredLowWatermark * 1024)}))" 29 ''; 30 in '' 31 ${setWiredLimitMb} 32 ${setWiredLowWaterMarkMb} 33 ''; 34 }; 35} 36