2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2007-01-10 18:09:00 +01:00
|
|
|
|
2008-02-01 13:01:27 +01:00
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
inherit (config.services) jobsTags;
|
|
|
|
|
|
|
|
# Put all the system cronjobs together.
|
|
|
|
systemCronJobsFile = pkgs.writeText "system-crontab"
|
|
|
|
''
|
2009-11-24 15:20:33 +01:00
|
|
|
SHELL=${pkgs.bash}/bin/bash
|
2009-11-24 16:05:08 +01:00
|
|
|
PATH=${config.system.path}/bin:${config.system.path}/sbin
|
2009-10-12 18:36:19 +02:00
|
|
|
MAILTO="${config.services.cron.mailto}"
|
2010-08-31 14:57:47 +02:00
|
|
|
NIX_CONF_DIR=/nix/etc/nix
|
2009-10-12 18:36:19 +02:00
|
|
|
${pkgs.lib.concatStrings (map (job: job + "\n") config.services.cron.systemCronJobs)}
|
|
|
|
'';
|
2010-10-10 13:08:10 +02:00
|
|
|
|
|
|
|
# Vixie cron requires build-time configuration for the sendmail path.
|
|
|
|
cronNixosPkg = pkgs.cron.override {
|
|
|
|
# The mail.nix nixos module, if there is any local mail system enabled,
|
|
|
|
# should have sendmail in this path.
|
|
|
|
sendmailPath = "/var/setuid-wrappers/sendmail";
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2008-02-01 13:01:27 +01:00
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.cron = {
|
2008-11-09 17:44:43 +01:00
|
|
|
|
2010-10-10 13:14:02 +02:00
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "Whether to enable the `vixie cron' daemon.";
|
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
mailto = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = " The job output will be mailed to this email address. ";
|
2008-11-09 17:44:43 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
systemCronJobs = mkOption {
|
|
|
|
default = [];
|
|
|
|
example = [
|
|
|
|
"* * * * * test ls -l / > /tmp/cronout 2>&1"
|
|
|
|
"* * * * * eelco echo Hello World > /home/eelco/cronout"
|
|
|
|
];
|
|
|
|
description = ''
|
|
|
|
A list of Cron jobs to be appended to the system-wide
|
|
|
|
crontab. See the manual page for crontab for the expected
|
|
|
|
format. If you want to get the results mailed you must setuid
|
|
|
|
sendmail. See <option>security.setuidOwners</option>
|
|
|
|
|
|
|
|
If neither /var/cron/cron.deny nor /var/cron/cron.allow exist only root
|
|
|
|
will is allowed to have its own crontab file. The /var/cron/cron.deny file
|
|
|
|
is created automatically for you. So every user can use a crontab.
|
2010-10-10 13:35:15 +02:00
|
|
|
|
|
|
|
Many nixos modules set systemCronJobs, so if you decide to disable vixie cron
|
|
|
|
and enable another cron daemon, you may want it to get its system crontab
|
|
|
|
based on systemCronJobs.
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
};
|
|
|
|
|
2008-12-07 13:27:46 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2008-11-09 17:44:43 +01:00
|
|
|
|
2010-10-10 13:35:15 +02:00
|
|
|
config = mkIf config.services.cron.enable {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
environment.etc = singleton
|
2008-11-09 17:44:43 +01:00
|
|
|
# The system-wide crontab.
|
|
|
|
{ source = systemCronJobsFile;
|
|
|
|
target = "crontab";
|
|
|
|
mode = "0600"; # Cron requires this.
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2008-02-01 14:56:36 +01:00
|
|
|
|
2010-10-10 13:35:15 +02:00
|
|
|
security.setuidPrograms = [ "crontab" ];
|
|
|
|
|
2010-10-10 13:08:10 +02:00
|
|
|
environment.systemPackages = [ cronNixosPkg ];
|
2008-11-09 17:44:43 +01:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.cron =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "Cron daemon";
|
2008-11-09 17:44:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
startOn = "startup";
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
# Needed to interpret times in the local timezone.
|
2009-10-12 18:36:19 +02:00
|
|
|
environment = { TZ = config.time.timeZone; };
|
2008-11-09 17:44:43 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
preStart =
|
|
|
|
''
|
2009-04-03 17:14:00 +02:00
|
|
|
mkdir -m 710 -p /var/cron
|
|
|
|
|
|
|
|
# By default, allow all users to create a crontab. This
|
|
|
|
# is denoted by the existence of an empty cron.deny file.
|
|
|
|
if ! test -e /var/cron/cron.allow -o -e /var/cron/cron.deny; then
|
|
|
|
touch /var/cron/cron.deny
|
|
|
|
fi
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
|
2010-10-10 13:08:10 +02:00
|
|
|
exec = "${cronNixosPkg}/sbin/cron -n";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-04-03 17:14:00 +02:00
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2007-01-10 18:09:00 +01:00
|
|
|
}
|