2009-10-12 17:36:19 +01:00
|
|
|
{ config, pkgs, ... }:
|
2009-01-02 19:41:39 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
with pkgs.lib;
|
2009-01-02 19:41:39 +00:00
|
|
|
|
|
|
|
let
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2009-01-02 19:41:39 +00:00
|
|
|
cfg = config.services.fcron;
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-01-02 19:41:39 +00:00
|
|
|
queuelen = if cfg.queuelen == "" then "" else "-q ${toString cfg.queuelen}";
|
|
|
|
|
2011-01-03 18:36:31 +00:00
|
|
|
systemCronJobs =
|
2009-10-12 17:36:19 +01:00
|
|
|
''
|
2010-10-10 12:35:15 +01:00
|
|
|
SHELL=${pkgs.bash}/bin/bash
|
|
|
|
PATH=${config.system.path}/bin:${config.system.path}/sbin
|
|
|
|
MAILTO="${config.services.cron.mailto}"
|
2011-11-03 19:04:54 +00:00
|
|
|
NIX_CONF_DIR=/etc/nix
|
2010-10-10 12:35:15 +01:00
|
|
|
${pkgs.lib.concatStrings (map (job: job + "\n") config.services.cron.systemCronJobs)}
|
2009-10-12 17:36:19 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
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 19:41:39 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
###### interface
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
services.fcron = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the `fcron' daemon.";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
allow = mkOption {
|
2010-10-10 12:35:15 +01:00
|
|
|
default = [ "all" ];
|
2009-10-12 17:36:19 +01:00
|
|
|
description = ''
|
|
|
|
Users allowed to use fcrontab and fcrondyn (one name per line, "all" for everyone).
|
|
|
|
'';
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
deny = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "Users forbidden from using fcron.";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
maxSerialJobs = mkOption {
|
|
|
|
default = 1;
|
|
|
|
description = "Maximum number of serial jobs which can run simultaneously.";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
queuelen = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "Number of jobs the serial queue and the lavg queue can contain - empty to net set this number (-q)";
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
systab = mkOption {
|
2011-01-05 10:42:39 +00:00
|
|
|
default = "";
|
2009-10-12 17:36:19 +01:00
|
|
|
description = ''The "system" crontab contents.'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2009-01-02 19:41:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2009-01-02 19:41:39 +00:00
|
|
|
|
2011-01-05 10:42:39 +00:00
|
|
|
services.fcron.systab = systemCronJobs;
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
environment.etc =
|
2010-10-10 12:35:15 +01:00
|
|
|
[ (allowdeny "allow" (cfg.allow))
|
2009-10-12 17:36:19 +01:00
|
|
|
(allowdeny "deny" cfg.deny)
|
|
|
|
# see man 5 fcron.conf
|
|
|
|
{ source = pkgs.writeText "fcon.conf" ''
|
2010-04-15 16:47:26 +01: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
|
2012-07-16 16:27:59 +01:00
|
|
|
editor = /run/current-system/sw/bin/vi
|
2009-10-12 17:36:19 +01:00
|
|
|
'';
|
|
|
|
target = "fcron.conf";
|
|
|
|
mode = "0600"; # max allowed is 644
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.fcron ];
|
|
|
|
|
2010-10-10 12:35:15 +01:00
|
|
|
security.setuidPrograms = [ "fcrontab" ];
|
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.fcron =
|
2009-10-12 17:36:19 +01:00
|
|
|
{ description = "fcron daemon";
|
|
|
|
|
2013-04-16 23:19:39 +01:00
|
|
|
startOn = "startup";
|
|
|
|
|
|
|
|
after = [ "local-fs.target" ];
|
2009-01-02 19:41:39 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
environment =
|
2012-07-16 16:27:59 +01:00
|
|
|
{ PATH = "/run/current-system/sw/bin";
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2009-01-02 19:41:39 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
preStart =
|
|
|
|
''
|
2009-01-02 19:41:39 +00:00
|
|
|
${pkgs.coreutils}/bin/mkdir -m 0700 -p /var/spool/fcron
|
|
|
|
# load system crontab file
|
2009-10-12 17:36:19 +01:00
|
|
|
${pkgs.fcron}/bin/fcrontab -u systab ${pkgs.writeText "systab" cfg.systab}
|
|
|
|
'';
|
|
|
|
|
2012-06-10 16:14:16 +01:00
|
|
|
daemonType = "fork";
|
|
|
|
|
|
|
|
exec = "${pkgs.fcron}/sbin/fcron -m ${toString cfg.maxSerialJobs} ${queuelen}";
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
2009-01-02 19:41:39 +00:00
|
|
|
|
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2009-01-02 19:41:39 +00:00
|
|
|
}
|