You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过~/.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.

1. First: Add the Unstable Channel to Your System

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
2. Configure ~/.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 unstable variable pulls in all packages from the nixpkgs-unstable channel you added earlier.
  • By setting all = unstable, we tell Nix that when you run nix-env -i all, it should install every package from the unstable channel instead of your default stable channel.
3. Install the Unstable Packages

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.

4. Verify the Installation

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.

Extra Tips
  • Keep the unstable channel updated: Run nix-channel --update nixpkgs-unstable regularly to get the latest unstable package builds.
  • Roll back if things break: If installing all unstable packages causes issues, use nix-env --rollback to 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 your config.nix. For example:
    nix-env -i unstable.firefox
    

内容的提问来源于stack exchange,提问作者Răzvan Flavius Panda

火山引擎 最新活动