system.stateVersion with NixOps

I am using NixOps to deploy a server. Before the first nixops deploy, the server NixOS version was 19.09 and NixOps successfully noticed that:

$ nixops --version
NixOps 1.7
$ nixops show-physical -d mydeployment
{
  server = { config, lib, pkgs, ... }: {
    config = {
      boot.kernelModules = [];
      networking = {
        extraHosts = "127.0.0.1 applicationServer-encrypted\n";
        firewall.trustedInterfaces = [];
        vpnPublicKey = "ssh-ed25519 […] NixOps VPN key of server";
      };
      system.stateVersion = ( lib.mkDefault "19.09" );
    };
    imports = [
      {
        config.users.extraUsers.root.openssh.authorizedKeys.keys = [
          "ssh-ed25519 […] NixOps client key for server"
        ];
      }
    ];
  };
}

The value is indeed 19.09:

$ nixops info -d mydeployment
[…]
Nix path: -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-19.09-small.tar.gz
[…]
$ nixops show-option -d mydeployment server system.stateVersion
"19.09"

However, when I use the nixos-20.03-small channel, the value is changed to 20.03:

$ nixops info -d mydeployment
[…]
Nix path: -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-20.03-small.tar.gz
[…]
$ nixops show-option -d mydeployment server system.stateVersion
"20.03"

I do not set system.stateVersion in my deployment files. Why doesn’t the value stay at 19.09?

Are you able to run nixops show-physical -d mydeployment after you’ve updated your nix path? I expect the line system.stateVersion = ( lib.mkDefault "19.09" ); to be different.

It looks like NixOps sets the stateVersion based on the NixOS version https://github.com/NixOS/nixops/blob/890722355db83bb9894276c4f236ad49183fc8c2/nixops/deployment.py#L604

You should probably be doing system.stateVersion = "19.09"; in your own configuration. (Until you’ve verified that there are no state-based migrations between 19.09 and 20.03 that you need to take care of.)

Running nixops show-physical -d mydeployment after returns the same as before I updated the nix path.

https://github.com/NixOS/nixops/issues/1340