nix-store-optimise - Man Page

Name

nix-store --optimise — reduce disk space usage

Synopsis

nix-store --optimise

Description

The operation --optimise reduces Nix store disk space usage by finding identical files in the store and hard-linking them to each other. It typically reduces the size of the store by something like 25-35%. Only regular files and symlinks are hard-linked in this manner. Files are considered identical when they have the same Nix Archive (NAR) serialisation: that is, regular files must have the same contents and permission (executable or non-executable), and symlinks must have the same contents.

After completion, or when the command is interrupted, a report on the achieved savings is printed on standard error.

Use -vv or -vvv to get some progress indication.

Options

The following options are allowed for all nix-store operations, but may not always have an effect.

$ nix-store --add-root /home/eelco/bla/result --realise ...

$ ls -l /nix/var/nix/gcroots/auto
lrwxrwxrwx    1 ... 2005-03-13 21:10 dn54lcypm8f8... -> /home/eelco/bla/result

$ ls -l /home/eelco/bla/result
lrwxrwxrwx    1 ... 2005-03-13 21:10 /home/eelco/bla/result -> /nix/store/1r11343n6qd4...-f-spot-0.0.10

Thus, when /home/eelco/bla/result is removed, the GC root in the auto directory becomes a dangling symlink and will be ignored by the collector.

Warning

Note that it is not possible to move or rename GC roots, since the symlink in the auto directory will still point to the old location.

If there are multiple results, then multiple symlinks will be created by sequentially numbering symlinks beyond the first one (e.g., foo, foo-2, foo-3, and so on).

Common Options

Most Nix commands accept the following command-line options:

{ # The system (e.g., `i686-linux') for which to build the packages.
system ? builtins.currentSystem
...
}: ...

So if you call this Nix expression (e.g., when you do nix-env --install --attr pkgname), the function will be called automatically using the value builtins.currentSystem for the system argument. You can override this using --arg, e.g., nix-env --install --attr pkgname --arg system \"i686-freebsd\". (Note that since the argument is a Nix string literal, you have to escape the quotes.)

Common Environment Variables

Most Nix commands interpret the following environment variables:

$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix

Consult the mount 8 manual page for details.

XDG Base Directories

Nix follows the XDG Base Directory Specification\c .

For backwards compatibility, Nix commands will follow the standard only when use-xdg-base-directories is enabled. New Nix commands (experimental) conform to the standard by default.

The following environment variables are used to determine locations of various state and configuration files:

  • [XDG_CONFIG_HOME]{#env-XDGCONFIGHOME} (default ~/.config)
  • [XDG_STATE_HOME]{#env-XDGSTATEHOME} (default ~/.local/state)
  • [XDG_CACHE_HOME]{#env-XDGCACHEHOME} (default ~/.cache)

In addition, setting the following environment variables overrides the XDG base directories:

  • [NIX_CONFIG_HOME]{#env-NIXCONFIGHOME} (default $XDG_CONFIG_HOME/nix)
  • [NIX_STATE_HOME]{#env-NIXSTATEHOME} (default $XDG_STATE_HOME/nix)
  • [NIX_CACHE_HOME]{#env-NIXCACHEHOME} (default $XDG_CACHE_HOME/nix)

When use-xdg-base-directories is enabled, the configuration directory is:

  1. $NIX_CONFIG_HOME, if it is defined
  2. Otherwise, $XDG_CONFIG_HOME/nix, if XDG_CONFIG_HOME is defined
  3. Otherwise, ~/.config/nix.

Likewise for the state and cache directories.

Example

$ nix-store --optimise
hashing files in `/nix/store/qhqx7l2f1kmwihc9bnxs7rc159hsxnf3-gcc-4.1.1'
...
541838819 bytes (516.74 MiB) freed by hard-linking 54143 files;
there are 114486 files with equal contents out of 215894 files in total