等了几天后,我发现没有得到任何回复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
.