Skip to main content

Profiles

Profiles is Nix's way to isolate each user's configuration and enable easy rollback. Each profile (and thus each profile's generation) is a symlink in the /nix/var/nix/profiles/.

Every time a change is made to the user's environment a new generation is created from the last one.

The .nix-profile directory in each home directories has its binaries added to the user's $PATH. This way stuff that are in ~/.nix-profile/bin will be accessible as commands.

And as seen on the picture, every user has a .nix-profile directory which actually is a symlink to a corresponding profile in the Nix profile's directory. Each profile (default and carol in this case) is actually a symlink to the last generation (default-42-link and carol-23-link). Those are themselves symlinks to special derivations in the Nix store (yes those are derivations as well), and those mimick Linux's file system hierarchy but use symlinks to point to each actual package.

That way when you rollback, the only thing that happens is that the symlink change to a different generation. When you install a new package with nix-env, it creates a new generation from the last one, create a new derivation and symlink the current environment to that new generation.

This allow to do atomic updates that can always be rolled back. As you can imagine, in this scenario nothing is ever deleted which allow easy, offline rollbacks in case anything goes wrong. However sometimes we just want to free some space. So in the next page we'll talk about how the garbage collector works.