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 92 config = mkMerge [ 93 94 - { services.cron.enable = mkDefault (allFiles != []); 95 - 96 - } 97 98 (mkIf (config.services.cron.enable && allFiles != []) { 99 ··· 101 102 environment.systemPackages = [ cronNixosPkg ]; 103 104 systemd.services.cron = 105 { description = "Cron Daemon"; 106 ··· 108 109 preStart = 110 '' 111 - rm -f /etc/crontab 112 - cat ${concatMapStrings (f: "\"${f}\" ") allFiles} > /etc/crontab 113 - chmod 0600 /etc/crontab 114 - 115 mkdir -m 710 -p /var/cron 116 117 # By default, allow all users to create a crontab. This
··· 91 92 config = mkMerge [ 93 94 + { services.cron.enable = mkDefault (allFiles != []); } 95 96 (mkIf (config.services.cron.enable && allFiles != []) { 97 ··· 99 100 environment.systemPackages = [ cronNixosPkg ]; 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 + 113 systemd.services.cron = 114 { description = "Cron Daemon"; 115 ··· 117 118 preStart = 119 '' 120 mkdir -m 710 -p /var/cron 121 122 # By default, allow all users to create a crontab. This