#readwise
# Profiles (Nix Reference Manual)

## Metadata
- Author: [[nix.dev]]
- Full Title: Profiles (Nix Reference Manual)
- URL: https://nix.dev/manual/nix/stable/package-management/profiles
## Summary
Profiles are symlinks stored outside the Nix store, to user environments which are stored inside the store. User environments group binaries from multiple packages together using symlinks. Each profile is version controlled. A profile's version is called a generation. ^9yc1si
## Highlights
Profiles and user environments are Nix’s mechanism for implementing the ability to allow different users to have different configurations, and to do atomic upgrades and rollbacks. ([View Highlight](https://read.readwise.io/read/01jdpg932w03emjwb937p8128z))
---
In Nix, packages are stored in unique locations in the *Nix store* (typically, `/nix/store`). For instance, a particular version of the Subversion package might be stored in a directory `/nix/store/dpmvp969yhdqs7lm2r1a3gng7pyq6vy4-subversion-1.1.3/`, while another version might be stored in `/nix/store/5mq2jcn36ldlmh93yj1n8s9c95pj7c5s-subversion-1.1.2`. The long strings prefixed to the directory names are cryptographic hashes (to be precise, 160-bit truncations of SHA-256 hashes encoded in a base-32 notation) of *all* inputs involved in building the package — sources, dependencies, compiler flags, and so on. ([View Highlight](https://read.readwise.io/read/01jdpgdv0f712q28ab0p7rd4ny))
**To create a profile in Nix, you can use the command `nix-env --switch-profile /nix/var/nix/profiles/my-profile`, replacing `my-profile` with your desired profile name. If the profile does not already exist, it will be created automatically.** ^5u7qwz
---
You should be careful about storing a profile in another location than the `profiles` directory, since otherwise it might not be used as a root of the [garbage collector](https://nix.dev/manual/nix/2.18/package-management/garbage-collection). ([View Highlight](https://read.readwise.io/read/01jdpgx2vzxbd8bwtadq66dytk))
---
All `nix-env` operations work on the profile pointed to by `~/.nix-profile`, but you can override this using the `--profile` option (abbreviation `-p`): ([View Highlight](https://read.readwise.io/read/01jdpgxcjhn0qb4xtyzewymr60))
---
Of course we could set up the `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.** ([View Highlight](https://read.readwise.io/read/01je226xtqcx5nh2xdakkrthbz))
---
**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.** ([View Highlight](https://read.readwise.io/read/01je2288jm4yyz0458q14n4268))
---
**Generations are grouped together into *profiles*** so that different users don’t interfere with each other if they don’t want to. ([View Highlight](https://read.readwise.io/read/01je228ksewej23xwxxh1q36aa))
---