Nixops2 deploy flakes

Since the tip from my earlier question:
I’ve decided to migrate to using flakes, and added experimental-features = nix-command flakes to /etc/nix/nix.conf as instructed.

Next, I’ve figured out how to install nixops2:
nix-env -i nixops-with-plugins will install v2.0.0 (at time of writing)
nix-env -i nixops will install v1.7 (at time of writing)

edit: Nixops2 will revert nix from v2.6.0 to v2.4 on install, so I ran nix upgrade-nix to get back to v2.6.0.

Now, my current nixops.nix with the added = {}; gives the error: Exception: could not find specified deployment in state file ‘/tmp/tmp88u3n4lknixops/state.nixops’ I’m not sure why it would look in a tmp directory? Do I perhaps have to explicitly provide the location of the default legacy SQLite database?
Simply chaning it to = {}; seems to work without error.

Unfortunately I run into another error when using flake.nix:

nixops deploy
error: flake 'path:/workspaces/deployments/local-vms' requires lock file changes but they're not allowed due to '--no-update-lock-file'

nixops deploy --recreate-lock-file
usage: nixops [-h] [--version] [--pdb] operation ...
nixops: error: unrecognized arguments: --recreate-lock-file

How to proceed?

Ok, from this issue I figured to try running nix flake lock & nix flake update which resolves the problem above :slight_smile:

And with a lot of trial and error to resolve this error:
I figured I could try

inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11";
outputs = { self, nixpkgs, ... }: {
        nixopsConfigurations.default = {
                inherit nixpkgs;

Which outputs:

WARNING: NixOps 1.0 -> 2.0 conversion step required

NixOps 2.0 added support for multiple storage backends.

Upgrade steps:
1. Open /workspaces/deployments/local-vms
2. Add: = {
      databasefile = "~/.nixops/deployments.nixops";
3. Rerun

See for more guidance.

which relates to the question above about the location of the nixops state.

When I then add: = {
    databasefile = "~/.nixops/deployments.nixops";

I get the same error as before:

Exception: could not find specified deployment in state file ‘/tmp/tmps5ws3p5znixops/state.nixops’

So I feel like I’m making progress, but also that I’m a bit stuck.

I suspect the issue could be related to the ~/.nixops/... path being a bit indeterminate?

Note that it’s possible to export the state to json. I think roughly something like

nixops export -d my-deployment > legacy-state.json

To import to a relative ./state.nixops, use NIXOPS_STATE

NIXOPS_STATE=$(pwd)/state.nixops nixops import -d my-new-deployment < legacy-state.json
NIXOPS_STATE=$(pwd)/state.nixops nixops info -d my-new-deployment

Not sure if thats what you would want, but thought it might be helpful to be aware of export/import if you aren’t