If I have a mkShell like this:
buildInputs = with pkgs; [
nativeBuildInputs = with pkgs; [
wrapGAppsHook will create an environment var $GSETTINGS_SCHEMAS_PATH, I can use this var inside $XDG_DATA_DIRS, like this:
shellHook = ''
It’s also possible to create shell env vars inside
mkShell without exporting it inside the
shellHook, but declaring like this:
FOO = BAR
I was thinking in not using
shellHook to declare
XDG_DATA_DIRS. I tried this way:
But it won’t work, it’ll just declare
XDG_DATA_DIRS with the string
"$GSETTINGS_SCHEMAS_PATH" not with the value of
$GSETTINGS_SCHEMAS_PATH. Is there a way to do that outside of
shellHook? I tried with
placeholder is didn’t work.
Nix will not interpolate environment variables. It cannot really interpolate them during evaluation or instantiation since they do not exist yet – the environment variables are only set when builder script is running and after it executes the relevant setup hooks.
Some tools like
make might perform additional interpolations e.g. if you run
make 'PREFIX=$(out)' but values passed to
mkDerivation are mostly just passed to bash as they are (well if they can be stringified).
placeholders will be substituted for the corresponding output path at the beginning of the build but the feature is specific to derivation outputs and does not use environment variables. And the environment variables are not defined yet anyway.
So really if you want to do anything dynamic with the environment, you need to do it in the builder, which can only be done by using hooks.
shellHook is probably okay for
mkShell; in packages, you will have to use some hook that runs after the glib’s env hook.