nixpkgs-suyu/nixos/modules/services/scheduling/fcron.nix

132 lines
3.5 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.fcron;
2013-10-30 17:37:45 +01:00
queuelen = if cfg.queuelen == null then "" else "-q ${toString cfg.queuelen}";
# Duplicate code, also found in cron.nix. Needs deduplication.
systemCronJobs =
''
SHELL=${pkgs.bash}/bin/bash
PATH=${config.system.path}/bin:${config.system.path}/sbin
${optionalString (config.services.cron.mailto != null) ''
MAILTO="${config.services.cron.mailto}"
''}
NIX_CONF_DIR=/etc/nix
${lib.concatStrings (map (job: job + "\n") config.services.cron.systemCronJobs)}
'';
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
};
in
{
###### interface
options = {
services.fcron = {
enable = mkOption {
2013-10-30 17:37:45 +01:00
type = types.bool;
default = false;
2013-10-30 17:37:45 +01:00
description = "Whether to enable the <command>fcron</command> daemon.";
};
allow = mkOption {
2013-10-30 17:37:45 +01:00
type = types.listOf types.str;
default = [ "all" ];
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).
'';
};
deny = mkOption {
2013-10-30 17:37:45 +01:00
type = types.listOf types.str;
default = [];
description = "Users forbidden from using fcron.";
};
maxSerialJobs = mkOption {
2013-10-30 17:37:45 +01:00
type = types.int;
default = 1;
description = "Maximum number of serial jobs which can run simultaneously.";
};
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.";
};
systab = mkOption {
2013-10-30 17:37:45 +01:00
type = types.lines;
default = "";
description = ''The "system" crontab contents.'';
};
};
};
###### implementation
config = mkIf cfg.enable {
services.fcron.systab = systemCronJobs;
environment.etc =
[ (allowdeny "allow" (cfg.allow))
(allowdeny "deny" cfg.deny)
# see man 5 fcron.conf
{ source = pkgs.writeText "fcon.conf" ''
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 = /run/wrappers/bin/sendmail
editor = /run/current-system/sw/bin/vi
'';
target = "fcron.conf";
mode = "0600"; # max allowed is 644
}
];
environment.systemPackages = [ pkgs.fcron ];
2017-01-29 12:33:56 +01:00
security.wrappers.fcrontab.source = "${pkgs.fcron.out}/bin/fcrontab";
2016-01-06 07:50:18 +01:00
systemd.services.fcron = {
description = "fcron daemon";
after = [ "local-fs.target" ];
wantedBy = [ "multi-user.target" ];
# FIXME use specific path
environment = {
PATH = "/run/current-system/sw/bin";
};
2016-01-06 07:50:18 +01:00
preStart = ''
${pkgs.coreutils}/bin/mkdir -m 0700 -p /var/spool/fcron
# load system crontab file
${pkgs.fcron}/bin/fcrontab -u systab ${pkgs.writeText "systab" cfg.systab}
'';
2016-01-06 07:50:18 +01:00
serviceConfig.Type = "forking";
2016-01-06 07:50:18 +01:00
script = "${pkgs.fcron}/sbin/fcron -m ${toString cfg.maxSerialJobs} ${queuelen}";
};
};
}