ive got a surface tablet at work running nixos. it mostly is used to view security cameras.

the machine is fairly low spec and bogs itself down after a coupke days, so id like it to auto reboot at 9am. i work a late shift and often don't leave til around 2am.

i guess we don't use cron anymore? i really don't understand how the systemd timers work... the wiki doesnt really give great details...

systemd.timers."autoreboot" = {

wantedBy = [ "timers.target" ];

timerConfig = {

  OnCalendar="*-*-* 9:00:00";                                     Unit = "autoreboot.service";

};

};

systemd.services."autoreboot" = {

script = ''

set -eu

${pkgs.coreutils}/run/current-system/sw/bin/reboot

'';

serviceConfig = {

Type = "oneshot";

User = "root";

};

};

the systemd target seems to be created, but it reports as dead when i check it...

any advice?

you are viewing a single comment's thread
view the rest of the comments
[–] 10 points 3 months ago (3 children)

This line:

${pkgs.coreutils}/run/current-system/sw/bin/reboot

is incorrect, as you've mixed a package path with an absolute path. Additionally, on my system at least, reboot is a part of pkgs.systemd and not pkgs.coreutils.

So this should work:

${pkgs.systemd}/bin/reboot

Or, since systemd is always installed on NixOS systems, you can use the absolute wrapper path:

/run/current-system/sw/bin/reboot
  • source
  • hideshow 3 child comments
  • [–] [S] 4 points 3 months ago (2 children)

    excellent, thank you! in the future, how would i determine which package and path to use?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 6 points 3 months ago (1 child)

    For installed packages, you can use readlink:

    $ readlink $(type -P reboot)
    /nix/store/axx9bvf0dmah41f39ds9xdkds1lsz6z9-systemd-261/bin/reboot
    

    The NixOS search can also search for binaries. It seems that busybox also provides a reboot which I guess might be useful for weird systemd-less deployments?

    If you want to search for any file across all packages, there's also nix-index, which scrapes Hydra for output files and builds a database which you can then query with nix-locate.

  • source
  • parent
  • hideshow 1 child comment