2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
2009-01-02 20:41:39 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
with pkgs.lib;
|
2009-01-02 20:41:39 +01:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-01-02 20:41:39 +01:00
|
|
|
# Put all the system cronjobs together.
|
|
|
|
# TODO allow using fcron only..
|
|
|
|
#systemCronJobs =
|
|
|
|
# config.services.cron.systemCronJobs;
|
|
|
|
cfg = config.services.fcron;
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-01-02 20:41:39 +01:00
|
|
|
queuelen = if cfg.queuelen == "" then "" else "-q ${toString cfg.queuelen}";
|
|
|
|
|
|
|
|
# shell is set to /sh in config..
|
|
|
|
# ${pkgs.lib.concatStrings (map (job: job + "\n") systemCronJobs)}
|
2009-10-12 18:36:19 +02:00
|
|
|
systemCronJobsFile = pkgs.writeText "fcron-systab"
|
|
|
|
''
|
|
|
|
SHELL=${pkgs.bash}/bin/sh
|
|
|
|
PATH=${pkgs.coreutils}/bin:${pkgs.findutils}/bin:${pkgs.gnused}/bin
|
|
|
|
'';
|
|
|
|
|
|
|
|
allowdeny = target: users:
|
|
|
|
{ source = pkgs.writeText "fcron.${target}" (concatStringsSep "\n" users);
|
|
|
|
target = "fcron.${target}";
|
|
|
|
mode = "600"; # fcron has some security issues.. So I guess this is most safe
|
|
|
|
};
|
2009-01-02 20:41:39 +01:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.fcron = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the `fcron' daemon.";
|
|
|
|
};
|
|
|
|
|
|
|
|
allow = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Users allowed to use fcrontab and fcrondyn (one name per line, "all" for everyone).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
deny = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "Users forbidden from using fcron.";
|
|
|
|
};
|
|
|
|
|
|
|
|
maxSerialJobs = mkOption {
|
|
|
|
default = 1;
|
|
|
|
description = "Maximum number of serial jobs which can run simultaneously.";
|
|
|
|
};
|
|
|
|
|
|
|
|
queuelen = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Number of jobs the serial queue and the lavg queue can contain - empty to net set this number (-q)";
|
|
|
|
};
|
|
|
|
|
|
|
|
systab = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''The "system" crontab contents.'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-01-02 20:41:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2009-01-02 20:41:39 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment.etc =
|
|
|
|
[ (allowdeny "allow" (["root"] ++ cfg.allow))
|
|
|
|
(allowdeny "deny" cfg.deny)
|
|
|
|
# see man 5 fcron.conf
|
|
|
|
{ source = pkgs.writeText "fcon.conf" ''
|
2010-04-15 17:47:26 +02:00
|
|
|
fcrontabs = /var/spool/fcron
|
|
|
|
pidfile = /var/run/fcron.pid
|
|
|
|
fifofile = /var/run/fcron.fifo
|
|
|
|
fcronallow = /etc/fcron.allow
|
|
|
|
fcrondeny = /etc/fcron.deny
|
|
|
|
shell = /bin/sh
|
|
|
|
sendmail = /var/setuid-wrappers/sendmail
|
|
|
|
editor = /var/run/current-system/sw/bin/vi
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
target = "fcron.conf";
|
|
|
|
mode = "0600"; # max allowed is 644
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.fcron ];
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.fcron =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "fcron daemon";
|
|
|
|
|
|
|
|
startOn = "startup";
|
2009-01-02 20:41:39 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment =
|
|
|
|
{ PATH = "/var/run/current-system/sw/bin";
|
|
|
|
};
|
2009-01-02 20:41:39 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
preStart =
|
|
|
|
''
|
2009-01-02 20:41:39 +01:00
|
|
|
${pkgs.coreutils}/bin/mkdir -m 0700 -p /var/spool/fcron
|
|
|
|
# load system crontab file
|
2009-10-12 18:36:19 +02:00
|
|
|
${pkgs.fcron}/bin/fcrontab -u systab ${pkgs.writeText "systab" cfg.systab}
|
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${pkgs.fcron}/sbin/fcron -f -m ${toString cfg.maxSerialJobs} ${queuelen}";
|
|
|
|
};
|
2009-01-02 20:41:39 +01:00
|
|
|
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-01-02 20:41:39 +01:00
|
|
|
}
|