2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-04-01 10:16:35 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2009-08-16 14:49:14 +00:00
|
|
|
|
2009-01-02 16:07:10 +00:00
|
|
|
let
|
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
cfg = config.services.atd;
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
inherit (pkgs) at;
|
|
|
|
|
2008-04-01 10:16:35 +00:00
|
|
|
in
|
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
{
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
###### interface
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
services.atd.enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2013-06-01 09:38:49 +00:00
|
|
|
default = false;
|
2009-08-16 14:49:14 +00:00
|
|
|
description = ''
|
2013-10-30 16:37:45 +00:00
|
|
|
Whether to enable the <command>at</command> daemon, a command scheduler.
|
2009-08-16 14:49:14 +00:00
|
|
|
'';
|
|
|
|
};
|
2008-04-01 10:16:35 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
services.atd.allowEveryone = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2009-08-16 14:49:14 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
2013-10-30 16:37:45 +00:00
|
|
|
Whether to make <filename>/var/spool/at{jobs,spool}</filename>
|
|
|
|
writeable by everyone (and sticky). This is normally not
|
|
|
|
needed since the <command>at</command> commands are
|
|
|
|
setuid/setgid <literal>atd</literal>.
|
2009-08-16 14:49:14 +00:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
###### implementation
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
config = mkIf cfg.enable {
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
security.setuidOwners = map (program: {
|
|
|
|
inherit program;
|
|
|
|
owner = "atd";
|
|
|
|
group = "atd";
|
|
|
|
setuid = true;
|
|
|
|
setgid = true;
|
2013-04-27 20:42:03 +00:00
|
|
|
}) [ "at" "atq" "atrm" "batch" ];
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
environment.systemPackages = [ at ];
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2013-10-15 12:47:51 +00:00
|
|
|
security.pam.services.atd = {};
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "atd";
|
|
|
|
uid = config.ids.uids.atd;
|
|
|
|
description = "atd user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 14:49:14 +00:00
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = "atd";
|
|
|
|
gid = config.ids.gids.atd;
|
|
|
|
};
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-10-12 18:09:34 +00:00
|
|
|
jobs.atd =
|
2013-01-10 12:59:41 +00:00
|
|
|
{ description = "Job Execution Daemon (atd)";
|
2009-08-21 00:02:45 +00:00
|
|
|
|
2010-10-05 14:22:06 +00:00
|
|
|
startOn = "stopped udevtrigger";
|
2009-08-21 00:02:45 +00:00
|
|
|
|
2011-11-25 16:32:54 +00:00
|
|
|
path = [ at ];
|
|
|
|
|
2009-08-21 00:02:45 +00:00
|
|
|
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
|
2010-07-13 09:23:35 +00:00
|
|
|
mkdir -p "$dir"
|
|
|
|
chown atd:atd "$dir"
|
2009-08-21 00:02:45 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
chmod 1770 "$spooldir" "$jobdir"
|
|
|
|
${if cfg.allowEveryone then ''chmod a+rwxt "$spooldir" "$jobdir" '' else ""}
|
|
|
|
if [ ! -f "$etcdir"/at.deny ]; then
|
2010-07-13 09:23:35 +00:00
|
|
|
touch "$etcdir"/at.deny
|
|
|
|
chown root:atd "$etcdir"/at.deny
|
2009-08-21 00:02:45 +00:00
|
|
|
chmod 640 "$etcdir"/at.deny
|
|
|
|
fi
|
|
|
|
if [ ! -f "$jobdir"/.SEQ ]; then
|
2010-07-13 09:23:35 +00:00
|
|
|
touch "$jobdir"/.SEQ
|
|
|
|
chown atd:atd "$jobdir"/.SEQ
|
2009-08-21 00:02:45 +00:00
|
|
|
chmod 600 "$jobdir"/.SEQ
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2011-11-25 16:32:54 +00:00
|
|
|
exec = "atd";
|
2010-10-05 14:22:06 +00:00
|
|
|
|
|
|
|
daemonType = "fork";
|
2009-08-16 14:49:14 +00:00
|
|
|
};
|
2009-01-02 16:07:10 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-04-01 10:16:35 +00:00
|
|
|
}
|