2006-08-21 19:05:11 +03:00
|
|
|
|
<chapter xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
|
|
|
xml:id='chap-package-management'>
|
|
|
|
|
|
|
|
|
|
<title>Package Management</title>
|
|
|
|
|
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
2004-10-14 19:43:09 +03:00
|
|
|
|
<para>This chapter discusses how to do package management with Nix,
|
2007-12-04 13:42:58 +02:00
|
|
|
|
i.e., how to obtain, install, upgrade, and erase packages. This is
|
2005-04-10 23:54:21 +03:00
|
|
|
|
the “user’s” perspective of the Nix system — people
|
2007-12-04 13:42:58 +02:00
|
|
|
|
who want to <emphasis>create</emphasis> packages should consult
|
2004-10-14 19:43:09 +03:00
|
|
|
|
<xref linkend='chap-writing-nix-expressions' />.</para>
|
|
|
|
|
|
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
<section><title>Basic package management</title>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
2005-04-10 23:54:21 +03:00
|
|
|
|
<para>The main command for package management is <link
|
|
|
|
|
linkend="sec-nix-env"><command>nix-env</command></link>. You can use
|
2007-12-04 13:42:58 +02:00
|
|
|
|
it to install, upgrade, and erase packages, and to query what
|
|
|
|
|
packages are installed or are available for installation.</para>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
2005-04-10 23:54:21 +03:00
|
|
|
|
<para>In Nix, different users can have different “views”
|
2004-10-14 19:43:09 +03:00
|
|
|
|
on the set of installed applications. That is, there might be lots of
|
|
|
|
|
applications present on the system (possibly in many different
|
2004-10-25 19:54:56 +03:00
|
|
|
|
versions), but users can have a specific selection of those active —
|
2005-04-10 23:54:21 +03:00
|
|
|
|
where “active” just means that it appears in a directory
|
2005-03-16 16:40:48 +02:00
|
|
|
|
in the user’s <envar>PATH</envar>. Such a view on the set of
|
2004-10-25 19:54:56 +03:00
|
|
|
|
installed applications is called a <emphasis>user
|
|
|
|
|
environment</emphasis>, which is just a directory tree consisting of
|
|
|
|
|
symlinks to the files of the active applications. </para>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
|
|
|
|
<para>Components are installed from a set of <emphasis>Nix
|
2007-12-04 13:42:58 +02:00
|
|
|
|
expressions</emphasis> that tell Nix how to build those packages,
|
2004-10-14 19:43:09 +03:00
|
|
|
|
including, if necessary, their dependencies. There is a collection of
|
|
|
|
|
Nix expressions called the Nix Package collection that contains
|
2007-12-04 13:42:58 +02:00
|
|
|
|
packages ranging from basic development stuff such as GCC and Glibc,
|
2004-10-14 19:43:09 +03:00
|
|
|
|
to end-user applications like Mozilla Firefox. (Nix is however not
|
|
|
|
|
tied to the Nix Package collection; you could write your own Nix
|
2005-04-10 23:54:21 +03:00
|
|
|
|
expressions based on it, or completely new ones.) You can download
|
2006-08-21 19:05:11 +03:00
|
|
|
|
the latest version from <link
|
2010-03-16 14:58:20 +02:00
|
|
|
|
xlink:href='http://nixos.org/nixpkgs/download.html' />.</para>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
|
|
|
|
<para>Assuming that you have downloaded and unpacked a release of Nix
|
2007-12-04 13:42:58 +02:00
|
|
|
|
Packages, you can view the set of available packages in the release:
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<screen>
|
2006-09-29 14:03:16 +03:00
|
|
|
|
$ nix-env -qaf nixpkgs-<replaceable>version</replaceable> '*'
|
2004-10-14 19:43:09 +03:00
|
|
|
|
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
|
2004-10-14 14:55:12 +03:00
|
|
|
|
...</screen>
|
|
|
|
|
|
2004-10-14 19:43:09 +03:00
|
|
|
|
where <literal>nixpkgs-<replaceable>version</replaceable></literal> is
|
2006-10-02 12:01:36 +03:00
|
|
|
|
where you’ve unpacked the release. The flag <option>-q</option>
|
|
|
|
|
specifies a query operation; <option>-a</option> means that you want
|
|
|
|
|
to show the “available” (i.e., installable) packages, as opposed to
|
|
|
|
|
the installed packages; and <option>-f</option>
|
|
|
|
|
<filename>nixpkgs-<replaceable>version</replaceable></filename>
|
|
|
|
|
specifies the source of the packages. The argument
|
|
|
|
|
<literal>'*'</literal> shows all installable packages. (The quotes are
|
|
|
|
|
necessary to prevent shell expansion.) You can also select specific
|
|
|
|
|
packages by name:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env -qaf nixpkgs-<replaceable>version</replaceable> gcc
|
|
|
|
|
gcc-3.4.6
|
|
|
|
|
gcc-4.0.3
|
|
|
|
|
gcc-4.1.1</screen>
|
|
|
|
|
|
|
|
|
|
</para>
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<para>It is also possible to see the <emphasis>status</emphasis> of
|
2007-12-04 13:42:58 +02:00
|
|
|
|
available packages, i.e., whether they are installed into the user
|
2004-10-14 19:43:09 +03:00
|
|
|
|
environment and/or present in the system:
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<screen>
|
2006-09-29 14:03:16 +03:00
|
|
|
|
$ nix-env -qasf nixpkgs-<replaceable>version</replaceable> '*'
|
2004-10-14 19:43:09 +03:00
|
|
|
|
...
|
|
|
|
|
-PS bash-3.0
|
|
|
|
|
--S binutils-2.15
|
|
|
|
|
IPS bison-1.875d
|
|
|
|
|
...</screen>
|
|
|
|
|
|
|
|
|
|
The first character (<literal>I</literal>) indicates whether the
|
2007-12-04 13:42:58 +02:00
|
|
|
|
package is installed in your current user environment. The second
|
2004-10-14 19:43:09 +03:00
|
|
|
|
(<literal>P</literal>) indicates whether it is present on your system
|
2004-11-14 02:24:57 +02:00
|
|
|
|
(in which case installing it into your user environment would be a
|
|
|
|
|
very quick operation). The last one (<literal>S</literal>) indicates
|
|
|
|
|
whether there is a so-called <emphasis>substitute</emphasis> for the
|
2007-12-04 13:42:58 +02:00
|
|
|
|
package, which is Nix’s mechanism for doing binary deployment. It
|
|
|
|
|
just means that Nix knows that it can fetch a pre-built package from
|
2004-11-14 02:24:57 +02:00
|
|
|
|
somewhere (typically a network server) instead of building it
|
|
|
|
|
locally.</para>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
|
|
|
|
<para>So now that we have a set of Nix expressions we can build the
|
2007-12-04 13:42:58 +02:00
|
|
|
|
packages contained in them. This is done using <literal>nix-env
|
2004-10-14 19:43:09 +03:00
|
|
|
|
-i</literal>. For instance,
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<screen>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -i subversion</screen>
|
|
|
|
|
|
2007-12-04 13:42:58 +02:00
|
|
|
|
will install the package called <literal>subversion</literal> (which
|
2006-08-21 19:05:11 +03:00
|
|
|
|
is, of course, the <link
|
|
|
|
|
xlink:href='http://subversion.tigris.org/'>Subversion version
|
|
|
|
|
management system</link>).</para>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
|
|
|
|
<para>When you do this for the first time, Nix will start building
|
2004-10-18 15:22:14 +03:00
|
|
|
|
Subversion and all its dependencies. This will take quite a while —
|
|
|
|
|
typically an hour or two on modern machines. Fortunately, there is a
|
2004-11-14 02:24:57 +02:00
|
|
|
|
faster way (so do a Ctrl-C on that install operation!): you just need
|
2007-12-04 13:42:58 +02:00
|
|
|
|
to tell Nix that pre-built binaries of all those packages are
|
2004-10-18 15:22:14 +03:00
|
|
|
|
available somewhere. This is done using the
|
2004-10-14 19:43:09 +03:00
|
|
|
|
<command>nix-pull</command> command, which must be supplied with a URL
|
|
|
|
|
containing a <emphasis>manifest</emphasis> describing what binaries
|
|
|
|
|
are available. This URL should correspond to the Nix Packages release
|
2006-08-21 19:05:11 +03:00
|
|
|
|
that you’re using. For instance, if you obtained a release from <link
|
2008-06-09 16:42:13 +03:00
|
|
|
|
xlink:href='http://nixos.org/releases/nixpkgs/nixpkgs-0.12pre11712-4lrp7j8x'
|
|
|
|
|
/>, then you should do:
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<screen>
|
2008-06-09 16:42:13 +03:00
|
|
|
|
$ nix-pull http://nixos.org/releases/nixpkgs/nixpkgs-0.12pre11712-4lrp7j8x/MANIFEST</screen>
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
2004-10-14 19:43:09 +03:00
|
|
|
|
If you then issue the installation command, it should start
|
|
|
|
|
downloading binaries from <systemitem
|
2008-06-09 16:42:13 +03:00
|
|
|
|
class='fqdomainname'>nixos.org</systemitem>, instead of building
|
2006-08-21 19:05:11 +03:00
|
|
|
|
them from source. This might still take a while since all
|
2004-10-14 19:43:09 +03:00
|
|
|
|
dependencies must be downloaded, but on a reasonably fast connection
|
2005-03-16 16:40:48 +02:00
|
|
|
|
such as an DSL line it’s on the order of a few minutes.</para>
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
2004-10-14 19:43:09 +03:00
|
|
|
|
<para>Naturally, packages can also be uninstalled:
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<screen>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
$ nix-env -e subversion</screen>
|
|
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<para>Upgrading to a new version is just as easy. If you have a new
|
|
|
|
|
release of Nix Packages, you can do:
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<screen>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -u subversion</screen>
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
2004-10-14 19:43:09 +03:00
|
|
|
|
This will <emphasis>only</emphasis> upgrade Subversion if there is a
|
2005-04-10 23:54:21 +03:00
|
|
|
|
“newer” version in the new set of Nix expressions, as
|
2004-11-14 02:24:57 +02:00
|
|
|
|
defined by some pretty arbitrary rules regarding ordering of version
|
2005-03-16 16:40:48 +02:00
|
|
|
|
numbers (which generally do what you’d expect of them). To just
|
2004-11-14 02:24:57 +02:00
|
|
|
|
unconditionally replace Subversion with whatever version is in the Nix
|
|
|
|
|
expressions, use <parameter>-i</parameter> instead of
|
2004-11-01 14:02:44 +02:00
|
|
|
|
<parameter>-u</parameter>; <parameter>-i</parameter> will remove
|
|
|
|
|
whatever version is already installed.</para>
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
2007-12-04 13:42:58 +02:00
|
|
|
|
<para>You can also upgrade all packages for which there are newer
|
2004-10-14 19:43:09 +03:00
|
|
|
|
versions:
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
<screen>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
$ nix-env -f nixpkgs-<replaceable>version</replaceable> -u '*'</screen>
|
|
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<para>Sometimes it’s useful to be able to ask what
|
2004-11-01 14:02:44 +02:00
|
|
|
|
<command>nix-env</command> would do, without actually doing it. For
|
|
|
|
|
instance, to find out what packages would be upgraded by
|
|
|
|
|
<literal>nix-env -u '*'</literal>, you can do
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env ... -u '*' --dry-run
|
|
|
|
|
(dry run; not doing anything)
|
|
|
|
|
upgrading `libxslt-1.1.0' to `libxslt-1.1.10'
|
|
|
|
|
upgrading `graphviz-1.10' to `graphviz-1.12'
|
|
|
|
|
upgrading `coreutils-5.0' to `coreutils-5.2.1'</screen>
|
|
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
</section>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
<section xml:id="sec-profiles"><title>Profiles</title>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<para>Profiles and user environments are Nix’s mechanism for
|
2005-07-13 20:39:10 +03:00
|
|
|
|
implementing the ability to allow different users to have different
|
2004-11-01 14:02:44 +02:00
|
|
|
|
configurations, and to do atomic upgrades and rollbacks. To
|
2005-03-16 16:40:48 +02:00
|
|
|
|
understand how they work, it’s useful to know a bit about how Nix
|
2007-12-04 13:42:58 +02:00
|
|
|
|
works. In Nix, packages are stored in unique locations in the
|
2004-11-01 14:02:44 +02:00
|
|
|
|
<emphasis>Nix store</emphasis> (typically,
|
|
|
|
|
<filename>/nix/store</filename>). For instance, a particular version
|
2007-12-04 13:42:58 +02:00
|
|
|
|
of the Subversion package might be stored in a directory
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<filename>/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3/</filename>,
|
2004-11-01 14:02:44 +02:00
|
|
|
|
while another version might be stored in
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<filename>/nix/store/5mq2jcn36ldlmh93yj1n8s9c95pj7c5s-subversion-1.1.2</filename>.
|
|
|
|
|
The long strings prefixed to the directory names are cryptographic
|
|
|
|
|
hashes<footnote><para>160-bit truncations of SHA-256 hashes encoded in
|
|
|
|
|
a base-32 notation, to be precise.</para></footnote> of
|
2007-12-04 13:42:58 +02:00
|
|
|
|
<emphasis>all</emphasis> inputs involved in building the package —
|
2005-03-16 16:40:48 +02:00
|
|
|
|
sources, dependencies, compiler flags, and so on. So if two
|
2007-12-04 13:42:58 +02:00
|
|
|
|
packages differ in any way, they end up in different locations in
|
2005-03-16 16:40:48 +02:00
|
|
|
|
the file system, so they don’t interfere with each other. <xref
|
|
|
|
|
linkend='fig-user-environments' /> shows a part of a typical Nix
|
|
|
|
|
store.</para>
|
2004-11-01 14:02:44 +02:00
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
<figure xml:id='fig-user-environments'><title>User environments</title>
|
2004-10-25 19:54:56 +03:00
|
|
|
|
<mediaobject>
|
|
|
|
|
<imageobject>
|
2004-10-31 18:13:25 +02:00
|
|
|
|
<imagedata fileref='figures/user-environments.png' format='PNG' />
|
2004-10-25 19:54:56 +03:00
|
|
|
|
</imageobject>
|
|
|
|
|
</mediaobject>
|
|
|
|
|
</figure>
|
|
|
|
|
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<para>Of course, you wouldn’t want to type
|
2004-11-01 14:02:44 +02:00
|
|
|
|
|
|
|
|
|
<screen>
|
2005-03-16 16:40:48 +02:00
|
|
|
|
$ /nix/store/dpmvp969yhdq...-subversion-1.1.3/bin/svn</screen>
|
2004-11-01 14:02:44 +02:00
|
|
|
|
|
|
|
|
|
every time you want to run Subversion. Of course we could set up the
|
|
|
|
|
<envar>PATH</envar> environment variable to include the
|
2007-12-04 13:42:58 +02:00
|
|
|
|
<filename>bin</filename> directory of every package we want to use,
|
2004-11-01 14:02:44 +02:00
|
|
|
|
but this is not very convenient since changing <envar>PATH</envar>
|
2005-03-16 16:40:48 +02:00
|
|
|
|
doesn’t take effect for already existing processes. The solution Nix
|
2004-11-01 14:02:44 +02:00
|
|
|
|
uses is to create directory trees of symlinks to
|
2007-12-04 13:42:58 +02:00
|
|
|
|
<emphasis>activated</emphasis> packages. These are called
|
|
|
|
|
<emphasis>user environments</emphasis> and they are packages
|
2004-11-01 14:02:44 +02:00
|
|
|
|
themselves (though automatically generated by
|
|
|
|
|
<command>nix-env</command>), so they too reside in the Nix store. For
|
|
|
|
|
instance, in <xref linkend='fig-user-environments' /> the user
|
2005-03-16 16:40:48 +02:00
|
|
|
|
environment <filename>/nix/store/5mq2jcn36ldl...-user-env</filename>
|
|
|
|
|
contains a symlink to just Subversion 1.1.2 (arrows in the figure
|
2004-11-01 14:02:44 +02:00
|
|
|
|
indicate symlinks). This would be what we would obtain if we had done
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env -i subversion</screen>
|
|
|
|
|
|
2005-03-16 16:40:48 +02:00
|
|
|
|
on a set of Nix expressions that contained Subversion 1.1.2.</para>
|
2004-11-01 14:02:44 +02:00
|
|
|
|
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<para>This doesn’t in itself solve the problem, of course; you
|
|
|
|
|
wouldn’t want to type
|
|
|
|
|
<filename>/nix/store/0c1p5z4kda11...-user-env/bin/svn</filename>
|
|
|
|
|
either. That’s why there are symlinks outside of the store that point
|
2004-11-01 14:02:44 +02:00
|
|
|
|
to the user environments in the store; for instance, the symlinks
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<filename>default-42-link</filename> and
|
|
|
|
|
<filename>default-43-link</filename> in the example. These are called
|
|
|
|
|
<emphasis>generations</emphasis> since every time you perform a
|
|
|
|
|
<command>nix-env</command> operation, a new user environment is
|
|
|
|
|
generated based on the current one. For instance, generation 43 was
|
|
|
|
|
created from generation 42 when we did
|
2004-11-01 14:02:44 +02:00
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env -i subversion mozilla</screen>
|
|
|
|
|
|
|
|
|
|
on a set of Nix expressions that contained Mozilla and a new version
|
|
|
|
|
of Subversion.</para>
|
|
|
|
|
|
|
|
|
|
<para>Generations are grouped together into
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<emphasis>profiles</emphasis> so that different users don’t interfere
|
|
|
|
|
with each other if they don’t want to. For example:
|
2004-11-01 14:02:44 +02:00
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ ls -l /nix/var/nix/profiles/
|
|
|
|
|
...
|
2005-03-16 16:40:48 +02:00
|
|
|
|
lrwxrwxrwx 1 eelco ... default-42-link -> /nix/store/0c1p5z4kda11...-user-env
|
|
|
|
|
lrwxrwxrwx 1 eelco ... default-43-link -> /nix/store/3aw2pdyx2jfc...-user-env
|
2004-11-01 14:02:44 +02:00
|
|
|
|
lrwxrwxrwx 1 eelco ... default -> default-43-link</screen>
|
|
|
|
|
|
|
|
|
|
This shows a profile called <filename>default</filename>. The file
|
2004-11-14 02:24:57 +02:00
|
|
|
|
<filename>default</filename> itself is actually a symlink that points
|
2004-11-01 14:02:44 +02:00
|
|
|
|
to the current generation. When we do a <command>nix-env</command>
|
|
|
|
|
operation, a new user environment and generation link are created
|
|
|
|
|
based on the current one, and finally the <filename>default</filename>
|
|
|
|
|
symlink is made to point at the new generation. This last step is
|
|
|
|
|
atomic on Unix, which explains how we can do atomic upgrades. (Note
|
2007-12-04 13:42:58 +02:00
|
|
|
|
that the building/installing of new packages doesn’t interfere in
|
|
|
|
|
any way with old packages, since they are stored in different
|
2004-11-01 14:02:44 +02:00
|
|
|
|
locations in the Nix store.)</para>
|
|
|
|
|
|
|
|
|
|
<para>If you find that you want to undo a <command>nix-env</command>
|
|
|
|
|
operation, you can just do
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env --rollback</screen>
|
|
|
|
|
|
|
|
|
|
which will just make the current generation link point at the previous
|
|
|
|
|
link. E.g., <filename>default</filename> would be made to point at
|
|
|
|
|
<filename>default-42-link</filename>. You can also switch to a
|
|
|
|
|
specific generation:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env --switch-generation 43</screen>
|
|
|
|
|
|
|
|
|
|
which in this example would roll forward to generation 43 again. You
|
|
|
|
|
can also see all available generations:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env --list-generations</screen></para>
|
|
|
|
|
|
|
|
|
|
<para>Actually, there is another level of indirection not shown in the
|
2005-03-16 16:40:48 +02:00
|
|
|
|
figure above. You generally wouldn’t have
|
2004-11-01 14:02:44 +02:00
|
|
|
|
<filename>/nix/var/nix/profiles/<replaceable>some-profile</replaceable>/bin</filename>
|
|
|
|
|
in your <envar>PATH</envar>. Rather, there is a symlink
|
2004-11-14 02:24:57 +02:00
|
|
|
|
<filename>~/.nix-profile</filename> that points to your current
|
2004-11-01 14:02:44 +02:00
|
|
|
|
profile. This means that you should put
|
|
|
|
|
<filename>~/.nix-profile/bin</filename> in your <envar>PATH</envar>
|
2005-03-16 16:40:48 +02:00
|
|
|
|
(and indeed, that’s what the initialisation script
|
2004-11-01 14:02:44 +02:00
|
|
|
|
<filename>/nix/etc/profile.d/nix.sh</filename> does). This makes it
|
2004-11-14 02:24:57 +02:00
|
|
|
|
easier to switch to a different profile. You can do that using the
|
|
|
|
|
command <command>nix-env --switch-profile</command>:
|
2004-11-01 14:02:44 +02:00
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env --switch-profile /nix/var/nix/profiles/my-profile
|
|
|
|
|
|
|
|
|
|
$ nix-env --switch-profile /nix/var/nix/profiles/default</screen>
|
|
|
|
|
|
|
|
|
|
These commands switch to the <filename>my-profile</filename> and
|
2005-03-16 16:40:48 +02:00
|
|
|
|
default profile, respectively. If the profile doesn’t exist, it will
|
2004-11-01 14:02:44 +02:00
|
|
|
|
be created automatically. You should be careful about storing a
|
2004-11-14 02:24:57 +02:00
|
|
|
|
profile in another location than the <filename>profiles</filename>
|
|
|
|
|
directory, since otherwise it might not be used as a root of the
|
2009-07-14 17:58:12 +03:00
|
|
|
|
garbage collector (see <xref linkend='sec-garbage-collection'
|
2004-11-01 14:02:44 +02:00
|
|
|
|
/>).</para>
|
|
|
|
|
|
|
|
|
|
<para>All <command>nix-env</command> operations work on the profile
|
|
|
|
|
pointed to by <command>~/.nix-profile</command>, but you can override
|
2004-11-14 02:24:57 +02:00
|
|
|
|
this using the <option>--profile</option> option (abbreviation
|
2004-11-01 14:02:44 +02:00
|
|
|
|
<option>-p</option>):
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env -p /nix/var/nix/profiles/other-profile -i subversion</screen>
|
|
|
|
|
|
|
|
|
|
This will <emphasis>not</emphasis> change the
|
|
|
|
|
<command>~/.nix-profile</command> symlink.</para>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
</section>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
<section xml:id='sec-garbage-collection'><title>Garbage collection</title>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
2004-11-01 18:03:35 +02:00
|
|
|
|
<para><command>nix-env</command> operations such as upgrades
|
|
|
|
|
(<option>-u</option>) and uninstall (<option>-e</option>) never
|
2007-12-04 13:42:58 +02:00
|
|
|
|
actually delete packages from the system. All they do (as shown
|
2004-11-14 02:24:57 +02:00
|
|
|
|
above) is to create a new user environment that no longer contains
|
2007-12-04 13:42:58 +02:00
|
|
|
|
symlinks to the “deleted” packages.</para>
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
2007-12-04 13:42:58 +02:00
|
|
|
|
<para>Of course, since disk space is not infinite, unused packages
|
2004-11-01 18:03:35 +02:00
|
|
|
|
should be removed at some point. You can do this by running the Nix
|
2007-12-04 13:42:58 +02:00
|
|
|
|
garbage collector. It will remove from the Nix store any package
|
2004-11-01 18:03:35 +02:00
|
|
|
|
not used (directly or indirectly) by any generation of any
|
|
|
|
|
profile.</para>
|
|
|
|
|
|
|
|
|
|
<para>Note however that as long as old generations reference a
|
2007-12-04 13:42:58 +02:00
|
|
|
|
package, it will not be deleted. After all, we wouldn’t be able to
|
2004-11-01 18:03:35 +02:00
|
|
|
|
do a rollback otherwise. So in order for garbage collection to be
|
|
|
|
|
effective, you should also delete (some) old generations. Of course,
|
|
|
|
|
this should only be done if you are certain that you will not need to
|
|
|
|
|
roll back.</para>
|
|
|
|
|
|
|
|
|
|
<para>To delete all old (non-current) generations of your current
|
|
|
|
|
profile:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env --delete-generations old</screen>
|
|
|
|
|
|
|
|
|
|
Instead of <literal>old</literal> you can also specify a list of
|
|
|
|
|
generations, e.g.,
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env --delete-generations 10 11 14</screen>
|
|
|
|
|
|
|
|
|
|
</para>
|
|
|
|
|
|
|
|
|
|
<para>After removing appropriate old generations you can run the
|
|
|
|
|
garbage collector as follows:
|
|
|
|
|
|
|
|
|
|
<screen>
|
2005-04-08 16:00:38 +03:00
|
|
|
|
$ nix-store --gc</screen>
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
2005-04-08 16:00:38 +03:00
|
|
|
|
If you are feeling uncertain, you can also first view what files would
|
|
|
|
|
be deleted:
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
|
|
|
|
<screen>
|
2005-04-08 16:00:38 +03:00
|
|
|
|
$ nix-store --gc --print-dead</screen>
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
|
|
|
|
Likewise, the option <option>--print-live</option> will show the paths
|
2005-03-16 16:40:48 +02:00
|
|
|
|
that <emphasis>won’t</emphasis> be deleted.</para>
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
2006-09-29 14:03:16 +03:00
|
|
|
|
<para>There is also a convenient little utility
|
|
|
|
|
<command>nix-collect-garbage</command>, which when invoked with the
|
|
|
|
|
<option>-d</option> (<option>--delete-old</option>) switch deletes all
|
|
|
|
|
old generations of all profiles in
|
|
|
|
|
<filename>/nix/var/nix/profiles</filename>. So
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-collect-garbage -d</screen>
|
|
|
|
|
|
|
|
|
|
is a quick and easy way to clean up your system.</para>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-08 16:00:38 +03:00
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
<section xml:id="ssec-gc-roots"><title>Garbage collector roots</title>
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
2005-04-08 16:00:38 +03:00
|
|
|
|
<para>The roots of the garbage collector are all store paths to which
|
|
|
|
|
there are symlinks in the directory
|
|
|
|
|
<filename><replaceable>prefix</replaceable>/nix/var/nix/gcroots</filename>.
|
|
|
|
|
For instance, the following command makes the path
|
|
|
|
|
<filename>/nix/store/d718ef...-foo</filename> a root of the collector:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ ln -s /nix/store/d718ef...-foo /nix/var/nix/gcroots/bar</screen>
|
|
|
|
|
|
|
|
|
|
That is, after this command, the garbage collector will not remove
|
|
|
|
|
<filename>/nix/store/d718ef...-foo</filename> or any of its
|
|
|
|
|
dependencies.</para>
|
|
|
|
|
|
|
|
|
|
<para>Subdirectories of
|
|
|
|
|
<filename><replaceable>prefix</replaceable>/nix/var/nix/gcroots</filename>
|
|
|
|
|
are also searched for symlinks. Symlinks to non-store paths are
|
|
|
|
|
followed and searched for roots, but symlinks to non-store paths
|
|
|
|
|
<emphasis>inside</emphasis> the paths reached in that way are not
|
|
|
|
|
followed to prevent infinite recursion.</para>
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
</section>
|
2004-11-01 18:03:35 +02:00
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
</section>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
<section xml:id="sec-channels"><title>Channels</title>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<para>If you want to stay up to date with a set of packages, it’s not
|
2004-11-01 18:21:37 +02:00
|
|
|
|
very convenient to manually download the latest set of Nix expressions
|
|
|
|
|
for those packages, use <command>nix-pull</command> to register
|
|
|
|
|
pre-built binaries (if available), and upgrade using
|
2005-03-16 16:40:48 +02:00
|
|
|
|
<command>nix-env</command>. Fortunately, there’s a better way:
|
2004-11-01 18:21:37 +02:00
|
|
|
|
<emphasis>Nix channels</emphasis>.</para>
|
|
|
|
|
|
|
|
|
|
<para>A Nix channel is just a URL that points to a place that contains
|
2005-04-09 20:16:00 +03:00
|
|
|
|
a set of Nix expressions and a manifest. Using the command <link
|
|
|
|
|
linkend="sec-nix-channel"><command>nix-channel</command></link> you
|
|
|
|
|
can automatically stay up to date with whatever is available at that
|
|
|
|
|
URL.</para>
|
2004-11-01 18:21:37 +02:00
|
|
|
|
|
2005-04-10 23:54:21 +03:00
|
|
|
|
<para>You can “subscribe” to a channel using
|
2004-11-14 02:24:57 +02:00
|
|
|
|
<command>nix-channel --add</command>, e.g.,
|
2004-11-01 18:21:37 +02:00
|
|
|
|
|
|
|
|
|
<screen>
|
2008-06-09 16:42:13 +03:00
|
|
|
|
$ nix-channel --add http://nixos.org/releases/nixpkgs/channels/nixpkgs-unstable</screen>
|
2004-11-01 18:21:37 +02:00
|
|
|
|
|
|
|
|
|
subscribes you to a channel that always contains that latest version
|
|
|
|
|
of the Nix Packages collection. (Instead of
|
|
|
|
|
<literal>nixpkgs-unstable</literal> you could also subscribe to
|
|
|
|
|
<literal>nixpkgs-stable</literal>, which should have a higher level of
|
|
|
|
|
stability, but right now is just outdated.) Subscribing really just
|
|
|
|
|
means that the URL is added to the file
|
|
|
|
|
<filename>~/.nix-channels</filename>. Right now there is no command
|
2005-04-10 23:54:21 +03:00
|
|
|
|
to “unsubscribe”; you should just edit that file manually
|
2004-11-01 18:21:37 +02:00
|
|
|
|
and delete the offending URL.</para>
|
|
|
|
|
|
|
|
|
|
<para>To obtain the latest Nix expressions available in a channel, do
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-channel --update</screen>
|
|
|
|
|
|
|
|
|
|
This downloads the Nix expressions in every channel (downloaded from
|
|
|
|
|
<literal><replaceable>url</replaceable>/nixexprs.tar.bz2</literal>)
|
|
|
|
|
and registers any available pre-built binaries in every channel
|
|
|
|
|
(by <command>nix-pull</command>ing
|
|
|
|
|
<literal><replaceable>url</replaceable>/MANIFEST</literal>). It also
|
2005-03-16 16:40:48 +02:00
|
|
|
|
makes the union of each channel’s Nix expressions the default for
|
2004-11-01 18:21:37 +02:00
|
|
|
|
<command>nix-env</command> operations. Consequently, you can then say
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env -u '*'</screen>
|
|
|
|
|
|
2007-12-04 13:42:58 +02:00
|
|
|
|
to upgrade all packages in your profile to the latest versions
|
2004-11-14 02:24:57 +02:00
|
|
|
|
available in the subscribed channels.</para>
|
2004-10-14 19:43:09 +03:00
|
|
|
|
|
2006-08-21 19:05:11 +03:00
|
|
|
|
</section>
|
2004-10-14 14:55:12 +03:00
|
|
|
|
|
|
|
|
|
|
2006-09-29 17:16:41 +03:00
|
|
|
|
<section xml:id="sec-one-click"><title>One-click installs</title>
|
2006-09-29 14:03:16 +03:00
|
|
|
|
|
2006-09-29 17:59:10 +03:00
|
|
|
|
<para>Often, when you want to install a specific package (e.g., from
|
|
|
|
|
the <link
|
2010-02-05 12:17:13 +02:00
|
|
|
|
xlink:href="http://nixos.org/nixpkgs/">Nix
|
2008-06-09 16:42:13 +03:00
|
|
|
|
Packages collection</link>), subscribing to a channel is a bit
|
|
|
|
|
cumbersome. And channels don’t help you at all if you want to install
|
|
|
|
|
an older version of a package than the one provided by the current
|
|
|
|
|
contents of the channel, or a package that has been removed from the
|
|
|
|
|
channel. That’s when <emphasis>one-click installs</emphasis> come in
|
|
|
|
|
handy: you can just go to the web page that contains the package,
|
|
|
|
|
click on it, and it will be installed with all the necessary
|
|
|
|
|
dependencies.</para>
|
2006-09-29 17:59:10 +03:00
|
|
|
|
|
|
|
|
|
<para>For instance, you can go to <link
|
2009-11-05 11:07:43 +02:00
|
|
|
|
xlink:href="http://hydra.nixos.org/jobset/nixpkgs/trunk/channel/latest"
|
|
|
|
|
/> and click on any link for the individual packages for your
|
|
|
|
|
platform. The first time you do this, your browser will ask what to
|
|
|
|
|
do with <literal>application/nix-package</literal> files. You should
|
|
|
|
|
open them with <filename>/nix/bin/nix-install-package</filename>.
|
|
|
|
|
This will open a window that asks you to confirm that you want to
|
|
|
|
|
install the package. When you answer <literal>Y</literal>, the
|
|
|
|
|
package and all its dependencies will be installed. This is a binary
|
|
|
|
|
deployment mechanism — you get packages pre-compiled for the selected
|
|
|
|
|
platform type.</para>
|
2006-09-29 17:59:10 +03:00
|
|
|
|
|
|
|
|
|
<para>You can also install <literal>application/nix-package</literal>
|
|
|
|
|
files from the command line directly. See <xref
|
|
|
|
|
linkend='sec-nix-install-package' /> for details.</para>
|
2006-09-29 14:03:16 +03:00
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
2008-11-19 17:20:46 +02:00
|
|
|
|
<section xml:id="sec-sharing-packages"><title>Sharing packages between machines</title>
|
|
|
|
|
|
|
|
|
|
<para>Sometimes you want to copy a package from one machine to
|
|
|
|
|
another. Or, you want to install some packages and you know that
|
|
|
|
|
another machine already has some or all of those packages or their
|
|
|
|
|
dependencies. In that case there are mechanisms to quickly copy
|
|
|
|
|
packages between machines.</para>
|
|
|
|
|
|
|
|
|
|
<para>The command <command
|
|
|
|
|
linkend="sec-nix-copy-closure">nix-copy-closure</command> copies a Nix
|
|
|
|
|
store path along with all its dependencies to or from another machine
|
|
|
|
|
via the SSH protocol. It doesn’t copy store paths that are already
|
|
|
|
|
present on the target machine. For example, the following command
|
|
|
|
|
copies Firefox with all its dependencies:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-copy-closure --to alice@itchy.example.org $(type -p firefox)</screen>
|
|
|
|
|
|
|
|
|
|
See <xref linkend='sec-nix-copy-closure' /> for details.</para>
|
|
|
|
|
|
|
|
|
|
<para>With <command linkend='refsec-nix-store-export'>nix-store
|
|
|
|
|
--export</command> and <command
|
|
|
|
|
linkend='refsec-nix-store-import'>nix-store --import</command> you can
|
|
|
|
|
write the closure of a store path (that is, the path and all its
|
|
|
|
|
dependencies) to a file, and then unpack that file into another Nix
|
|
|
|
|
store. For example,
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-store --export $(type -p firefox) > firefox.closure</screen>
|
|
|
|
|
|
|
|
|
|
writes the closure of Firefox to a file. You can then copy this file
|
|
|
|
|
to another machine and install the closure:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-store --import < firefox.closure</screen>
|
|
|
|
|
|
|
|
|
|
Any store paths in the closure that are already present in the target
|
|
|
|
|
store are ignored. It is also possible to pipe the export into
|
|
|
|
|
another command, e.g. to copy and install a closure directly to/on
|
|
|
|
|
another machine:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-store --export $(type -p firefox) | bzip2 | \
|
|
|
|
|
ssh alice@itchy.example.org "bunzip2 | nix-store --import"</screen>
|
|
|
|
|
|
|
|
|
|
But note that <command>nix-copy-closure</command> is generally more
|
|
|
|
|
efficient in this example because it only copies paths that are not
|
|
|
|
|
already present in the target Nix store.</para>
|
|
|
|
|
|
|
|
|
|
<para>Finally, if you can mount the Nix store of a remote machine in
|
|
|
|
|
your local filesystem, Nix can copy paths from the remote Nix store to
|
|
|
|
|
the local Nix store <emphasis>on demand</emphasis>. For instance,
|
|
|
|
|
suppose that you mount a remote machine containing a Nix store via
|
|
|
|
|
<command
|
|
|
|
|
xlink:href="http://fuse.sourceforge.net/sshfs.html">sshfs</command>:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ sshfs alice@itchy.example.org:/ /mnt</screen>
|
|
|
|
|
|
|
|
|
|
You should then set the <envar>NIX_OTHER_STORES</envar> environment
|
|
|
|
|
variable to tell Nix about this remote Nix store:
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ export NIX_OTHER_STORES=/mnt/nix</screen>
|
|
|
|
|
|
|
|
|
|
Then if you do any Nix operation, e.g.
|
|
|
|
|
|
|
|
|
|
<screen>
|
|
|
|
|
$ nix-env -i firefox</screen>
|
|
|
|
|
|
|
|
|
|
and Nix has to build a path that it sees is already present in
|
|
|
|
|
<filename>/mnt/nix</filename>, then it will just copy from there
|
|
|
|
|
instead of building it from source.</para>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
2004-11-14 02:24:57 +02:00
|
|
|
|
</chapter>
|