From 136bc53720a0424acc7e9c3a2f5402c8ebd76a3e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 3 Jan 2021 18:13:19 +0100 Subject: persistent-nix-shell --- overlays/persistent-nix-shell/default.nix | 19 +++++++++++++++++++ overlays/persistent-nix-shell/persistent-nix-shell | 20 ++++++++++++++++++++ user-profiles/utils.nix | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 overlays/persistent-nix-shell/default.nix create mode 100644 overlays/persistent-nix-shell/persistent-nix-shell diff --git a/overlays/persistent-nix-shell/default.nix b/overlays/persistent-nix-shell/default.nix new file mode 100644 index 00000000..60396335 --- /dev/null +++ b/overlays/persistent-nix-shell/default.nix @@ -0,0 +1,19 @@ +final: prev: { + persistent-nix-shell = prev.stdenv.mkDerivation { + name = "persistent-nix-shell"; + src = ./persistent-nix-shell; + + phases = [ "buildPhase" "installPhase" ]; + + inherit (final) zsh; + + buildPhase = '' + substituteAll $src persistent-nix-shell + ''; + + installPhase = '' + install -m 0755 -D -t $out/bin \ + persistent-nix-shell + ''; + }; +} diff --git a/overlays/persistent-nix-shell/persistent-nix-shell b/overlays/persistent-nix-shell/persistent-nix-shell new file mode 100644 index 00000000..a17f6de6 --- /dev/null +++ b/overlays/persistent-nix-shell/persistent-nix-shell @@ -0,0 +1,20 @@ +#!@zsh@/bin/zsh + +set -e + +gcrootsDir=${PWD}/.nix-gc-roots + +if [[ ${#@} -ge 1 ]]; then + shellFile=${1} + shift +else + shellFile=${PWD}/shell.nix +fi + +set -x +mkdir -p ${gcrootsDir} +nix-instantiate ${shellFile} --indirect --add-root ${gcrootsDir}/shell.drv +nix-store --indirect --add-root ${gcrootsDir}/shell.dep --realise $(nix-store --query --references ${gcrootsDir}/shell.drv) +set +x + +exec nix-shell $(readlink ${gcrootsDir}/shell.drv) ${@} diff --git a/user-profiles/utils.nix b/user-profiles/utils.nix index 8b34279d..484af0a3 100644 --- a/user-profiles/utils.nix +++ b/user-profiles/utils.nix @@ -17,7 +17,7 @@ qrencode tty-clock dnsutils openssl sshfs psmisc mosh tree vnstat file pv bc fast-cli zip nmap aspell aspellDicts.de aspellDicts.en borgbackup man-pages rsync socat telnet yq - cached-nix-shell + cached-nix-shell persistent-nix-shell ]; }; } -- cgit v1.2.3