2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2008-04-01 11:16:35 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-08-16 15:49:14 +01:00
|
|
|
|
2009-01-02 16:07:10 +00:00
|
|
|
let
|
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
cfg = config.services.atd;
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
inherit (pkgs) at;
|
|
|
|
|
2008-04-01 11:16:35 +01:00
|
|
|
in
|
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
{
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
###### interface
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
services.atd.enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2013-06-01 10:38:49 +01:00
|
|
|
default = false;
|
2009-08-16 15:49:14 +01:00
|
|
|
description = ''
|
2013-10-30 16:37:45 +00:00
|
|
|
Whether to enable the <command>at</command> daemon, a command scheduler.
|
2009-08-16 15:49:14 +01:00
|
|
|
'';
|
|
|
|
};
|
2008-04-01 11:16:35 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
services.atd.allowEveryone = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2009-08-16 15:49:14 +01: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 15:49:14 +01:00
|
|
|
'';
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
###### implementation
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
config = mkIf cfg.enable {
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2017-10-15 10:20:11 +01:00
|
|
|
# Not wrapping "batch" because it's a shell script (kernel drops perms
|
|
|
|
# anyway) and it's patched to invoke the "at" setuid wrapper.
|
2017-02-15 07:25:59 +00:00
|
|
|
security.wrappers = builtins.listToAttrs (
|
|
|
|
map (program: { name = "${program}"; value = {
|
|
|
|
source = "${at}/bin/${program}";
|
2009-08-16 15:49:14 +01:00
|
|
|
owner = "atd";
|
|
|
|
group = "atd";
|
|
|
|
setuid = true;
|
|
|
|
setgid = true;
|
2017-10-15 10:20:11 +01:00
|
|
|
};}) [ "at" "atq" "atrm" ]);
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2009-08-16 15:49:14 +01:00
|
|
|
environment.systemPackages = [ at ];
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2013-10-15 13:47:51 +01:00
|
|
|
security.pam.services.atd = {};
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.users.atd =
|
2021-08-08 13:00:00 +01:00
|
|
|
{
|
|
|
|
uid = config.ids.uids.atd;
|
|
|
|
group = "atd";
|
2009-08-16 15:49:14 +01:00
|
|
|
description = "atd user";
|
|
|
|
home = "/var/empty";
|
|
|
|
};
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.groups.atd.gid = config.ids.gids.atd;
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.atd = {
|
|
|
|
description = "Job Execution Daemon (atd)";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
path = [ at ];
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-05-01 14:15:01 +01:00
|
|
|
install -dm755 -o atd -g atd "$etcdir"
|
|
|
|
spool_and_job_dir_perms=${if cfg.allowEveryone then "1777" else "1770"}
|
|
|
|
install -dm"$spool_and_job_dir_perms" -o atd -g atd "$spooldir" "$jobdir"
|
2016-01-06 06:50:18 +00:00
|
|
|
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-01-02 16:07:10 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
script = "atd";
|
2009-01-02 16:07:10 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
};
|
|
|
|
};
|
2008-04-01 11:16:35 +01:00
|
|
|
}
|