-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
network: Add nixpkgs attribute for passing custom nixpkgs #1369
Conversation
6244143
to
4a55a21
Compare
Is using this as simple as setting Would be nice if there were some docs to accompany this describing how to use it -- feel free to take inspiration from my suggestion over at #1331. |
An example of how to use this is: {
network.description = "Test deployment";
network.nixpkgs = import <nixpkgs> {};
myhost = { config, lib, resources, ... }: {};
} |
4a55a21
to
ecbe11b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this branch, if I set network.nixpkgs = import sources.nixpkgs { };
and I run NIX_PATH= nixops deploy --dry-activate
, I get the following error:
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)
Traceback (most recent call last):
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/bin/.nixops-wrapped", line 9, in <module>
sys.exit(main())
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/__main__.py", line 710, in main
args.op(args)
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/script_defs.py", line 638, in op_deploy
max_concurrent_activate=args.max_concurrent_activate,
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/deployment.py", line 1418, in deploy
self.run_with_notify("deploy", lambda: self._deploy(**kwargs))
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/deployment.py", line 1407, in run_with_notify
f()
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/deployment.py", line 1418, in <lambda>
self.run_with_notify("deploy", lambda: self._deploy(**kwargs))
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/deployment.py", line 1334, in _deploy
dry_run=dry_run, repair=repair, include=include, exclude=exclude
File "/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/deployment.py", line 761, in build_configs
text=True,
File "/nix/store/q732h09azy7lf0j30bnnhdl15p4rxpdy-python3-3.7.7/lib/python3.7/subprocess.py", line 411, in check_output
**kwargs).stdout
File "/nix/store/q732h09azy7lf0j30bnnhdl15p4rxpdy-python3-3.7.7/lib/python3.7/subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['nix-instantiate', '--find-file', 'nixpkgs/nixos', '-I', 'nixops=/nix/store/50l5y9imknxf9hx58kmy46ffbfwhf32q-python3.7-nixops-1.8.0/lib/python3.7/site-packages/nixops/../nix']' returned non-zero exit status 1.
This appears to stem from
Line 759 in 231e43f
["nix-instantiate", "--find-file", "nixpkgs/nixos"] |
I fixed my previous issue with the following diff. However, note that it's very brittle -- it relies on diff --git a/nixops/deployment.py b/nixops/deployment.py
index b3ccb40f..bc389237 100644
--- a/nixops/deployment.py
+++ b/nixops/deployment.py
@@ -360,6 +360,18 @@ class Deployment:
path for paths in get_plugin_manager().hook.nixexprs() for path in paths
]
+ nixpkgs_path = subprocess.run(
+ [
+ "nix-instantiate",
+ "--eval",
+ # FIXME: self.nix_exprs[0] is not guaranteed to always work
+ "-E" "(import {0}).network.nixpkgs.path".format(self.nix_exprs[0]),
+ ],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.DEVNULL,
+ text=True,
+ ).stdout.rstrip()
+
flags = (
list(
itertools.chain(
@@ -371,6 +383,9 @@ class Deployment:
)
+ self.extra_nix_flags
)
+ flags.extend(
+ ["-I", "nixpkgs=" + nixpkgs_path] if nixpkgs_path is not "" else []
+ )
flags.extend(["-I", "nixops=" + self.expr_path])
return flags
|
Is anything blocking this? |
Looking up NIX_PATH is no longer a viable solution as we have both flakes & network.nixpkgs to describe how to find nixpkgs.
ecbe11b
to
9294637
Compare
This is useful to pin nixpkgs without flakes.