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

2024-02-17

我正在尝试探索 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 https://www.youtube.com/watch?v=6VepnulTfu8talk,结合 nix-shell、nix-build 和 nix-instantiate 手册页中的示例,产生了所需的答案。

相当于:

nix-shell '<nixpkgs>' -A gnused

is:

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

或作为 shell.nix:

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

相当于:

nix-shell -p ctags

is:

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 replnix repl '<nixpkgs>'并输入gnused.然后按 Tab 完成或使用nix edit nixpkgs.gnused这将在编辑器中打开推导$EDITOR.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

nix-shell '' -A gnused 的等效 shell.nix 是什么 的相关文章

随机推荐