summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2020-02-19 14:57:11 +0100
committerAdrian Kummerlaender2020-02-19 14:57:11 +0100
commit6118a3f382d9e136575da6a64a444af08eef2363 (patch)
treeb6354c3ab5f9f3acecdefff0cb2e1a78ea42bfce
parent18d2edf330e6932c177e71b1c7831a7a5ad77e38 (diff)
downloadpkgs-6118a3f382d9e136575da6a64a444af08eef2363.tar
pkgs-6118a3f382d9e136575da6a64a444af08eef2363.tar.gz
pkgs-6118a3f382d9e136575da6a64a444af08eef2363.tar.bz2
pkgs-6118a3f382d9e136575da6a64a444af08eef2363.tar.lz
pkgs-6118a3f382d9e136575da6a64a444af08eef2363.tar.xz
pkgs-6118a3f382d9e136575da6a64a444af08eef2363.tar.zst
pkgs-6118a3f382d9e136575da6a64a444af08eef2363.zip
Add some flags to persistent-nix-shell wrapper
-rw-r--r--pkgs/persistent-nix-shell/default.nix13
-rw-r--r--pkgs/persistent-nix-shell/persistent-nix-shell.sh27
2 files changed, 28 insertions, 12 deletions
diff --git a/pkgs/persistent-nix-shell/default.nix b/pkgs/persistent-nix-shell/default.nix
index 8a74eb4..5e53ee6 100644
--- a/pkgs/persistent-nix-shell/default.nix
+++ b/pkgs/persistent-nix-shell/default.nix
@@ -5,16 +5,5 @@ pkgs.writeTextFile {
executable = true;
destination = "/bin/persistent-nix-shell";
- text = ''
- #!/bin/sh -eu
-
- mkdir -p .gcroots
-
- 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
-
- # Fix to prevent implicit interactiveBash dependency
- export NIX_BUILD_SHELL=/run/current-system/sw/bin/bash
- exec nix-shell $(readlink $PWD/.gcroots/shell.drv) "$@"
- '';
+ text = builtins.readFile ./persistent-nix-shell.sh;
}
diff --git a/pkgs/persistent-nix-shell/persistent-nix-shell.sh b/pkgs/persistent-nix-shell/persistent-nix-shell.sh
new file mode 100644
index 0000000..b9ecfbc
--- /dev/null
+++ b/pkgs/persistent-nix-shell/persistent-nix-shell.sh
@@ -0,0 +1,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