简体   繁体   中英

What is the equivilent shell.nix for nix-shell '<nixpkgs>' -A gnused

I am trying to explore the gnu sed code base.

I can do this from the command line:

nix-shell '<nixpkgs>' -A gnused
unpackPhase
cd sed-4.8
configurePhase
buildPhase

and then edit the code under sed etc

However I would like to use ctags which is not installed:

nix-shell -p ctags

Installs the package but:

nix-shell '<nixpkgs>' -A gnused -p ctags

gets the error:

error: attribute 'gnused' in selection path 'gnused' not found

I realise I must use a shell.nix but can't find a mkShell example for the above.

PS Two invocations of nix-shell achieve the required result but this seems unwieldy:

nix-shell -p ctags
nix-shell '<nixpkgs>' -A gnused

After waiting a couple of days and getting no response I found this talk, which in combination with the examples in the man pages of nix-shell, nix-build and nix-instantiate, produced the required answer.

The equivalent of:

nix-shell '<nixpkgs>' -A gnused

is:

nix-shell -E 'with import <nixpkgs> {}; gnused'

or as a shell.nix:

# shell.nix
with import <nixpkgs> {};
gnused

The equivalent of:

nix-shell -p ctags

is:

nix-shell -E 'with import <nixpkgs> {}; runCommand "dummy" { buildInputs = [ ctags ]; } ""'

or as a shell.nix:

# shell.nix
with import <nixpkgs> {};
runCommand "dummy" { buildInputs = [ ctags ]; } ""

NB The runCommand takes the 3 input parameters, in this case the 3rd parameter is purposely left blank.

To combine both, we use an override but not gnused.override which would override the arguments of mkDerivation for gnused, instead we use gnused.overrideAttrs which overrides the attributes inside of mkDerivation .

nix-shell -E 'with import <nixpkgs> {}; gnused.overrideAttrs (oldAttrs: { buildInputs = [ ctags ]: })'

or as a shell.nix:

# shell.nix
with import <nixpkgs> {};
gnused.overrideAttrs (oldAttrs: { buildInputs = [ ctags ]; })

NB To find the attributes of a derivation such as gnused , invoke the nix repl using nix repl '<nixpkgs>' and type gnused. and then press tab for completion or use nix edit nixpkgs.gnused which will open up the derivation in the editor set by $EDITOR .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM