Symphorien (talk | contribs) (mention home-manager as a possible declarative setup in addition to the pure nix solution.) |
(Add warning about the new wiki) |
||
Line 1: | Line 1: | ||
+ | {{warning|1=You are reading an article on the deprecated unofficial wiki. For the up to date version of this article, see https://wiki.nixos.org/wiki/FAQ/Why_not_use_nix-env_-i_foo?.}} | ||
+ | |||
{{FAQ/breadcrumb}}{{#tweekihide:firstHeading}}<onlyinclude> | {{FAQ/breadcrumb}}{{#tweekihide:firstHeading}}<onlyinclude> | ||
== Why not use nix-env -i hello? == | == Why not use nix-env -i hello? == |
Revision as of 16:29, 4 April 2024
Why not use nix-env -i hello?
nix-env -i hello
is slower and tends to be less precise than nix-env -f '<nixpkgs>' -iA hello
. This is because it will evaluate all of nixpkgs searching for packages with the name hello
, and install the one determined to be the latest (which may not even be the one that you want). Meanwhile, with -A
, nix-env will evaluate only the given attribute in nixpkgs. This will be significantly faster, consume significantly less memory, and more likely get you what you want.
nix-env -u
has the same problem, searching for all the packages in the user environment by name and upgrading them. This may lead to unwanted major-version upgrades like JDK 8 → JDK 9. If you want to have a declarative user environment, you may wish to use Home Manager. It is also possible to home-bake a pure nix solution like LnL's. With this setup, you can update your packages by simply running nix-rebuild
.