mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 05:56:15 +02:00
nix-shell: Execute shellHook if it exists
Since normal builds don't execute shellHook, this allows nix-shell specific customisation. Suggested by Domen.
This commit is contained in:
parent
832377bbd6
commit
e81d38c02b
2 changed files with 17 additions and 0 deletions
|
@ -51,6 +51,22 @@ derivation for development.</para>
|
||||||
<filename>shell.nix</filename> if it exists, and
|
<filename>shell.nix</filename> if it exists, and
|
||||||
<filename>default.nix</filename> otherwise.</para>
|
<filename>default.nix</filename> otherwise.</para>
|
||||||
|
|
||||||
|
<para>If the derivation defines the variable
|
||||||
|
<varname>shellHook</varname>, it will be evaluated after
|
||||||
|
<literal>$stdenv/setup</literal> has been sourced. Since this hook is
|
||||||
|
not executed by regular Nix builds, it allows you to perform
|
||||||
|
initialisation specific to <command>nix-shell</command>. For example,
|
||||||
|
the derivation attribute
|
||||||
|
|
||||||
|
<programlisting>
|
||||||
|
shellHook =
|
||||||
|
''
|
||||||
|
echo "Hello shell!"
|
||||||
|
'';
|
||||||
|
</programlisting>
|
||||||
|
|
||||||
|
will cause <command>nix-shell</command> to print <literal>Hello shell!</literal>.</para>
|
||||||
|
|
||||||
</refsection>
|
</refsection>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -207,6 +207,7 @@ foreach my $expr (@exprs) {
|
||||||
($pure ? '' : 'p=$PATH; ' ) .
|
($pure ? '' : 'p=$PATH; ' ) .
|
||||||
'dontAddDisableDepTrack=1; ' .
|
'dontAddDisableDepTrack=1; ' .
|
||||||
'[ -e $stdenv/setup ] && source $stdenv/setup; ' .
|
'[ -e $stdenv/setup ] && source $stdenv/setup; ' .
|
||||||
|
'if [ "$(type -t runHook)" = function ]; then runHook shellHook; fi; ' .
|
||||||
($pure ? '' : 'PATH=$PATH:$p; unset p; ') .
|
($pure ? '' : 'PATH=$PATH:$p; unset p; ') .
|
||||||
'set +e; ' .
|
'set +e; ' .
|
||||||
'[ -n "$PS1" ] && PS1="\n\[\033[1;32m\][nix-shell:\w]$\[\033[0m\] "; ' .
|
'[ -n "$PS1" ] && PS1="\n\[\033[1;32m\][nix-shell:\w]$\[\033[0m\] "; ' .
|
||||||
|
|
Loading…
Reference in a new issue