Flox is designed to enhance the powerful Nix package manager by simplifying the creation and management of development environments. If you're running NixOS and want to leverage Flox's user-friendly approach without disturbing your current configuration, you're in the right place. This guide details how to install Flox into your user profile, allowing it to coexist peacefully with your system's Nix setup.
nix profile install, adding it to your user environment without altering the core NixOS system.nix-command, flakes) are enabled in your Nix configuration for a smooth installation.Flox acts as a layer on top of Nix, aiming to make its capabilities more accessible. It allows developers to define, share, and activate isolated environments containing specific packages quickly. For NixOS users, installing Flox provides an alternative, often simpler, workflow for managing project dependencies alongside the robust, declarative system configuration NixOS is known for.
Flox aims to simplify Nix-based environment management.
While NixOS provides powerful system-level configuration, managing per-project development environments can still involve manual nix-shell or flake configurations. Flox simplifies this with commands like flox init, flox install <package>, and flox activate, offering a more imperative-style interface while still leveraging Nix's reproducible builds underneath.
The radar chart below offers a visual comparison of key aspects when using Flox within an existing NixOS setup versus relying solely on traditional Nix/NixOS tools for environment management.
This chart suggests that while traditional Nix tools offer maximum flexibility and reproducibility, Flox enhances ease of use and environment sharing, integrating well within the existing NixOS framework.
Before installing Flox, ensure your NixOS system is prepared:
Flox requires Nix version 2.7.0 or later. Check your current version:
nix --version
If your version is older, you may need to update Nix through your NixOS configuration.
Flox installation relies on the nix-command and flakes experimental features. You need to enable these in your Nix configuration.
/etc/nix/nix.confEdit the global Nix configuration file:
sudo nano /etc/nix/nix.conf
Add or modify the experimental-features line:
experimental-features = nix-command flakes
Save the file (Ctrl+O in nano, then Enter) and exit (Ctrl+X).
/etc/nixos/configuration.nixAlternatively, you can manage Nix settings declaratively within your main NixOS configuration file:
# In /etc/nixos/configuration.nix
nix.settings.experimental-features = [ "nix-command" "flakes" ];
After modifying either configuration file, you must rebuild your NixOS system for the changes to take effect:
sudo nixos-rebuild switch
Wait for the rebuild process to complete.
Ensure your system meets the recommended minimums for running Flox and installing packages: at least 4GB of RAM and 8GB of available storage.
Follow these steps to install the Flox CLI tool into your user profile.
This mindmap provides a visual overview of the installation journey:
Using Flox's binary cache can speed up package installations by downloading pre-built binaries instead of building them locally. Add the Flox cache details to your Nix configuration.
Edit /etc/nix/nix.conf (or manage via configuration.nix as shown previously):
sudo nano /etc/nix/nix.conf
Add or ensure the following lines are present, merging with any existing substituters or keys:
substituters = https://cache.flox.dev https://cache.nixos.org/
trusted-public-keys = flox-cache-public-1:7F4OyH7ZCnFhcze3fJdfyXYLQw/aV7GEed86nQ7IsOs= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
Note: Always ensure you include the default cache.nixos.org substituter and its key alongside Flox's.
Save the file and rebuild your NixOS configuration again:
sudo nixos-rebuild switch
Now, install Flox using the nix profile install command. This command fetches Flox directly from its GitHub repository using Nix Flakes and installs it into your current user's profile.
nix profile install --impure \
--experimental-features "nix-command flakes" \
--accept-flake-config \
'github:flox/flox'
--impure: Allows access to network resources (like GitHub) during evaluation, which is necessary here.--experimental-features "nix-command flakes": Explicitly ensures the required features are enabled for this command's execution.--accept-flake-config: Automatically accepts configuration settings defined within the Flox flake.'github:flox/flox': Specifies the source flake repository for Flox.This command should run without needing sudo as it installs into your user profile (~/.nix-profile). The process might take a few minutes.
Once the installation completes, verify that the flox command is available:
flox --version
This should output the installed Flox version number. You can also perform a quick functional test:
# Navigate to a test directory
mkdir ~/flox-test && cd ~/flox-test
# Initialize a flox environment
flox init
# Install a package
flox install nodejs
# Activate the environment (your shell prompt should change)
flox activate
# Check the package works
node --version
# Exit the flox environment
exit
If these commands work, Flox is successfully installed and ready to use.
Now that Flox is installed, you can start using it to manage your development environments. This video provides a good overview of Flox and its capabilities:
The video highlights how Flox, built upon Nix, simplifies creating isolated and reproducible environments, reducing setup times and making collaboration easier. Key commands like flox install, flox activate, flox push, and flox pull enable efficient package and environment management.
Here’s how to update or remove Flox if needed.
To update Flox to the latest version available on its GitHub repository, you can use:
nix profile upgrade flox
Alternatively, re-running the original nix profile install command often achieves the same result, pulling the latest commit.
If you decide to remove Flox from your user profile, use the following command:
nix profile remove github:flox/flox
This removes the Flox binaries and links from your profile without affecting your underlying NixOS system or other installed Nix packages.
This table summarizes the core commands for installing and verifying Flox on NixOS:
| Step | Action | Command / Configuration | Notes |
|---|---|---|---|
| Prerequisite 1 | Verify Nix Version | nix --version |
Must be >= 2.7.0 |
| Prerequisite 2 | Enable Experimental Features | Edit /etc/nix/nix.conf or configuration.nixexperimental-features = nix-command flakes |
Requires sudo nixos-rebuild switch |
| Optional | Configure Substituters | Edit /etc/nix/nix.conf or configuration.nixAdd Flox cache URL & public key |
Requires sudo nixos-rebuild switch. Improves speed. |
| Install | Install Flox CLI | nix profile install --impure --experimental-features "nix-command flakes" --accept-flake-config 'github:flox/flox' |
Installs to user profile. |
| Verify | Check Flox Version | flox --version |
Confirms successful installation. |
| Manage | Update Flox | nix profile upgrade flox |
Keeps Flox up-to-date. |
| Manage | Remove Flox | nix profile remove github:flox/flox |
Uninstalls Flox from user profile. |
No, the recommended installation method using nix profile install adds Flox to your user profile alongside your existing system-wide Nix installation. It does not replace or interfere with your NixOS configuration or the system's Nix package manager. You can continue using standard Nix commands and manage your NixOS system as usual.
Flox utilizes modern Nix features, specifically Nix Flakes (`flakes`) and the newer command-line interface (`nix-command`), for its operation and installation process. As these features are still considered experimental by the core Nix team (though widely used), they need to be explicitly enabled in your Nix configuration.
No, it's not strictly required. Flox can function without its dedicated cache by building packages from source using Nix. However, configuring the substituter is highly recommended because it allows Nix to download pre-built binaries from Flox's cache (`cache.flox.dev`), significantly speeding up the installation of Flox itself and packages within Flox environments.
First, double-check that you have met all prerequisites: correct Nix version (>= 2.7.0) and experimental features (`nix-command`, `flakes`) enabled and applied via `sudo nixos-rebuild switch`. Ensure you have a stable internet connection, as the command needs to fetch data from GitHub. Check the error message for specific clues – it might indicate a network issue, a problem with the flake source, or a configuration conflict. Consulting the official Flox documentation or community forums might also provide solutions to specific errors.
Navigate to your project directory in the terminal. You can initialize a new Flox environment using flox init. Add packages using flox install <package-name> (e.g., flox install python3 git). Activate the environment with flox activate to make the installed packages available in your shell. Use exit or `deactivate` (depending on Flox version/shell integration) to leave the environment. You can also use flox shell to directly enter an environment defined in a local `flake.nix` or from a remote source.