Skip to content

Commit

Permalink
module: add rosetta2-gc
Browse files Browse the repository at this point in the history
Provides a service to prune the Rosetta 2 JIT bytecode cache.
  • Loading branch information
mweinelt committed Nov 12, 2024
1 parent 5c74ab8 commit 378e9ce
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
./services/postgresql
./services/privoxy
./services/redis
./services/rosetta2-gc
./services/sketchybar
./services/skhd
./services/spacebar
Expand Down
61 changes: 61 additions & 0 deletions modules/services/rosetta2-gc/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
config,
lib,
...
}:

let
inherit (lib)
mkEnableOption
mkIf
mkOption
;

launchdTypes = import ../../launchd/types.nix { inherit config lib; };

logFile = "/var/log/rosetta2-gc.log";

cfg = config.rosetta2-gc;
in

{
options.rosetta2-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.rosetta2-gc = {
script = ''
date
/System/Library/Filesystems/apfs.fs/Contents/Resources/apfs.util -P -minsize 0 /System/Volumes/Data
'';
serviceConfig = {
RunAtLoad = true;
StartCalendarInterval = cfg.interval;
StandardErrorPath = logFile;
StandardOutPath = logFile;
};
};

environment.etc."newsyslog.d/rosetta2-gc.conf".text = ''
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
${logFile} 640 10 * $W0 NJ
'';
};
}

0 comments on commit 378e9ce

Please sign in to comment.