Skip to content

persist nix-shell instance across example steps #130

@warren2k

Description

@warren2k

This issue is in reference to the thaigersprint-2025 branch of eelco.

Current example of shell-session workflow

shell.nix:

let
  pkgs = import <nixpkgs> { config = {}; overlays = []; };
in

pkgs.mkShellNoCC {
  packages = with pkgs; [
    direnv
    which
    hello
  ];
}
$ echo "use nix" > .envrc
$ nix-shell
...
$ direnv allow
...
$ which hello
/nix/store/...-hello-...

Currently, the shell-session below cannot be executed successfully because it's not persisted from the previous step. The only way to make it work is to re-launch nix-shell and re-execute direnv allow, which seems unnecessarily repetitive:

$ which hello
/nix/store/...-hello-...

Desired behavior of shell-session workflow

I'd like to avoid having to specify packages in shell.nix in order to work around the fact that nix-shell instances are not persisted across example steps. I'd like to be able to use packages installed in a previous launch of nix-shell in subsequent steps of an example, like so:

shell.nix:

let
  pkgs = import <nixpkgs> { config = {}; overlays = []; };
in

pkgs.mkShellNoCC {
  packages = with pkgs; [
    hello
  ];
}
$ echo "use nix" > .envrc
$ NIX_SHELL_PRESERVE_PROMPT=1 nix-shell -p direnv which
...
$ direnv allow
...
$ which hello
/nix/store/...-hello-...

This would enable examples to better align with the flow of the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions