作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试探索 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/
我是一名优秀的程序员,十分优秀!