2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-01-02 20:41:39 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with 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
|
|
|
cfg = config.services.fcron;
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2013-10-30 17:37:45 +01:00
|
|
|
queuelen = if cfg.queuelen == null then "" else "-q ${toString cfg.queuelen}";
|
2009-01-02 20:41:39 +01:00
|
|
|
|
2013-11-04 12:07:03 +01:00
|
|
|
# Duplicate code, also found in cron.nix. Needs deduplication.
|
2011-01-03 19:36:31 +01:00
|
|
|
systemCronJobs =
|
2009-10-12 18:36:19 +02:00
|
|
|
''
|
2010-10-10 13:35:15 +02:00
|
|
|
SHELL=${pkgs.bash}/bin/bash
|
|
|
|
PATH=${config.system.path}/bin:${config.system.path}/sbin
|
2013-11-04 12:07:03 +01:00
|
|
|
${optionalString (config.services.cron.mailto != null) ''
|
|
|
|
MAILTO="${config.services.cron.mailto}"
|
|
|
|
''}
|
2011-11-03 20:04:54 +01:00
|
|
|
NIX_CONF_DIR=/etc/nix
|
2014-05-05 20:58:51 +02:00
|
|
|
${lib.concatStrings (map (job: job + "\n") config.services.cron.systemCronJobs)}
|
2009-10-12 18:36:19 +02: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 20:41:39 +01:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
###### interface
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.fcron = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
enable = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.bool;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = false;
|
2013-10-30 17:37:45 +01:00
|
|
|
description = "Whether to enable the <command>fcron</command> daemon.";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
allow = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.listOf types.str;
|
2010-10-10 13:35:15 +02:00
|
|
|
default = [ "all" ];
|
2009-10-12 18:36:19 +02:00
|
|
|
description = ''
|
2013-10-30 17:37:45 +01:00
|
|
|
Users allowed to use fcrontab and fcrondyn (one name per
|
|
|
|
line, <literal>all</literal> for everyone).
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
deny = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.listOf types.str;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = [];
|
|
|
|
description = "Users forbidden from using fcron.";
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
maxSerialJobs = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.int;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = 1;
|
|
|
|
description = "Maximum number of serial jobs which can run simultaneously.";
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
queuelen = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
description = "Number of jobs the serial queue and the lavg queue can contain.";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
systab = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
type = types.lines;
|
2011-01-05 11:42:39 +01:00
|
|
|
default = "";
|
2009-10-12 18:36:19 +02:00
|
|
|
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
|
|
|
|
2011-01-05 11:42:39 +01:00
|
|
|
services.fcron.systab = systemCronJobs;
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment.etc =
|
2010-10-10 13:35:15 +02:00
|
|
|
[ (allowdeny "allow" (cfg.allow))
|
2009-10-12 18:36:19 +02:00
|
|
|
(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
|
2012-07-16 17:27:59 +02:00
|
|
|
editor = /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 ];
|
|
|
|
|
2010-10-10 13:35:15 +02:00
|
|
|
security.setuidPrograms = [ "fcrontab" ];
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.fcron =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "fcron daemon";
|
|
|
|
|
2013-04-17 00:19:39 +02:00
|
|
|
startOn = "startup";
|
|
|
|
|
|
|
|
after = [ "local-fs.target" ];
|
2009-01-02 20:41:39 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
environment =
|
2012-07-16 17:27:59 +02:00
|
|
|
{ PATH = "/run/current-system/sw/bin";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
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}
|
|
|
|
'';
|
|
|
|
|
2012-06-10 17:14:16 +02:00
|
|
|
daemonType = "fork";
|
|
|
|
|
|
|
|
exec = "${pkgs.fcron}/sbin/fcron -m ${toString cfg.maxSerialJobs} ${queuelen}";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
2009-01-02 20:41:39 +01:00
|
|
|
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-01-02 20:41:39 +01:00
|
|
|
}
|