summary refs log tree commit diff
path: root/nixos/modules/services/scheduling
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-22 15:12:47 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-22 15:15:09 +0200
commite2b25f94347da698994a00120e79ed67f40b8f38 (patch)
treeb6666e659f2ba051f5667aa92d38ad6b87c0f449 /nixos/modules/services/scheduling
parent201f9beddbf5786262bcff11482f0aa30914bb34 (diff)
downloadnixpkgs-e2b25f94347da698994a00120e79ed67f40b8f38.tar
nixpkgs-e2b25f94347da698994a00120e79ed67f40b8f38.tar.gz
nixpkgs-e2b25f94347da698994a00120e79ed67f40b8f38.tar.bz2
nixpkgs-e2b25f94347da698994a00120e79ed67f40b8f38.tar.lz
nixpkgs-e2b25f94347da698994a00120e79ed67f40b8f38.tar.xz
nixpkgs-e2b25f94347da698994a00120e79ed67f40b8f38.tar.zst
nixpkgs-e2b25f94347da698994a00120e79ed67f40b8f38.zip
Use environment.etc to manage /etc/crontab
Otherwise, /etc/crontab won't be deleted when cron is disabled.
Diffstat (limited to 'nixos/modules/services/scheduling')
-rw-r--r--nixos/modules/services/scheduling/cron.nix19
1 files changed, 12 insertions, 7 deletions
diff --git a/nixos/modules/services/scheduling/cron.nix b/nixos/modules/services/scheduling/cron.nix
index c81d2bdefa7..a92e8b65d2a 100644
--- a/nixos/modules/services/scheduling/cron.nix
+++ b/nixos/modules/services/scheduling/cron.nix
@@ -91,9 +91,7 @@ in
 
   config = mkMerge [
 
-    { services.cron.enable = mkDefault (allFiles != []);
-
-    }
+    { services.cron.enable = mkDefault (allFiles != []); }
 
     (mkIf (config.services.cron.enable && allFiles != []) {
 
@@ -101,6 +99,17 @@ in
 
       environment.systemPackages = [ cronNixosPkg ];
 
+      environment.etc.crontab =
+        { source = pkgs.runCommand "crontabs" { inherit allFiles; }
+            ''
+              touch $out
+              for i in $allFiles; do
+                cat "$i" >> $out
+              done
+            '';
+          mode = "0600"; # Cron requires this.
+        };
+
       systemd.services.cron =
         { description = "Cron Daemon";
 
@@ -108,10 +117,6 @@ in
 
           preStart =
             ''
-              rm -f /etc/crontab
-              cat ${concatMapStrings (f: "\"${f}\" ") allFiles} > /etc/crontab
-              chmod 0600 /etc/crontab
-
               mkdir -m 710 -p /var/cron
 
               # By default, allow all users to create a crontab.  This