我正在尝试探索gnu sed代码库。
我可以从命令行执行此操作:
nix-shell '<nixpkgs>' -A gnused
unpackPhase
cd sed-4.8
configurePhase
buildPhase,然后在sed等下编辑代码。
但是,我想使用未安装的ctag:
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发布于 2020-09-21 21:56:04
在等待了几天之后,我发现了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个输入参数,在这种情况下,有意将第3个参数留空。
要将两者结合起来,我们使用override,但不使用gnused.override,它将覆盖gnused的mkDerivation参数,而使用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设置的编辑器中打开派生。
https://stackoverflow.com/questions/63966084
复制相似问题