Use environment.etc to manage /etc/crontab

Otherwise, /etc/crontab won't be deleted when cron is disabled.

+12 -7
+12 -7
nixos/modules/services/scheduling/cron.nix
··· 91 91 92 92 config = mkMerge [ 93 93 94 - { services.cron.enable = mkDefault (allFiles != []); 95 - 96 - } 94 + { services.cron.enable = mkDefault (allFiles != []); } 97 95 98 96 (mkIf (config.services.cron.enable && allFiles != []) { 99 97 ··· 101 99 102 100 environment.systemPackages = [ cronNixosPkg ]; 103 101 102 + environment.etc.crontab = 103 + { source = pkgs.runCommand "crontabs" { inherit allFiles; } 104 + '' 105 + touch $out 106 + for i in $allFiles; do 107 + cat "$i" >> $out 108 + done 109 + ''; 110 + mode = "0600"; # Cron requires this. 111 + }; 112 + 104 113 systemd.services.cron = 105 114 { description = "Cron Daemon"; 106 115 ··· 108 117 109 118 preStart = 110 119 '' 111 - rm -f /etc/crontab 112 - cat ${concatMapStrings (f: "\"${f}\" ") allFiles} > /etc/crontab 113 - chmod 0600 /etc/crontab 114 - 115 120 mkdir -m 710 -p /var/cron 116 121 117 122 # By default, allow all users to create a crontab. This