LinuxCommandLibrary

nix3-profile

Manage Nix package profiles

TLDR

Install some packages from nixpkgs into the default profile

$ nix profile install [nixpkgs#pkg1 nixpkgs#pkg2 ...]
copy

Install a package from a flake on GitHub into a custom profile
$ nix profile install [github:owner/repo/pkg] --profile [./path/to/directory]
copy

List packages currently installed in the default profile
$ nix profile list
copy

Remove a package installed from nixpkgs from the default profile, by name
$ nix profile remove [legacyPackages.x86_64-linux.pkg]
copy

Upgrade packages in the default to the latest available versions
$ nix profile upgrade
copy

Rollback (cancel) the latest action on the default profile
$ nix profile rollback
copy

SYNOPSIS

`nix profile subcommand [options...]

Common subcommands include:
`nix profile install [flake-url] [--profile path] [attr-path]...`
`nix profile remove [--profile path] item-id...`
`nix profile upgrade [--profile path] [item-id]...`
`nix profile list [--profile path]`
`nix profile rollback [--profile path] [generation]`
`nix profile diff-closures [--profile path] [generation1] [generation2]`

PARAMETERS

install
    Adds new packages to the user profile. Can install from Nix paths, attribute paths in Nixpkgs, or flake outputs.

remove
    Removes packages from the user profile by their item ID (as shown by `nix profile list`).

upgrade
    Upgrades packages currently in the user profile to their latest available versions.

list
    Displays all packages currently installed in the user profile, showing their item IDs, attribute paths, and current generation.

rollback
    Reverts the user profile to a previous generation. If no generation is specified, it rolls back to the immediately preceding one.

history
    Shows a list of all historical generations of the user profile, including creation dates and descriptions.

diff-closures
    Compares the full dependency closures of two specified profile generations, showing what packages have been added or removed.

--profile path
    Specifies an alternative profile path to operate on instead of the default `~/.nix-profile`.

--dry-run
    Shows what would happen without actually modifying the profile.

--print-rollbacks
    For `install` or `upgrade` commands, prints the new generation number to facilitate quick rollback if needed.

--show-trace
    Shows a full stack trace for Nix evaluation errors, aiding in debugging.

DESCRIPTION

The `nix profile` command (often referred to as `nix3-profile` in the context of the new Nix CLI) is the modern, imperative package manager for user-specific environments. It allows users to imperatively add, remove, and upgrade packages in their `~/.nix-profile` symlink, which points to a specific "generation" of their user environment. Each modification creates a new generation, enabling easy rollback to previous states. This command simplifies package management compared to the older `nix-env`, providing a more declarative and reproducible way to manage packages within a user's profile without affecting the global Nix store or other users. It integrates seamlessly with the Nix ecosystem, especially with Nix flakes, allowing users to install packages directly from flake inputs or traditional Nix expressions.

CAVEATS

The `nix profile` command manages imperative installations. For truly reproducible and declarative environment definitions, Nix flakes with `nix build` or `nix develop` are generally preferred.
Each `nix profile` operation creates a new generation, which consumes disk space. Regular garbage collection (`nix store gc` or `nix-collect-garbage`) is necessary to reclaim space from older, unused generations.
Packages installed via `nix profile` are symlinked into the `~/.nix-profile` directory (e.g., `~/.nix-profile/bin`). Ensure this directory is included in your `PATH` environment variable for executables to be found.

GENERATIONS AND ROLLBACKS

Every successful `nix profile install`, `remove`, or `upgrade` operation creates a new "generation" of your profile. These generations are numbered chronologically, starting from 1. You can easily view your history with `nix profile history` and revert to any previous stable generation using `nix profile rollback generation_number`, providing a powerful undo mechanism for package changes.

FLAKE INTEGRATION

`nix profile` fully supports Nix flakes. You can install packages directly from a flake's outputs, e.g., `nix profile install nixpkgs#hello` or `nix profile install github:NixOS/nixpkgs#firefox`. This allows for highly reproducible installations tied to specific versions of package sets and simplifies managing dependencies from various sources.

HISTORY

The `nix profile` command was introduced as a core component of the new Nix 2.0 CLI, which aimed to provide a more consistent and user-friendly interface than the previous collection of disparate `nix-*` commands (such as `nix-env`, `nix-build`, `nix-shell`). It effectively deprecates much of `nix-env`'s functionality for managing user profiles, offering an improved system for tracking profile generations and facilitating easier rollbacks. The transition to the new CLI, and `nix profile` specifically, was a significant step towards a more unified and accessible Nix user experience, especially with the later introduction and integration of Nix flakes.

SEE ALSO

nix-env(1), nix store(1), nix build(1), nix shell(1), nix develop(1), nix flake(1)

Copied to clipboard