gpt4 book ai didi

nix - nix-shell '' -A gnused 的等效 shell.nix 是什么

转载 作者:行者123 更新时间:2023-12-05 02:49:37 26 4
gpt4 key购买 nike

我正在尝试探索 gnu sed 代码库。

我可以从命令行执行此操作:

nix-shell '<nixpkgs>' -A gnused
unpackPhase
cd sed-4.8
configurePhase
buildPhase

然后在sed等下面编辑代码

但是我想使用未安装的 ctags:

nix-shell -p ctags

安装包但是:

nix-shell '<nixpkgs>' -A gnused -p ctags

获取错误:

error: attribute 'gnused' in selection path 'gnused' not found

我意识到我必须使用 shell.nix,但找不到上面的 mkShell 示例。

附言两次调用 nix-shell 达到了所需的结果,但这似乎很笨拙:

nix-shell -p ctags
nix-shell '<nixpkgs>' -A gnused

最佳答案

等了几天没有得到任何回应后,我找到了this talk,结合 nix-shell、nix-build 和 nix-instantiate 手册页中的示例,产生了所需的答案。

相当于:

nix-shell '<nixpkgs>' -A gnused

是:

nix-shell -E 'with import <nixpkgs> {}; gnused'

或作为 shell.nix:

# shell.nix
with import <nixpkgs> {};
gnused

相当于:

nix-shell -p ctags

是:

nix-shell -E 'with import <nixpkgs> {}; runCommand "dummy" { buildInputs = [ ctags ]; } ""'

或作为 shell.nix:

# shell.nix
with import <nixpkgs> {};
runCommand "dummy" { buildInputs = [ ctags ]; } ""

注意runCommand采用 3 个输入参数,在本例中,第三个参数有意留空。

为了结合两者,我们使用覆盖而不是 gnused.override这将覆盖 mkDerivation 的参数对于 gnused,我们使用 gnused.overrideAttrs它会覆盖 mkDerivation 中的属性.

nix-shell -E 'with import <nixpkgs> {}; gnused.overrideAttrs (oldAttrs: { buildInputs = [ ctags ]; })'

或作为 shell.nix:

# shell.nix
with import <nixpkgs> {};
gnused.overrideAttrs (oldAttrs: { buildInputs = [ ctags ]; })

注意查找派生的属性,例如 gnused , 使用 nix repl '<nixpkgs>' 调用 nix repl然后输入 gnused.然后按 Tab 键完成或使用 nix edit nixpkgs.gnused这将在 $EDITOR 设置的编辑器中打开推导.

关于nix - nix-shell '<nixpkgs>' -A gnused 的等效 shell.nix 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63966084/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com