错误:在 Nix 搜索路径中找不到文件“nixpkgs”(使用 $NIX_PATH 或 -I 添加它)

问题描述 投票:0回答:3

我使用

sh <(curl -L https://nixos.org/nix/install) --daemon
来安装 Nix。 安装完成后运行
nix-shell -p nix-info --run "nix-info -m"
来验证安装。 它返回以下错误

Output

warning: Nix search path entry '/nix/var/nix/profiles/per-user/kana/channels' does not exist, ignoring
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «string»:1:25:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (nix-info) ]; } ""
             |                         ^
(use '--show-trace' to show detailed location information)
ubuntu installation nix nixos nixpkgs
3个回答
9
投票

我也有同样的问题。在新安装的 Ubuntu 22.04.2 LTS 上,我的脚本中对

<nixkpgs>
的每次引用都失败,并出现您所描述的错误消息。

我的解决方案:

nix-channel --add https://nixos.org/channels/nixpkgs-unstable
nix-channel --update

对于 nixpkgs 的特定稳定版本,您可以运行如下命令:

nix-channel --add https://nixos.org/channels/nixos-23.11 nixpkgs
nix-channel --update

为了验证您的问题实际上是我的问题,

nix-channel --list
的输出对我来说是空的。

我猜安装有错误。我像您一样使用了多用户安装过程。


2
投票

确保 nix 环境文件来源正确。尝试启动一个新终端,如https://nix.dev/tutorials/install-nix#verify-installation

中所述

-1
投票

最终对我有用的是把事情掌握在自己手中并手动设置 NIX_PATH 变量,如下所示:

export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/74e2faf5965a12e8fa5cff799b1b19c6cd26b0e3.tar.gz

(我最终将其添加到我的

~/.bashrc
~./zshrc files
中)。顺便说一句,我用的是 MacBook。

© www.soinside.com 2019 - 2024. All rights reserved.