2022-08-14 14:44:59 -07:00
|
|
|
# Based off: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/services/misc/nix-gc.nix
|
|
|
|
# When making changes please try to keep it in sync.
|
|
|
|
{ config, lib, ... }:
|
2017-07-17 21:42:27 +02:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.nix.gc;
|
2023-06-29 00:50:28 -07:00
|
|
|
launchdTypes = import ../../launchd/types.nix { inherit config lib; };
|
2017-07-17 21:42:27 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2022-08-14 14:57:12 -07:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "nix" "gc" "dates" ] "Use `nix.gc.interval` instead.")
|
2022-10-12 08:38:06 -04:00
|
|
|
(mkRemovedOptionModule [ "nix" "gc" "randomizedDelaySec" ] "No `nix-darwin` equivalent to this NixOS option.")
|
|
|
|
(mkRemovedOptionModule [ "nix" "gc" "persistent" ] "No `nix-darwin` equivalent to this NixOS option.")
|
2022-08-14 14:57:12 -07:00
|
|
|
];
|
2022-08-14 14:44:59 -07:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
2017-07-17 21:42:27 +02:00
|
|
|
options = {
|
|
|
|
|
2022-08-14 14:44:59 -07:00
|
|
|
nix.gc = {
|
2019-01-02 20:19:23 +01:00
|
|
|
|
2022-08-14 14:44:59 -07:00
|
|
|
automatic = mkOption {
|
|
|
|
default = false;
|
2022-08-14 14:57:12 -07:00
|
|
|
type = types.bool;
|
2024-04-14 23:02:32 +02:00
|
|
|
description = "Automatically run the garbage collector at a specific time.";
|
2022-08-14 14:44:59 -07:00
|
|
|
};
|
|
|
|
|
2022-08-14 14:57:12 -07:00
|
|
|
# Not in NixOS module
|
2022-08-14 14:44:59 -07:00
|
|
|
user = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2024-04-14 23:02:32 +02:00
|
|
|
description = "User that runs the garbage collector.";
|
2022-08-14 14:44:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
interval = mkOption {
|
2023-06-29 00:50:28 -07:00
|
|
|
type = launchdTypes.StartCalendarInterval;
|
|
|
|
default = [{ Weekday = 7; 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.
|
|
|
|
'';
|
2022-08-14 14:44:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
options = mkOption {
|
|
|
|
default = "";
|
|
|
|
example = "--max-freed $((64 * 1024**3))";
|
2022-08-14 14:57:12 -07:00
|
|
|
type = types.str;
|
2024-04-14 23:02:32 +02:00
|
|
|
description = ''
|
2023-06-22 12:21:32 +01:00
|
|
|
Options given to {file}`nix-collect-garbage` when the
|
2022-08-14 14:44:59 -07:00
|
|
|
garbage collector is run automatically.
|
|
|
|
'';
|
|
|
|
};
|
2017-07-17 21:42:27 +02:00
|
|
|
|
|
|
|
};
|
2022-08-14 14:44:59 -07:00
|
|
|
|
2017-07-17 21:42:27 +02:00
|
|
|
};
|
|
|
|
|
2022-08-14 14:44:59 -07:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2017-07-17 21:42:27 +02:00
|
|
|
config = mkIf cfg.automatic {
|
|
|
|
|
|
|
|
launchd.daemons.nix-gc = {
|
|
|
|
command = "${config.nix.package}/bin/nix-collect-garbage ${cfg.options}";
|
2019-07-01 21:14:14 +02:00
|
|
|
environment.NIX_REMOTE = optionalString config.nix.useDaemon "daemon";
|
2017-07-17 21:42:27 +02:00
|
|
|
serviceConfig.RunAtLoad = false;
|
2023-06-29 00:50:28 -07:00
|
|
|
serviceConfig.StartCalendarInterval = cfg.interval;
|
2019-01-02 20:19:23 +01:00
|
|
|
serviceConfig.UserName = cfg.user;
|
2017-07-17 21:42:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|