(Replit) Nix:如何将包添加到 .nix?

(Replit) Nix: How do I add a package to .nix?

编辑:


我有一个 python 脚本,我需要通过 运行 宁 python3 myscript.py 来 运行 该脚本,但是我收到此消息:

python3: command not installed. Multiple versions of this command were found in Nix.

然后在选择.out时,python开始。

我发现我需要将 python3 添加到 .nix 以便 nix 可以自动 运行 python39Full 如果我键入 python3,以便跳过上面的消息。

Add 'python39Full' to replit.nix if you want to install 'python3' in this repl.

不幸的是,我不知道如何将包添加到 .nix,所以谁能告诉我如何将包添加到 .nix?谢谢。

(如果您需要查看 .nix 文件)

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
    ];
}

幸运的是,我找到了一种将包添加到 .nix 的方法(至少在 replit 上):


如果您想跳过以下消息:

python3: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
> 
qtile.out
python39Full.out
python38Full.out
python3Minimal.out
python310.out
python37Full.out
python37.out
python38.out
sourcehut.python.out
python36.out

  1. 获取你希望 nix 自动选择的包名称(在我的例子中我将使用 python39Full.out)

  1. 打开 .nix 文件,它看起来像这样:

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
    ];
}

  1. 将包名称添加到 .nix,因此 .nix 现在看起来像这样:

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
        python39Full.out
    ];
}

  1. 在包名的开头添加'pkgs.',并从包名中删除'.out',所以.nix文件现在是:

replit.nix

{ pkgs }: {
    deps = [
        pkgs.bashInteractive
        pkgs.python39Full
    ];
}

  1. 保存文件,下次你运行python3,nix不会每次都问你,它会自动为你启动python 3.9

演示

john@doe:~$ python3 
Python 3.9.6 (default, Jun 28 2021, 08:57:49) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>