nix - nix-shell 的等效 shell.nix 是什么?' - 一个 gnused
问题描述
我正在尝试探索 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 示例。
PS 两次调用 nix-shell 实现了所需的结果,但这似乎很笨拙:
nix-shell -p ctags
nix-shell '<nixpkgs>' -A gnused
解决方案
在等待了几天并没有得到回应后,我发现了这个演讲,结合 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
。
推荐阅读
- python - 图无法按拓扑顺序排序
- r - 从长格式数据框中计算股票收益
- java - 过滤列表后点击 ListView Item
- jquery - 即使填写了必填字段,Jquery Validate 插件也会引发错误
- laravel - Laravel、Vuejs、axios 获取登录用户的帖子
- android - 改造预期为 BEGIN_OBJECT,但为 STRING
- ios - 是否可以制作包含 SwiftUI 的 Swift 项目模板?
- android - 如何将数据从 Android 中的数据报套接字发送到 Node js 服务器?
- php - 如何在 Laravel 中从 json 索引计数
- node.js - 在 Vagrant 框中连接 Angular 到 Node/express