在等待了几天并没有得到回应后,我发现了这个演讲,结合 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 个输入参数,在这种情况下,第 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 使用nix repl '<nixpkgs>'
并键入gnused.
,然后按 Tab 完成或使用nix edit nixpkgs.gnused
,这将在由 设置的编辑器中打开派生$EDITOR
。