NixOS generally uses
systemd which provides “Timers” as a replacement for
cron. However, for your convenience, regular cron is available on NixOS
User crontabs are not managed within the NixOS configuration model: there is no versioning and no atomic loading. Use systemd timers instead, if you can.
Installing user crontabs¶
You can edit a user’s crontab with the regular crontab command. See crontab(1) for details.
Cron jobs are executed with a rather minimal environment. The default is something like:
SHELL=/bin/sh HOME=/home/user LOGNAME=user USER=user PATH=/var/setuid-wrappers:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/run/current-system/sw/bin:/run/current-system/sw/sbin
Often, this set of environment variables is not sufficient. To get a full
environment similar to the one present in interactive sessions, prefix your
source /etc/profile;, e.g.:
* * * * * source /etc/profile; complicated_command
There is also the possibility to set custom environment variables at the top of a user crontab. See crontab(5) for details.
We advise strongly to include a line like
into the top section to get error mails delivered to an address where they are actually read and acted upon.