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 security.setuidOwners = map (program: { 46 inherit program; 47 owner = "atd"; 48 group = "atd"; 49 setuid = true; 50 setgid = true; 51 }) [ "at" "atq" "atrm" "batch" ]; 52 53 environment.systemPackages = [ at ]; 54 55 security.pam.services.atd = {}; 56 57 users.extraUsers = singleton 58 { name = "atd"; 59 uid = config.ids.uids.atd; 60 description = "atd user"; 61 home = "/var/empty"; 62 }; 63 64 users.extraGroups = singleton 65 { name = "atd"; 66 gid = config.ids.gids.atd; 67 }; 68 69 systemd.services.atd = { 70 description = "Job Execution Daemon (atd)"; 71 after = [ "systemd-udev-settle.service" ]; 72 wants = [ "systemd-udev-settle.service" ]; 73 wantedBy = [ "multi-user.target" ]; 74 75 path = [ at ]; 76 77 preStart = '' 78 # Snippets taken and adapted from the original `install' rule of 79 # the makefile. 80 81 # We assume these values are those actually used in Nixpkgs for 82 # `at'. 83 spooldir=/var/spool/atspool 84 jobdir=/var/spool/atjobs 85 etcdir=/etc/at 86 87 for dir in "$spooldir" "$jobdir" "$etcdir"; do 88 if [ ! -d "$dir" ]; then 89 mkdir -p "$dir" 90 chown atd:atd "$dir" 91 fi 92 done 93 chmod 1770 "$spooldir" "$jobdir" 94 ${if cfg.allowEveryone then ''chmod a+rwxt "$spooldir" "$jobdir" '' else ""} 95 if [ ! -f "$etcdir"/at.deny ]; then 96 touch "$etcdir"/at.deny 97 chown root:atd "$etcdir"/at.deny 98 chmod 640 "$etcdir"/at.deny 99 fi 100 if [ ! -f "$jobdir"/.SEQ ]; then 101 touch "$jobdir"/.SEQ 102 chown atd:atd "$jobdir"/.SEQ 103 chmod 600 "$jobdir"/.SEQ 104 fi 105 ''; 106 107 script = "atd"; 108 109 serviceConfig.Type = "forking"; 110 }; 111 }; 112}