From 30e327f99c5d1c20ddf09147c5873147fbb2568a Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Mon, 11 Nov 2024 22:20:49 +0100 Subject: [PATCH] module: add rosetta2 garbage collection service Provides a service to prune the Rosetta 2 JIT bytecode cache. --- modules/module-list.nix | 1 + modules/virtualisation/rosetta/gc.nix | 60 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 modules/virtualisation/rosetta/gc.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 3725c7ee..57dc7112 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -109,4 +109,5 @@ ./programs/zsh ./homebrew.nix ./users + ./virtualisation/rosetta/gc.nix ] diff --git a/modules/virtualisation/rosetta/gc.nix b/modules/virtualisation/rosetta/gc.nix new file mode 100644 index 00000000..b40d5a1f --- /dev/null +++ b/modules/virtualisation/rosetta/gc.nix @@ -0,0 +1,60 @@ +{ + config, + lib, + ... +}: + +let + inherit (lib) + mkEnableOption + mkIf + mkOption + ; + + launchdTypes = import ../../launchd/types.nix { inherit config lib; }; + + logFile = "/var/log/rosetta-gc.log"; + + cfg = config.virtualisation.rosetta.gc; +in + +{ + options.virtualisation.rosetta.gc = { + enable = mkEnableOption "Rosetta 2 JIT cache garbage collection"; + + interval = mkOption { + type = launchdTypes.StartCalendarInterval; + default = [ + { + Weekday = 6; + Hour = 3; + Minute = 15; + } + ]; + description = '' + The calendar interval at which the garbage collector will run. + See the {option}`serviceConfig.StartCalendarInterval` option of + the {option}`launchd` module for more info. + ''; + }; + }; + + config = mkIf cfg.enable { + launchd.daemons.rosetta-gc = { + script = '' + /System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -P -minsize 0 /System/Volumes/Data 2>&1| sed -e "s/^/$(date)| /" + ''; + serviceConfig = { + RunAtLoad = true; + StartCalendarInterval = cfg.interval; + StandardErrorPath = logFile; + StandardOutPath = logFile; + }; + }; + + environment.etc."newsyslog.d/rosetta-gc.conf".text = '' + # logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] + ${logFile} 640 10 * $W0 NJ + ''; + }; +}