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:
- 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.
- Run
shellHook everytime cached-nix-shell runs.
Thanks in advance!
Given the following
cached-shell.nix:This is how
nix-shellbehaves:And this is
cached-nix-shell(theechocommand outputs nothing both with a cached shell and when caching it the first time):So I think there's a difference in behavior. Would it be correct to say that the correct behavior for
cached-nix-shellshould be:shellHookattribute. However, take care to cache dependencies that might be brought in by${some-nix-var}inshellHook's body.shellHookeverytimecached-nix-shellruns.Thanks in advance!