2

I have an installation of nix on a Linux system, and I have added the channel nixpkgs-unstable. I can now install packages such as gcc:

% nix-env --install gcc
installing 'gcc-7.4.0'
...
created 78 symlinks in user environment

If I look into a directory such as ~/.nix-defexpr/channels/nixpkgs/pkgs/development/compilers/gcc/, I will discover that there is a variety of versions, all complete with default.nix.

  • How can I discover these hidden package versions with ghc-env --query, or some other friendly tool?

  • Suppose I wish to install gcc version 8 to my user environment, how should I go about it? Can I obtain several versions of gcc at once?

I have been browsing the voluminous documentation of Nix, but everywhere they say something along the lines of "with Nix, you can install any number of versions at once and they will never conflict" and at the same time "you are supposed to only install one version at a time, that is hardcoded in your channel of choice". What sense does it make?

1

I'd suggest to use attribute paths, e.g. nix-env -iA nixpkgs.gcc8 in your case where "nixpkgs" is because you named your channel that way (NixOS users will typically use "nixos" name). The attribute paths are unambigous, contrary to normal names.

How to discover these? One way is e.g. adding -P to nix-env -qa queries. I usually use tab-completion in nix repl or browse the all-packages.nix file :-) (unless I know or attempt to guess the attrpath)

Side notes:

  • If you tried to have multiple versions in a single profile at once (e.g. by nix-env), you would normally get conflicts when creating the profile's symlink tree unless you set priorities.
  • Inside a single channel version (i.e. nixpkgs commit), we try to keep the number of versions and configurations of each package at minimum, usually just one. That's motivated by saving resources (to build and distribute the binaries) and better quality/maintenance.
  • Thank you. Unfortunately, -P still does not list multiple versions of the same package. (Perhaps it should?) Can you please elaborate how to use nix repl for this? Also, how can I set these priorities? For instance, I installed gcc8 and now gcc symlinks to this. Do I have to create links, such as gcc-7.4.0, gcc-8.3.0 and so on, by hand? – Ignat Insarov Jul 9 at 21:41
  • Also, this method will not work with, for instance, ghc, because there I have several versions of .nix files rather than directories, each with a default.nix. I cannot select any of them with nix-env. – Ignat Insarov Jul 10 at 3:25
  • nix-env -qaP | grep 'gcc[0-9]\>' shows five different versions for me. It's true not everything is showed by nix-env, with haskellPackages being a notable example - but note that isn't due to directory structure but explicit dontRecurseIntoAttrs request in the sources. – Vladimír Čunát Jul 10 at 20:43
  • You are right. I must have done something wrong the last time I was checking. – Ignat Insarov Jul 10 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.