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