1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-06 16:57:08 +00:00
nix-darwin/modules/services/nix-gc/default.nix

77 lines
2.1 KiB
Nix
Raw Normal View History

# 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;
launchdTypes = import ../../launchd/types.nix { inherit config lib; };
2017-07-17 21:42:27 +02:00
in
{
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.")
];
###### interface
2017-07-17 21:42:27 +02:00
options = {
nix.gc = {
automatic = mkOption {
default = false;
type = types.bool;
2024-04-14 23:02:32 +02:00
description = "Automatically run the garbage collector at a specific time.";
};
# Not in NixOS module
user = mkOption {
type = types.nullOr types.str;
default = null;
2024-04-14 23:02:32 +02:00
description = "User that runs the garbage collector.";
};
interval = mkOption {
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.
'';
};
options = mkOption {
default = "";
example = "--max-freed $((64 * 1024**3))";
type = types.str;
2024-04-14 23:02:32 +02:00
description = ''
Options given to {file}`nix-collect-garbage` when the
garbage collector is run automatically.
'';
};
2017-07-17 21:42:27 +02:00
};
2017-07-17 21:42:27 +02: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}";
environment.NIX_REMOTE = optionalString config.nix.useDaemon "daemon";
2017-07-17 21:42:27 +02:00
serviceConfig.RunAtLoad = false;
serviceConfig.StartCalendarInterval = cfg.interval;
serviceConfig.UserName = cfg.user;
2017-07-17 21:42:27 +02:00
};
};
}