Migration to nixops 2.0

I try to migrate my nixops from version 1.7 to nixops_unstable 2.0.0-pre-7220cbd. After installing nixops_unstable I cannot work with the nixops command anymore:

$ nixops deploy -d streaming
Traceback (most recent call last):
  File "/nix/store/diamr11y34lkmnjwkyw5qnv5xcn1x60h-python3.9-nixops-2.0.0-pre-7220cbd/bin/.nixops-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/3ybyi0v3pj8hlchzcchsx3m2myjpbmir-python3-3.9.13-env/lib/python3.9/site-packages/nixops/__main__.py", line 56, in main
    args.op(args)
  File "/nix/store/3ybyi0v3pj8hlchzcchsx3m2myjpbmir-python3-3.9.13-env/lib/python3.9/site-packages/nixops/script_defs.py", line 710, in op_deploy
    with deployment(args, True, "nixops deploy") as depl:
  File "/nix/store/gwlgfywzqypv91rxw916v81mpzhckdz5-python3-3.9.13/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/nix/store/3ybyi0v3pj8hlchzcchsx3m2myjpbmir-python3-3.9.13-env/lib/python3.9/site-packages/nixops/script_defs.py", line 72, in deployment
    with network_state(args, writable, description=activityDescription) as sf:
  File "/nix/store/gwlgfywzqypv91rxw916v81mpzhckdz5-python3-3.9.13/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/nix/store/3ybyi0v3pj8hlchzcchsx3m2myjpbmir-python3-3.9.13-env/lib/python3.9/site-packages/nixops/script_defs.py", line 102, in network_state
    network = eval_network(get_network_file(args))
  File "/nix/store/3ybyi0v3pj8hlchzcchsx3m2myjpbmir-python3-3.9.13-env/lib/python3.9/site-packages/nixops/script_defs.py", line 60, in get_network_file
    raise ValueError(f"Neither flake.nix nor nixops.nix exists in {network_dir}")
ValueError: Neither flake.nix nor nixops.nix exists in /home/matthias/nixops

I guess the important part here is ValueError: Neither flake.nix nor nixops.nix exists in /home/matthias/nixops. That’s correct, I never had nixops.nix but this deployment is defined in /home/matthias/nixops/streaming.nix.

For the moment I don’t want to migrate to using flakes, I just try to get the existing way working with nixops_unstable.

Changing streaming.nix to nixops.nix does not work, probably because it cannot relate its existing state to this new file name, as the file is actually part of nixop’s state:

{
  "c54b29a1-417e-11eb-9873-0242cc6606ab": {
    "configsPath": "/nix/store/46s4g876yjdijfdjwpqqjzj94pyp05lz-nixops-machines", 
    "name": "streaming", 
    "nixExprs": "[\"/home/matthias/nixops/streaming.nix\"]", 
    "resources": {
      "styx": {
        "configsPath": "/nix/store/46s4g876yjdijfdjwpqqjzj94pyp05lz-nixops-machines", 
        "creationTime": "1608329862", 
        "index": "0", 
        "keys": "XXXXXXXX", 
        "none.sshPrivateKey": "XXXXXXXX\n", 
        "none.sshPublicKey": "XXXXXXXX", 
        "none.sshPublicKeyDeployed": "1", 
        "publicVpnKey": "XXXXXXXX", 
        "sshPinged": "1", 
        "state": "3", 
        "stateVersion": "20.09", 
        "targetHost": "styx.p7m.de", 
        "toplevel": "/nix/store/hjlv7mlp71rij4vn3dhvr6rxickldjaa-nixos-system-styx-22.05.915.9ff91ce2e4c", 
        "type": "none", 
        "vmId": "nixops-c54b29a1-417e-11eb-9873-0242cc6606ab-styx"
      }
    }, 
    "rollbackEnabled": "1"
  }
}

The documentation on migration I found is very sparse: https://nixops.readthedocs.io/en/latest/manual/migrating.html. More or less I could only find, that I have to define network.storage.legacy = {} which does not solve my migration problem.

How do I change from <deployment>.nix to nixops.nix? How do I separate between different deployments, that I use to group similar servers?

1 Like

There might be a correct terminal command / flag to fix the renaming issue… I think nixops modify might do the trick, if my memory doesn’t fail me.

However, I just want to also quickly mention my alternative “quick fix” method for dealing with these kinds of nixops issues:

  1. nixops export to a json file
  2. look at the output and figure out what’s wrong
  3. make a backup of the statefile
  4. nixops import a modified version of the json file

(EDIT: Oops I missed that you did already inspect your state json during my skim read.)

Hi rheno,

thanks for the help. Indeed I got the conversion done by doing the following steps for each deployment:

  1. I moved the file ${deploymentname}.nix to ${deploymentname}/nixops.nix
  2. I exported all state using nixops 1.7: nixops export -d ${deploymentname} > ${deploymentname}/state.json
  3. I updated the location of the moved file from step 1 in the ${deploymentname}.json file (which is on key nixExprs)
  4. I updated the configuration in ${deploymentname}/nixops.nix where it references external files using relative paths.
  5. I imported the state using nixops 2.0: cd ${deploymentname}/ ; nixops import < ${deploymentname}.json
  6. I redeployed: nixops deploy -d ${deploymentname}
3 Likes
Hosted by Flying Circus.