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