Skip to content

shellHook behavior #18

@mzabani

Description

@mzabani

Given the following cached-shell.nix:

{ pkgs ? import <nixpkgs> {} }: pkgs.mkShell { shellHook = ''  echo "Initialize something here (maybe a Postgres Database, for example)"  export SOMEVAR="$OTHERVAR"  ''; }

This is how nix-shell behaves:

$ OTHERVAR=201 nix-shell cached-shell.nix Initialize something here (maybe a Postgres Database, for example) $ echo $SOMEVAR 201

And this is cached-nix-shell (the echo command outputs nothing both with a cached shell and when caching it the first time):

$ OTHERVAR=201 cached-nix-shell cached-shell.nix $ echo $SOMEVAR 

So I think there's a difference in behavior. Would it be correct to say that the correct behavior for cached-nix-shell should be:

  1. Cache a derivation which is the shell derivation without its shellHook attribute. However, take care to cache dependencies that might be brought in by ${some-nix-var} in shellHook's body.
  2. Run shellHook everytime cached-nix-shell runs.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions