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
|
2009-11-24 15:05:08 +00:00
|
|
|
PATH=${config.system.path}/bin:${config.system.path}/sbin
|
2009-10-12 17:36:19 +01:00
|
|
|
MAILTO="${config.services.cron.mailto}"
|
2010-08-31 13:57:47 +01:00
|
|
|
NIX_CONF_DIR=/nix/etc/nix
|
2009-10-12 17:36:19 +01:00
|
|
|
${pkgs.lib.concatStrings (map (job: job + "\n") config.services.cron.systemCronJobs)}
|
|
|
|
'';
|
2010-10-10 12:08:10 +01: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";
|
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2010-10-10 12:14:02 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "Whether to enable the `vixie cron' daemon.";
|
|
|
|
};
|
|
|
|
|
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.
|
2010-10-10 12:35:15 +01: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 17:36:19 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2010-10-10 12:35:15 +01:00
|
|
|
config = mkIf config.services.cron.enable {
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2010-10-10 12:35:15 +01:00
|
|
|
security.setuidPrograms = [ "crontab" ];
|
|
|
|
|
2010-10-10 12:08:10 +01:00
|
|
|
environment.systemPackages = [ cronNixosPkg ];
|
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";
|
|
|
|
|
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
|
|
|
'';
|
|
|
|
|
2010-10-10 12:08:10 +01:00
|
|
|
exec = "${cronNixosPkg}/sbin/cron -n";
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
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
|
|
|
}
|