diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-09 14:28:35 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-09 14:28:35 +0200 |
commit | 36079454e5456d43a36aa75194265bda72f75f5d (patch) | |
tree | e1a8a7ee7113acee7ad21caefb8eb506a50ea32f /modules | |
parent | 87bea0b09eaa99a663c4d8a32b6b3da1c5352bfc (diff) | |
download | nixlib-36079454e5456d43a36aa75194265bda72f75f5d.tar nixlib-36079454e5456d43a36aa75194265bda72f75f5d.tar.gz nixlib-36079454e5456d43a36aa75194265bda72f75f5d.tar.bz2 nixlib-36079454e5456d43a36aa75194265bda72f75f5d.tar.lz nixlib-36079454e5456d43a36aa75194265bda72f75f5d.tar.xz nixlib-36079454e5456d43a36aa75194265bda72f75f5d.tar.zst nixlib-36079454e5456d43a36aa75194265bda72f75f5d.zip |
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.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/programs/venus.nix | 6 | ||||
-rw-r--r-- | modules/services/misc/nix-gc.nix | 26 | ||||
-rw-r--r-- | modules/system/boot/systemd-unit-options.nix | 14 | ||||
-rw-r--r-- | modules/system/boot/systemd.nix | 8 |
4 files changed, 32 insertions, 22 deletions
diff --git a/modules/programs/venus.nix b/modules/programs/venus.nix index c316163c8c7f..2b3bfbc6c188 100644 --- a/modules/programs/venus.nix +++ b/modules/programs/venus.nix @@ -167,11 +167,7 @@ in serviceConfig.User = "${cfg.user}"; serviceConfig.Group = "${cfg.group}"; environment.OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"; - }; - - systemd.timers.venus = - { wantedBy = [ "timers.target" ]; - timerConfig.OnCalendar = cfg.dates; + startOn = cfg.dates; }; }; diff --git a/modules/services/misc/nix-gc.nix b/modules/services/misc/nix-gc.nix index dfc4fd3c2ff0..dfdc4db65d54 100644 --- a/modules/services/misc/nix-gc.nix +++ b/modules/services/misc/nix-gc.nix @@ -48,22 +48,14 @@ in ###### implementation - config = mkMerge [ - - { systemd.services.nix-gc = - { description = "Nix Garbage Collector"; - path = [ config.environment.nix ]; - script = "exec nix-collect-garbage ${cfg.options}"; - }; - } - - (mkIf cfg.automatic { - systemd.timers.nix-gc = - { wantedBy = [ "timers.target" ]; - timerConfig.OnCalendar = cfg.dates; - }; - }) - - ]; + config = { + + systemd.services.nix-gc = + { description = "Nix Garbage Collector"; + serviceConfig.ExecStart = "${config.environment.nix}/bin/nix-collect-garbage ${cfg.options}"; + startAt = optionalString cfg.automatic cfg.dates; + }; + + }; } diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index e6e8d9eb3b01..dfb9036ab4df 100644 --- a/modules/system/boot/systemd-unit-options.nix +++ b/modules/system/boot/systemd-unit-options.nix @@ -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. + ''; + }; + }; diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index 35ae6a84024c..a5e1165574c5 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -628,6 +628,14 @@ in 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. systemd.services."systemd-update-utmp" = { description = "Update UTMP about System Reboot/Shutdown"; |