如何通过~/.nixpkgs/config.nix使用nix-env -i all安装Nix不稳定频道软件包?
Got it, let's walk through how to set up your ~/.nixpkgs/config.nix to install unstable Nix packages, specifically using nix-env -i all to pull packages from the unstable channel.
Before you can use unstable packages, you need to add the Nixpkgs unstable channel to your setup. Open your terminal and run these commands:
# Add the unstable channel nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable # Update the channel to get the latest package definitions nix-channel --update nixpkgs-unstable
~/.nixpkgs/config.nix to Map all to Unstable Packages Next, we'll edit your config.nix to create an alias that makes nix-env -i all target the unstable channel's package set instead of the default stable one.
If you don't already have a ~/.nixpkgs/config.nix file, create it first:
mkdir -p ~/.nixpkgs touch ~/.nixpkgs/config.nix
Now open the file in your favorite editor and paste this configuration:
{ packageOverrides = pkgs: let # Import the unstable channel's package collection unstable = import <nixpkgs-unstable> { inherit config; }; in { # Map the "all" alias to the entire unstable package set all = unstable; # Optional: If you want specific individual packages to default to unstable, add them here # Example: firefox = unstable.firefox; # Example: neovim = unstable.neovim; }; }
What this does:
- The
unstablevariable pulls in all packages from thenixpkgs-unstablechannel you added earlier. - By setting
all = unstable, we tell Nix that when you runnix-env -i all, it should install every package from the unstable channel instead of your default stable channel.
Now you're ready to run the install command. Open your terminal and execute:
nix-env -i all
⚠️ A big heads-up: Installing all packages from the unstable channel will take a massive amount of disk space (we're talking tens of gigabytes) and may introduce compatibility issues between packages. This is rarely a good idea for a daily-use system—you're better off installing only the specific unstable packages you need. But if you're testing or have a dedicated environment, go for it.
To confirm you've installed the unstable versions, run:
nix-env -q
Check the version numbers of your installed packages—they should match the latest versions from the nixpkgs-unstable channel.
- Keep the unstable channel updated: Run
nix-channel --update nixpkgs-unstableregularly to get the latest unstable package builds. - Roll back if things break: If installing all unstable packages causes issues, use
nix-env --rollbackto revert to your previous package state. - Selective installs (better practice): Instead of installing all packages, use
nix-env -i unstable.<package-name>to install specific unstable packages without modifying yourconfig.nix. For example:nix-env -i unstable.firefox
内容的提问来源于stack exchange,提问作者Răzvan Flavius Panda




