1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.atd;
8
9 inherit (pkgs) at;
10
11in
12
13{
14
15 ###### interface
16
17 options = {
18
19 services.atd.enable = mkOption {
20 type = types.bool;
21 default = false;
22 description = ''
23 Whether to enable the <command>at</command> daemon, a command scheduler.
24 '';
25 };
26
27 services.atd.allowEveryone = mkOption {
28 type = types.bool;
29 default = false;
30 description = ''
31 Whether to make <filename>/var/spool/at{jobs,spool}</filename>
32 writeable by everyone (and sticky). This is normally not
33 needed since the <command>at</command> commands are
34 setuid/setgid <literal>atd</literal>.
35 '';
36 };
37
38 };
39
40
41 ###### implementation
42
43 config = mkIf cfg.enable {
44
45 # Not wrapping "batch" because it's a shell script (kernel drops perms
46 # anyway) and it's patched to invoke the "at" setuid wrapper.
47 security.wrappers = builtins.listToAttrs (
48 map (program: { name = "${program}"; value = {
49 source = "${at}/bin/${program}";
50 owner = "atd";
51 group = "atd";
52 setuid = true;
53 setgid = true;
54 };}) [ "at" "atq" "atrm" ]);
55
56 environment.systemPackages = [ at ];
57
58 security.pam.services.atd = {};
59
60 users.users.atd =
61 { uid = config.ids.uids.atd;
62 description = "atd user";
63 home = "/var/empty";
64 };
65
66 users.groups.atd.gid = config.ids.gids.atd;
67
68 systemd.services.atd = {
69 description = "Job Execution Daemon (atd)";
70 wantedBy = [ "multi-user.target" ];
71
72 path = [ at ];
73
74 preStart = ''
75 # Snippets taken and adapted from the original `install' rule of
76 # the makefile.
77
78 # We assume these values are those actually used in Nixpkgs for
79 # `at'.
80 spooldir=/var/spool/atspool
81 jobdir=/var/spool/atjobs
82 etcdir=/etc/at
83
84 install -dm755 -o atd -g atd "$etcdir"
85 spool_and_job_dir_perms=${if cfg.allowEveryone then "1777" else "1770"}
86 install -dm"$spool_and_job_dir_perms" -o atd -g atd "$spooldir" "$jobdir"
87 if [ ! -f "$etcdir"/at.deny ]; then
88 touch "$etcdir"/at.deny
89 chown root:atd "$etcdir"/at.deny
90 chmod 640 "$etcdir"/at.deny
91 fi
92 if [ ! -f "$jobdir"/.SEQ ]; then
93 touch "$jobdir"/.SEQ
94 chown atd:atd "$jobdir"/.SEQ
95 chmod 600 "$jobdir"/.SEQ
96 fi
97 '';
98
99 script = "atd";
100
101 serviceConfig.Type = "forking";
102 };
103 };
104}