2009-01-02 17:07:10 +01:00
|
|
|
{pkgs, config, ...}:
|
2008-04-01 12:16:35 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
with pkgs.lib;
|
|
|
|
|
2009-01-02 17:07:10 +01:00
|
|
|
let
|
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
cfg = config.services.atd;
|
|
|
|
|
|
|
|
inherit (pkgs) at;
|
|
|
|
|
2008-04-01 12:16:35 +02:00
|
|
|
in
|
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
{
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
###### interface
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
options = {
|
|
|
|
|
|
|
|
services.atd.enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the `at' daemon, a command scheduler.
|
|
|
|
'';
|
|
|
|
};
|
2008-04-01 12:16:35 +02:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
services.atd.allowEveryone = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to make /var/spool/at{jobs,spool} writeable
|
|
|
|
by everyone (and sticky). This is normally not needed since
|
|
|
|
the `at' commands are setuid/setgid `atd'.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
###### implementation
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
config = mkIf cfg.enable {
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
security.setuidOwners = map (program: {
|
|
|
|
inherit program;
|
|
|
|
owner = "atd";
|
|
|
|
group = "atd";
|
|
|
|
setuid = true;
|
|
|
|
setgid = true;
|
|
|
|
}) [ "at" "atq" "atrm" ];
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
environment.systemPackages = [ at ];
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
security.pam.services = [ { name = "atd"; } ];
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "atd";
|
|
|
|
uid = config.ids.uids.atd;
|
|
|
|
description = "atd user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-08-16 16:49:14 +02:00
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "atd";
|
|
|
|
gid = config.ids.gids.atd;
|
|
|
|
};
|
2009-01-02 17:07:10 +01:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.atd =
|
2009-10-12 19:27:57 +02:00
|
|
|
{ description = "at daemon (atd)";
|
2009-08-21 02:02:45 +02:00
|
|
|
|
|
|
|
startOn = "startup";
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
# Snippets taken and adapted from the original `install' rule of
|
|
|
|
# the makefile.
|
|
|
|
|
|
|
|
# We assume these values are those actually used in Nixpkgs for
|
|
|
|
# `at'.
|
|
|
|
spooldir=/var/spool/atspool
|
|
|
|
jobdir=/var/spool/atjobs
|
|
|
|
etcdir=/etc/at
|
|
|
|
|
|
|
|
for dir in "$spooldir" "$jobdir" "$etcdir"; do
|
|
|
|
if [ ! -d "$dir" ]; then
|
|
|
|
mkdir -p "$dir" && chown atd:atd "$dir"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
chmod 1770 "$spooldir" "$jobdir"
|
|
|
|
${if cfg.allowEveryone then ''chmod a+rwxt "$spooldir" "$jobdir" '' else ""}
|
|
|
|
if [ ! -f "$etcdir"/at.deny ]; then
|
|
|
|
touch "$etcdir"/at.deny && \
|
|
|
|
chown root:atd "$etcdir"/at.deny && \
|
|
|
|
chmod 640 "$etcdir"/at.deny
|
|
|
|
fi
|
|
|
|
if [ ! -f "$jobdir"/.SEQ ]; then
|
|
|
|
touch "$jobdir"/.SEQ && \
|
|
|
|
chown atd:atd "$jobdir"/.SEQ && \
|
|
|
|
chmod 600 "$jobdir"/.SEQ
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2009-11-06 23:19:17 +01:00
|
|
|
daemonType = "fork";
|
|
|
|
|
|
|
|
exec = "${at}/sbin/atd";
|
|
|
|
|
2009-08-21 02:02:45 +02:00
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
test -e /var/run/atd.pid && kill $(cat /var/run/atd.pid)
|
|
|
|
'';
|
2009-08-16 16:49:14 +02:00
|
|
|
};
|
2009-01-02 17:07:10 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-04-01 12:16:35 +02:00
|
|
|
}
|