Make it easier to define timer units for services
Systemd services now have a startAt attribute. If set, NixOS will automatically emit a timer unit that causes the service to start at the specified time. For example: systemd.services.foo = { script = "... bla bla ..."; startAt = "02:15"; }; causes the given script to be started at 02:15 every day.
This commit is contained in:
parent
87bea0b09e
commit
36079454e5
@ -167,11 +167,7 @@ in
|
|||||||
serviceConfig.User = "${cfg.user}";
|
serviceConfig.User = "${cfg.user}";
|
||||||
serviceConfig.Group = "${cfg.group}";
|
serviceConfig.Group = "${cfg.group}";
|
||||||
environment.OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
|
environment.OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
|
||||||
};
|
startOn = cfg.dates;
|
||||||
|
|
||||||
systemd.timers.venus =
|
|
||||||
{ wantedBy = [ "timers.target" ];
|
|
||||||
timerConfig.OnCalendar = cfg.dates;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -48,22 +48,14 @@ in
|
|||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkMerge [
|
config = {
|
||||||
|
|
||||||
{ systemd.services.nix-gc =
|
systemd.services.nix-gc =
|
||||||
{ description = "Nix Garbage Collector";
|
{ description = "Nix Garbage Collector";
|
||||||
path = [ config.environment.nix ];
|
serviceConfig.ExecStart = "${config.environment.nix}/bin/nix-collect-garbage ${cfg.options}";
|
||||||
script = "exec nix-collect-garbage ${cfg.options}";
|
startAt = optionalString cfg.automatic cfg.dates;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
(mkIf cfg.automatic {
|
};
|
||||||
systemd.timers.nix-gc =
|
|
||||||
{ wantedBy = [ "timers.target" ];
|
|
||||||
timerConfig.OnCalendar = cfg.dates;
|
|
||||||
};
|
|
||||||
})
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -229,6 +229,20 @@ rec {
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
startAt = mkOption {
|
||||||
|
type = types.uniq types.string;
|
||||||
|
default = "";
|
||||||
|
example = "Sun 14:00:00";
|
||||||
|
description = ''
|
||||||
|
Automatically start this unit at the given date/time, which
|
||||||
|
must be in the format described in
|
||||||
|
<citerefentry><refentrytitle>systemd.time</refentrytitle>
|
||||||
|
<manvolnum>5</manvolnum></citerefentry>. This is equivalent
|
||||||
|
to adding a corresponding timer unit with
|
||||||
|
<option>OnCalendar</option> set to the value given here.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -628,6 +628,14 @@ in
|
|||||||
|
|
||||||
users.extraGroups.systemd-journal.gid = config.ids.gids.systemd-journal;
|
users.extraGroups.systemd-journal.gid = config.ids.gids.systemd-journal;
|
||||||
|
|
||||||
|
# Generate timer units for all services that have a ‘startAt’ value.
|
||||||
|
systemd.timers =
|
||||||
|
mapAttrs (name: service:
|
||||||
|
{ wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig.OnCalendar = service.startAt;
|
||||||
|
})
|
||||||
|
(filterAttrs (name: service: service.startAt != "") cfg.services);
|
||||||
|
|
||||||
# FIXME: These are borrowed from upstream systemd.
|
# FIXME: These are borrowed from upstream systemd.
|
||||||
systemd.services."systemd-update-utmp" =
|
systemd.services."systemd-update-utmp" =
|
||||||
{ description = "Update UTMP about System Reboot/Shutdown";
|
{ description = "Update UTMP about System Reboot/Shutdown";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user