Nix: [Question] How to use <pkg>.override with nix-build?

Created on 9 Jun 2017  Â·  3Comments  Â·  Source: NixOS/nix

Is is possible to override a derivation directly in a nix-build command?
I am trying to do something like:

$ nix-build -A 'nginx.override{ openssl = libressl; }'
error: attribute ‘override{ openssl = libressl; }’ in selection path ‘nginx.override{ openssl = libressl; }’ not found

As a comparison, overriding is working fine with nix-shell:

$ nix-shell -p 'nginx.override{ openssl = libressl; }' --run "nginx -V"
nginx version: nginx/1.12.0
built by gcc 5.4.0 (GCC)
built with LibreSSL 2.5.4
...

Most helpful comment

nix-build -A expects an attribute path; instead try something like

nix-build -E 'with (import <nixpkgs>{}); nginx.override { openssl = libressl; }'`

All 3 comments

nix-build -A expects an attribute path; instead try something like

nix-build -E 'with (import <nixpkgs>{}); nginx.override { openssl = libressl; }'`

Thanks, that made the trick!
It would be nice if the new cli could provide a simpler way to do this.

BTW, the fact that it works with nix-shell -p is really a bug/accident. It just pastes the argument into a Nix expression that it constructs, rather than parsing it properly as an attribute.

Was this page helpful?
0 / 5 - 0 ratings