Hi all i have this in my nix file but its not working. i made a system-wide package to archive my nixos folder and called it nixos-archive but the cron job aint working
Ive tried manually running and it works: sh -c “nixos-archive >> /home/tolga/test.log run” and logs the output
#---------------------------------------------------------------------
# Back up nixos folder every 1 min (testing)
#---------------------------------------------------------------------
services.cron = {
enable = true;
systemCronJobs = [
"*/1 * * * * nixos-archive >> /home/tolga/test.log run"
];
};
Its set to 1 minute purely for testing purposes.
[tolga@HP-G800:/etc/nixos]$ sudo systemctl status cron.service
[sudo] password for tolga:
● cron.service - Cron Daemon
Loaded: loaded (/etc/systemd/system/cron.service; enabled; preset: enabled)
Active: active (running) since Sat 2023-09-16 03:49:26 AWST; 20min ago
Main PID: 124323 (cron)
IP: 0B in, 0B out
IO: 20.0K read, 0B written
Tasks: 1 (limit: 33533)
Memory: 220.0K
CPU: 27ms
CGroup: /system.slice/cron.service
└─124323 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron -n
Sep 16 03:52:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[124773]: (tolga) MAIL (mailed 122 bytes of output but got status 0x0001
)
Sep 16 03:53:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[124868]: (tolga) CMD (sudo nixos-archive >> /home/tolga/test.log)
Sep 16 03:54:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[124935]: (tolga) CMD (sudo nixos-archive >> /home/tolga/test.log)
Sep 16 03:55:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[124949]: (tolga) CMD (sudo nixos-archive >> /home/tolga/test.log)
Sep 16 03:56:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[125164]: (tolga) CMD (sudo nixos-archive >> /home/tolga/test.log)
Sep 16 03:56:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[125163]: (tolga) MAIL (mailed 122 bytes of output but got status 0x0001
)
Sep 16 03:57:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[125320]: (tolga) CMD (sudo nixos-archive >> /home/tolga/test.log)
Sep 16 03:58:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[125636]: (tolga) CMD (sudo nixos-archive >> /home/tolga/test.log)
Sep 16 03:59:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[124323]: (*system*) RELOAD (/etc/crontab)
Sep 16 03:59:01 HP-G800 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron[126824]: (tolga) CMD (sudo nixos-archive >> /home/tolga/test.log)
sudo cat /etc/crontab
SHELL=/nix/store/8fv91097mbh5049i9rglc73dx6kjg3qk-bash-5.2-p15/bin/bash
PATH=/nix/store/ffz95zaxqb2kmcb7mbl969598vchl133-system-path/bin:/nix/store/ffz95zaxqb2kmcb7mbl969598vchl133-system-path/sbin
NIX_CONF_DIR=/etc/nix
*/1 * * * * sudo nixos-archive >> /home/tolga/test.log run
ps aux | grep cron
root 124323 0.0 0.0 5508 1920 ? Ss 03:49 0:00 /nix/store/42sfnspzz0s48zlvym40f1w1j5ihdnfg-cron-4.1/bin/cron -n
tolga 127932 0.0 0.0 6512 2432 pts/0 S+ 04:17 0:00 grep cron