【问题标题】:What is the equivilent shell.nix for nix-shell '<nixpkgs>' -A gnusednix-shell '<nixpkgs>' -A gnused 的等效 shell.nix 是什么
【发布时间】:2020-09-19 06:51:07
【问题描述】:

我正在尝试探索 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

【问题讨论】:

    标签: nix nix-shell


    【解决方案1】:

    在等了几天没有得到回复后,我找到了thistalk,结合 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 '&lt;nixpkgs&gt;' 调用nix repl,然后键入gnused.,然后按tab 完成或使用nix edit nixpkgs.gnused,这将在@987654339 设置的编辑器中打开派生@。

    【讨论】:

    • 非常感谢您进行这项研究!
    猜你喜欢
    • 1970-01-01
    • 2019-11-22
    • 2018-05-02
    • 2022-11-17
    • 2020-02-04
    • 2017-03-24
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    相关资源
    最近更新 更多