Home Explore Blog CI



nix

3rd chunk of `doc/manual/source/package-management/profiles.md`
f0595c6c077e30b0662fd3ed6300cc57c20845275f86b0700000000100000841
`PATH` environment variable to include the `bin` directory of every
package we want to use, but this is not very convenient since changing
`PATH` doesn’t take effect for already existing processes. The solution
Nix uses is to create directory trees of symlinks to *activated*
packages. These are called *user environments* and they are packages
themselves (though automatically generated by `nix-env`), so they too
reside in the Nix store. For instance, in the figure above, the user
environment `/nix/store/0c1p5z4kda11...-user-env` contains a symlink to
just Subversion 1.1.2 (arrows in the figure indicate symlinks). This
would be what we would obtain if we had done

```console
$ nix-env --install --attr nixpkgs.subversion
```

on a set of Nix expressions that contained Subversion 1.1.2.

This doesn’t in itself solve the problem, of course; you wouldn’t want
to type `/nix/store/0c1p5z4kda11...-user-env/bin/svn` either. That’s why
there are symlinks outside of the store that point to the user
environments in the store; for instance, the symlinks `default-42-link`
and `default-43-link` in the example. These are called *generations*
since every time you perform a `nix-env` operation, a new user
environment is generated based on the current one. For instance,
generation 43 was created from generation 42 when we did

```console
$ nix-env --install --attr nixpkgs.subversion nixpkgs.firefox
```

on a set of Nix expressions that contained Firefox and a new version of
Subversion.

Generations are grouped together into *profiles* so that different users
don’t interfere with each other if they don’t want to. For example:

```console
$ ls -l /nix/var/nix/profiles/
...
lrwxrwxrwx  1 eelco ... default-42-link -> /nix/store/0c1p5z4kda11...-user-env
lrwxrwxrwx  1 eelco ... default-43-link -> /nix/store/3aw2pdyx2jfc...-user-env
lrwxrwxrwx  1 eelco ... default -> default-43-link
```

This shows a profile called `default`. The file `default` itself is
actually a symlink that points to the current generation. When we do a
`nix-env` operation, a new user environment and generation link are

Title: Generations and Profiles in Nix
Summary
Nix creates user environments with symlinks to activated packages in the Nix store, but directly using these environments is still inconvenient. To solve this, Nix creates symlinks outside the store, such as `default-42-link` and `default-43-link`, pointing to the user environments. These are called generations, created with each `nix-env` operation. Generations are grouped into profiles to prevent user interference. Profiles, like `default`, contain a symlink pointing to the current generation, enabling easy access to installed packages.