NixOS / nixops

NixOps is a tool for deploying to NixOS machines in a network or cloud.
https://nixos.org/nixops
GNU Lesser General Public License v3.0
1.84k stars 363 forks source link

Documentation is not clear on how to fix nixpkgs version #452

Open expipiplus1 opened 8 years ago

expipiplus1 commented 8 years ago

Is it correct that the best way to use a specific version of nixpkgs for a deployment is to only call nixops with NIX_PATH=nixpkgs=/my/specific/version

It would be nice to be able to specify nixpkgs in the network configuration.

domenkozar commented 8 years ago

You can also pass -I /my/specific/version parameter. But I agree it should be documented as it's very common use case.

domenkozar commented 7 years ago

I wrote a bit about this in http://nix-cookbook.readthedocs.io/en/latest/faq.html#how-to-pin-nixpkgs-to-a-specific-commit-branch

chris-martin commented 6 years ago

Do any of these options let you specify a sha256 hash for nixpkgs?

domenkozar commented 6 years ago

https://github.com/NixOS/nixpkgs/pull/30399 seems to be the best solution so far

dhess commented 6 years ago

@domenkozar How does one use something like https://github.com/input-output-hk/iohk-ops/blob/develop/fetch-nixpkgs.nix or https://nixos.wiki/wiki/How_to_fetch_Nixpkgs_with_an_empty_NIX_PATH with NixOps? As far as I can tell, NixOps needs NIX_PATH and there is no way to pass it an expression to evaluate.

cleverca22 commented 6 years ago

i think nixops set-args -I nixpkgs=fetch-nixpkgs.nix would work, as long as that fetch file returns a path, but that requires some imperative setup for each new deployment

dhess commented 6 years ago

@cleverca22 I just tried that, but set-args seems to ignore the -I flag. The command you suggested did not change the state file at all. If I provide a dummy argument like --arg foo 10, it sets that attribute in the state file, but it still does not add a nixPath attribute.

I created a test deployment from scratch using https://github.com/input-output-hk/iohk-ops/blob/develop/fetch-nixpkgs.nix:

nixops create -d production.example.org "<machines/example.org.org.nix>" "<machines/production.example.org.nix>" -I "nixpkgs=fetch-nixpkgs.nix" -s test.nixops

That does set nixPath in the state file, but NixOps still complains that it can't find the Nix search path when I try to deploy:

error: file ‘nixpkgs/nixos/lib/testing.nix’ was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/store/cyq3cbka33lyp3kwx6cwdn46xi9z2iv7-nixops-1.6pre0_abcdef/share/nix/nixops/eval-machine-info.nix:9:13

cleverca22 commented 6 years ago

ah yeah, the trick i gave only works for import <nixpkgs> but it wont work for <nixpkgs/nixos/lib/testing.nix>

dhess commented 6 years ago

I already have a script wrapper around NixOps to import/export deployment state as JSON, to make certain kinds of errors less likely, etc.; so I've effectively achieved the same thing in the script by using the path that nix-build --no-out-link fetch-nixpkgs.nix prints to stdout as part of the NIX_PATH environment variable passed to nixops.

🎉

It would be nice if this were possible natively, though!

domenkozar commented 6 years ago

nixops .. -I nixpkgs=$(nix-build --no-out-link fetch-nixpkgs.nix) should work, but I haven't tested that :)

dhess commented 6 years ago

@domenkozar Ahh yes, of course! That is almost exactly what I'm doing in my wrapper script, in fact, just with more intermediate steps.