summaryrefslogtreecommitdiff
path: root/pkgs/persistent-nix-shell/default.nix
blob: 8a74eb4ed17e83deb13ac540b4bb28ad55ac8ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{ stdenv, pkgs, ... }:

pkgs.writeTextFile {
  name        = "persistent-nix-shell";
  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) "$@"
  '';
}