Reputation: 58578
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 I can't find a mkShell example for the above.
P.S. Two invocations of nix-shell achieve the required result but this seems unwieldy:
nix-shell -p ctags
nix-shell '<nixpkgs>' -A gnused
Upvotes: 4
Views: 1017
Reputation: 58578
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 ]; } ""
N.B. 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 ]; })
N.B. 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
.
Upvotes: 5