我尝试将我的nixops
版本从 1.7 迁移到nixops_unstable
2.0.0-pre-7220cbd。安装后,nixops_unstable
我无法再使用以下nixops
命令:
$ 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
我想这里最重要的部分是ValueError: Neither flake.nix nor nixops.nix exists in /home/matthias/nixops
。没错,我从来没有,nixops.nix
但这个部署是在中定义的/home/matthias/nixops/streaming.nix
。
目前我不想迁移到使用薄片,我只是尝试使用现有的方法nixops_unstable
。
更改streaming.nix
为nixops.nix
不起作用,可能是因为它无法将其现有状态与这个新文件名关联起来,因为该文件实际上是 nixop 状态的一部分:
{
"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"
}
}
我发现的有关迁移的文档非常稀少:https://nixops.readthedocs.io/en/latest/manual/migrating.html或多或少我只能发现,我必须定义network.storage.legacy = {}
哪些不能解决我的迁移问题。
我如何从 更改<deployment>.nix
为nixops.nix
?我如何区分用于对类似服务器进行分组的不同部署?
答案1
我通过对每个部署执行以下步骤完成了转换:
- 我将文件移动
${deploymentname}.nix
到${deploymentname}/nixops.nix
- 我使用 nixops 1.7 导出所有状态:
nixops export -d ${deploymentname} > ${deploymentname}/state.json
- 我在文件中更新了步骤 1 中移动文件的位置
${deploymentname}.json
(位于键上nixExprs
) ${deploymentname}/nixops.nix
我更新了使用相对路径引用外部文件的配置。- 我使用 nixops 2.0 导入了状态:
cd ${deploymentname}/ ; nixops import < ${deploymentname}.json
- 我重新部署:
nixops deploy -d ${deploymentname}