Package Management This chapter discusses how to do package management with Nix, i.e., how to obtain, install, upgrade, and erase components. This is the user's perspective of the Nix system — people who want to create components should consult . Basic package management The main command for package management is nix-env. You can use it to install, upgrade, and erase components, and to query what components are installed or are available for installation. In Nix, different users can have different views on the set of installed applications. That is, there might be lots of applications present on the system (possibly in many different versions), but users can have a specific selection of those active — where active just means that it appears in a directory in the user's PATH. Such a view on the set of installed applications is called a user environment, which is just a directory tree consisting of symlinks to the files of the active applications. In Nix, operations such as upgrading or removing components never overwrite or remove the files of those components, and they don't even touch the user environments that point to them. Rather, they cause a new user environment to be constructed based on the old one. Components are installed from a set of Nix expressions that tell Nix how to build those components, including, if necessary, their dependencies. There is a collection of Nix expressions called the Nix Package collection that contains components ranging from basic development stuff such as GCC and Glibc, to end-user applications like Mozilla Firefox. (Nix is however not tied to the Nix Package collection; you could write your own Nix expression based on that, or completely new.) You can download the latest version from . You probably want the latest unstable release; currently the stable releases tend to lag behind quite a bit. Assuming that you have downloaded and unpacked a release of Nix Packages, you can view the set of available components in the release: $ nix-env -qaf nixpkgs-version ant-blackdown-1.4.2 aterm-2.2 bash-3.0 binutils-2.15 bison-1.875d blackdown-1.4.2 bzip2-1.0.2 ... where nixpkgs-version is where you've unpacked the release. It is also possible to see the status of available component, i.e., whether they are installed into the user environment and/or present in the system: $ nix-env -qasf nixpkgs-version ... -PS bash-3.0 --S binutils-2.15 IPS bison-1.875d ... The first character (I) indicates whether the component is installed in your current user environment. The second (P) indicates whether it is present on your system (in which case installing it into your user environment would be very quick). The last one (S) indicates whether there is a so-called substitute for the component, which is Nix's mechanism for doing binary deployment. It just means that Nix know that it can fetch a pre-built component from somewhere (typically a network server) instead of building it locally. So now that we have a set of Nix expressions we can build the components contained in them. This is done using nix-env -i. For instance, $ nix-env -f nixpkgs-version -i subversion will install the component called subversion (which is, of course, the Subversion version management system). When you do this for the first time, Nix will start building Subversion and all its dependencies. This will take quite a while — typically an hour or two on modern machines. Fortunately, there is a faster way (so just do a Ctrl-C on that install operation!): you just need to tell Nix that pre-built binaries of all those components are available somewhere. This is done using the nix-pull command, which must be supplied with a URL containing a manifest describing what binaries are available. This URL should correspond to the Nix Packages release that you're using. For instance, if you obtained a release from , then you should do: $ nix-pull http://catamaran.labs.cs.uu.nl/dist/nix/nixpkgs-0.6pre1554/MANIFEST If you then issue the installation command, it should start downloading binaries from catamaran.labs.cs.uu.nl, instead of building them from source. This might still take a while since all dependencies must be downloaded, but on a reasonably fast connection such as an ADSL line it's on the order of a few minutes. Naturally, packages can also be uninstalled: $ nix-env -e subversion Upgrading to a new version is just as easy. If you have a new release of Nix Packages, you can do: $ nix-env -f nixpkgs-version -u subversion This will only upgrade Subversion if there is a newer version in the new set of Nix expressions, as defined by some pretty much arbitrary rules regarding ordering of version numbers (which generally do what you'd expect of them). To just unconditionally replace Subversion with whatever version is in the Nix expressions, use -i instead of -u-i will remove whatever version is already installed. You can also upgrade all components for which there are newer versions: $ nix-env -f nixpkgs-version -u '*' If you grow tired of specifying the Nix expressions using -f all the time, you can set a default location: $ nix-env -I nixpkgs-version After this you can just say, for instance, nix-env -u '*'.Setting a default using -I currently clashes with using Nix channels, since nix-channel --update calls nix-env -I to set the default to the Nix expressions it downloaded from the channel, replacing whatever default you had set. Profiles Bla Garbage collection Bla Channels Bla