about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/manual/nix-shell.xml16
-rwxr-xr-xscripts/nix-build.in1
2 files changed, 17 insertions, 0 deletions
diff --git a/doc/manual/nix-shell.xml b/doc/manual/nix-shell.xml
index e57c726f5394..4b369662e2af 100644
--- a/doc/manual/nix-shell.xml
+++ b/doc/manual/nix-shell.xml
@@ -51,6 +51,22 @@ derivation for development.</para>
 <filename>shell.nix</filename> if it exists, and
 <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>
 
 
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index fff71021fbf8..c197dcca9a12 100755
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -207,6 +207,7 @@ foreach my $expr (@exprs) {
             ($pure ? '' : 'p=$PATH; ' ) .
             'dontAddDisableDepTrack=1; ' .
             '[ -e $stdenv/setup ] && source $stdenv/setup; ' .
+            'if [ "$(type -t runHook)" = function ]; then runHook shellHook; fi; ' .
             ($pure ? '' : 'PATH=$PATH:$p; unset p; ') .
             'set +e; ' .
             '[ -n "$PS1" ] && PS1="\n\[\033[1;32m\][nix-shell:\w]$\[\033[0m\] "; ' .