How to make automatic upgrades in configuration.nix work?

My configuration.nix is not succesful when I insert this automatic update?!

### automatic upgrade
  system.autoUpgrade = {
      enable = true;
      channel = "https://nixos.org/channels/nixos-22.05";
  };

Errors:

[henry@nixos:~]$ sudo nixos-rebuild switch
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:345:20:

          344| ### automatic upgrade
          345| system.autoUpgrade = {
             |                    ^
          346|   enable = true;
(use '--show-trace' to show detailed location information)
building Nix...
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:345:20:

          344| ### automatic upgrade
          345| system.autoUpgrade = {
             |                    ^
          346|   enable = true;
(use '--show-trace' to show detailed location information)
building the system configuration...
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:345:20:

          344| ### automatic upgrade
          345| system.autoUpgrade = {
             |                    ^
          346|   enable = true;
(use '--show-trace' to show detailed location information)

Why don’t you just use system.autoUpgrade.enable = true; ?

The channel is already set globally and doesn’t have to be set in configuration.nix.

Still errors:

error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:343:27:

          342|
          343| system.autoUpgrade.enable = true;
             |                           ^
(use '--show-trace' to show detailed location information)
building Nix...
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:343:27:

          342|
          343| system.autoUpgrade.enable = true;
             |                           ^
(use '--show-trace' to show detailed location information)
building the system configuration...
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:343:27:

          342|
          343| system.autoUpgrade.enable = true;
             |                           ^
(use '--show-trace' to show detailed location information)

Check for missing/surplus semicolons, brackets etc. anywhere in configuration.nix.

This happens easily and is difficult to spot.

system.stateVersion = “22.05”;

Should these be integrated to one?

It was a ‘}’ in the wrong place afterall. OMG Sorry!