Add support for systemd timers
This commit is contained in:
parent
9c3a31ff4c
commit
7ad91f31d6
@ -11,36 +11,38 @@ in
|
||||
###### interface
|
||||
|
||||
options = {
|
||||
|
||||
nix.gc = {
|
||||
|
||||
automatic = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
description = "
|
||||
Automatically run the garbage collector at specified dates.
|
||||
";
|
||||
description = "Automatically run the garbage collector at a specific time.";
|
||||
};
|
||||
|
||||
dates = mkOption {
|
||||
default = "15 03 * * *";
|
||||
type = types.string;
|
||||
description = "
|
||||
Run the garbage collector at specified dates to avoid full
|
||||
hard-drives.
|
||||
";
|
||||
default = "00:43";
|
||||
type = types.uniq types.string;
|
||||
description = ''
|
||||
Specification (in the format described by
|
||||
<citerefentry><refentrytitle>systemd.time</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry>) of the time at
|
||||
which the garbage collector will run.
|
||||
'';
|
||||
};
|
||||
|
||||
options = mkOption {
|
||||
default = "";
|
||||
example = "--max-freed $((64 * 1024**3))";
|
||||
type = types.string;
|
||||
description = "
|
||||
type = types.uniq types.string;
|
||||
description = ''
|
||||
Options given to <filename>nix-collect-garbage</filename> when the
|
||||
garbage collector is run automatically.
|
||||
";
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -48,10 +50,11 @@ in
|
||||
|
||||
config = {
|
||||
|
||||
services.cron.systemCronJobs = mkIf cfg.automatic (singleton
|
||||
"${cfg.dates} root ${config.systemd.package}/bin/systemctl start nix-gc.service");
|
||||
#systemd.timers.nix-gc.enable = cfg.automatic;
|
||||
systemd.timers.nix-gc.enable = true;
|
||||
systemd.timers.nix-gc.timerConfig.OnCalendar = cfg.dates;
|
||||
|
||||
systemd.services."nix-gc" =
|
||||
systemd.services.nix-gc =
|
||||
{ description = "Nix Garbage Collector";
|
||||
path = [ config.environment.nix ];
|
||||
script = "exec nix-collect-garbage ${cfg.options}";
|
||||
|
@ -223,6 +223,26 @@ rec {
|
||||
|
||||
};
|
||||
|
||||
|
||||
timerOptions = unitOptions // {
|
||||
|
||||
timerConfig = mkOption {
|
||||
default = {};
|
||||
example = { OnCalendar = "Sun 14:00:00"; Unit = "foo.service"; };
|
||||
type = types.attrs;
|
||||
description = ''
|
||||
Each attribute in this set specifies an option in the
|
||||
<literal>[Timer]</literal> section of the unit. See
|
||||
<citerefentry><refentrytitle>systemd.timer</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> and
|
||||
<citerefentry><refentrytitle>systemd.time</refentrytitle>
|
||||
<manvolnum>5</manvolnum></citerefentry> for details.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
mountOptions = unitOptions // {
|
||||
|
||||
what = mkOption {
|
||||
|
@ -278,6 +278,18 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
timerToUnit = name: def:
|
||||
{ inherit (def) wantedBy enable;
|
||||
text =
|
||||
''
|
||||
[Unit]
|
||||
${attrsToSection def.unitConfig}
|
||||
|
||||
[Timer]
|
||||
${attrsToSection def.timerConfig}
|
||||
'';
|
||||
};
|
||||
|
||||
mountToUnit = name: def:
|
||||
{ inherit (def) wantedBy enable;
|
||||
text =
|
||||
@ -410,6 +422,13 @@ in
|
||||
description = "Definition of systemd socket units.";
|
||||
};
|
||||
|
||||
systemd.timers = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf types.optionSet;
|
||||
options = [ timerOptions unitConfig ];
|
||||
description = "Definition of systemd timer units.";
|
||||
};
|
||||
|
||||
systemd.mounts = mkOption {
|
||||
default = [];
|
||||
type = types.listOf types.optionSet;
|
||||
@ -552,6 +571,7 @@ in
|
||||
mapAttrs' (n: v: nameValuePair "${n}.target" (targetToUnit n v)) cfg.targets
|
||||
// mapAttrs' (n: v: nameValuePair "${n}.service" (serviceToUnit n v)) cfg.services
|
||||
// mapAttrs' (n: v: nameValuePair "${n}.socket" (socketToUnit n v)) cfg.sockets
|
||||
// mapAttrs' (n: v: nameValuePair "${n}.timer" (timerToUnit n v)) cfg.timers
|
||||
// listToAttrs (map
|
||||
(v: let n = escapeSystemdPath v.where;
|
||||
in nameValuePair "${n}.mount" (mountToUnit n v)) cfg.mounts);
|
||||
|
Loading…
Reference in New Issue
Block a user