summaryrefslogtreecommitdiff
path: root/pkgs/persistent-nix-shell/persistent-nix-shell.sh
blob: b9ecfbcd124985a16f5677a6ce8fc542301e691e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh -eu

mkdir -p .gcroots

inherit_shell=''
update=''

while getopts 'su' flag; do
	case "${flag}" in
		s) inherit_shell='true' ;;
		u) update='true' ;;
	esac
done

if [[ ! -f "$PWD/.gcroots/shell.drv" || $update ]]; then
	nix-instantiate shell.nix --indirect --add-root $PWD/.gcroots/shell.drv > /dev/null
	nix-store -r $(nix-store --query --references $PWD/.gcroots/shell.drv) --indirect --add-root $PWD/.gcroots/shell.dep > /dev/null
fi

# Fix to prevent implicit interactiveBash dependency
export NIX_BUILD_SHELL=/run/current-system/sw/bin/bash

if [ $inherit_shell ]; then
	exec nix-shell $(readlink $PWD/.gcroots/shell.drv) --command $SHELL
else
	exec nix-shell $(readlink $PWD/.gcroots/shell.drv)
fi