Best practices for auto-upgrades of flake-enabled NixOS systems?

I do it like this:

system.autoUpgrade = {
    enable = true;
    flake = inputs.self.outPath;
    flags = [
      "--update-input"
      "nixpkgs"
      "--no-write-lock-file"
      "-L" # print build logs
    ];
    dates = "02:00";
    randomizedDelaySec = "45min";
  };

This results in the following call with a systemd.timer:

nixos-rebuild switch --update-input nixpkgs --no-write-lock-file -L --flake /nix/store/<flake-source> --upgrade
13 Likes