Automatic system upgrades: Difference between revisions

From NixOS Wiki
imported>Onny
Add usage examples
imported>IgorM
m Added category
Line 30: Line 30:
# systemctl status nixos-upgrade.service
# systemctl status nixos-upgrade.service
</syntaxhighlight>
</syntaxhighlight>
[[Category:NixOS]]

Revision as of 09:21, 27 September 2023

Automatic system upgrades can be used to upgrade a system regularly at a specific time. This can help to reduce the time period of applying important security patches to your running software but might also introduce some breakage in case an automatic upgrade fails.

Configuration

To enable unattended automatic system updates on a flake-enabled host, add following part to your configuration:

/etc/nixos/configuration.nix
system.autoUpgrade = {
  enable = true;
  flake = inputs.self.outPath;
  flags = [
    "--update-input"
    "nixpkgs"
    "-L" # print build logs
  ];
  dates = "02:00";
  randomizedDelaySec = "45min";
};

To see the status of the timer run

# systemctl status nixos-upgrade.timer

The upgrade log can be printed with this command

# systemctl status nixos-upgrade.service