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"
|
|
|
|
''
|
|
|
|
SHELL=${pkgs.bash}/bin/sh
|
|
|
|
PATH=${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.gnused}/bin:${pkgs.su}/bin
|
|
|
|
MAILTO="${config.services.cron.mailto}"
|
|
|
|
${pkgs.lib.concatStrings (map (job: job + "\n") config.services.cron.systemCronJobs)}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2008-02-01 13:01:27 +01:00
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
options = {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.cron = {
|
2008-11-09 17:44:43 +01:00
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +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
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = {
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment.systemPackages = [pkgs.cron];
|
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";
|
|
|
|
|
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
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${pkgs.cron}/sbin/cron -n";
|
|
|
|
};
|
2009-04-03 17:14:00 +02:00
|
|
|
|
2008-11-09 17:44:43 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2007-01-10 18:09:00 +01:00
|
|
|
}
|