2009-10-12 17:36:19 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2007-01-10 17:09:00 +00:00
|
|
|
|
2008-02-01 12:01:27 +00:00
|
|
|
let
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
inherit (config.services) jobsTags;
|
|
|
|
|
|
|
|
# Put all the system cronjobs together.
|
|
|
|
systemCronJobsFile = pkgs.writeText "system-crontab"
|
|
|
|
''
|
2009-11-24 14:20:33 +00:00
|
|
|
SHELL=${pkgs.bash}/bin/bash
|
|
|
|
PATH=/var/run/current-system/sw/bin:/var/run/current-system/sw/sbin
|
2009-10-12 17:36:19 +01:00
|
|
|
MAILTO="${config.services.cron.mailto}"
|
|
|
|
${pkgs.lib.concatStrings (map (job: job + "\n") config.services.cron.systemCronJobs)}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2008-02-01 12:01:27 +00:00
|
|
|
|
2008-11-09 16:44:43 +00:00
|
|
|
options = {
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
services.cron = {
|
2008-11-09 16:44:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
mailto = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = " The job output will be mailed to this email address. ";
|
2008-11-09 16:44:43 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01: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 16:44:43 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-11-09 16:44:43 +00:00
|
|
|
};
|
|
|
|
|
2008-12-07 12:27:46 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### implementation
|
2008-11-09 16:44:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
config = {
|
|
|
|
|
|
|
|
environment.etc = singleton
|
2008-11-09 16:44:43 +00:00
|
|
|
# The system-wide crontab.
|
|
|
|
{ source = systemCronJobsFile;
|
|
|
|
target = "crontab";
|
|
|
|
mode = "0600"; # Cron requires this.
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2008-02-01 13:56:36 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
environment.systemPackages = [pkgs.cron];
|
2008-11-09 16:44:43 +00:00
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.cron =
|
2009-10-12 17:36:19 +01:00
|
|
|
{ description = "Cron daemon";
|
2008-11-09 16:44:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
startOn = "startup";
|
|
|
|
stopOn = "shutdown";
|
|
|
|
|
2008-11-09 16:44:43 +00:00
|
|
|
# Needed to interpret times in the local timezone.
|
2009-10-12 17:36:19 +01:00
|
|
|
environment = { TZ = config.time.timeZone; };
|
2008-11-09 16:44:43 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
preStart =
|
|
|
|
''
|
2009-04-03 16:14:00 +01: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 17:36:19 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${pkgs.cron}/sbin/cron -n";
|
|
|
|
};
|
2009-04-03 16:14:00 +01:00
|
|
|
|
2008-11-09 16:44:43 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2007-01-10 17:09:00 +00:00
|
|
|
}
|