blob: bd1ecb40969b3eadb5568f96a164e7c7e66d1598 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.fcron;
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 = "644";
gid = config.ids.gids.fcron;
};
in
{
###### interface
options = {
services.fcron = {
enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable the <command>fcron</command> daemon.";
};
allow = mkOption {
type = types.listOf types.str;
default = [ "all" ];
description = ''
Users allowed to use fcrontab and fcrondyn (one name per
line, <literal>all</literal> for everyone).
'';
};
deny = mkOption {
type = types.listOf types.str;
default = [];
description = "Users forbidden from using fcron.";
};
maxSerialJobs = mkOption {
type = types.int;
default = 1;
description = "Maximum number of serial jobs which can run simultaneously.";
};
queuelen = mkOption {
type = types.nullOr types.int;
default = null;
description = "Number of jobs the serial queue and the lavg queue can contain.";
};
systab = mkOption {
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 "fcron.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 = ${pkgs.vim}/bin/vim
'';
target = "fcron.conf";
gid = config.ids.gids.fcron;
mode = "0644";
}
];
environment.systemPackages = [ pkgs.fcron ];
users.extraUsers.fcron = {
uid = config.ids.uids.fcron;
home = "/var/spool/fcron";
group = "fcron";
};
users.groups.fcron.gid = config.ids.gids.fcron;
security.wrappers = {
fcrontab = {
source = "${pkgs.fcron}/bin/fcrontab";
owner = "fcron";
group = "fcron";
setgid = true;
};
fcrondyn = {
source = "${pkgs.fcron}/bin/fcrondyn";
owner = "fcron";
group = "fcron";
setgid = true;
};
fcronsighup = {
source = "${pkgs.fcron}/bin/fcronsighup";
group = "fcron";
};
};
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";
};
preStart = ''
${pkgs.coreutils}/bin/mkdir -m 0770 -p /var/spool/fcron
${pkgs.coreutils}/bin/chown -R fcron:fcron /var/spool/fcron
# load system crontab file
set -x
#${pkgs.fcron}/bin/fcrontab -u systab ${pkgs.writeText "systab" cfg.systab}
'';
serviceConfig = {
Type = "forking";
ExecStart = "${pkgs.fcron}/sbin/fcron -m ${toString cfg.maxSerialJobs} ${queuelen}";
};
};
};
}
|