I am trying to update the path environment variable on a layer I am building, but it doesn’t look like it is possible:
pkgs.dockerTools.buildImage {
name = "flutter-env";
fromImage = fromImage;
config = {
Env = [
"FLUTTER_HOME=${FLUTTER_HOME}" # Works
"PATH=\${PATH}:${FLUTTER_HOME}/bin:${FLUTTER_HOME}/bin/cache/dart-sdk/bin"# Does not work
];
};
};
I assume what you want here is to simply use bash’s variable interpretation at runtime (${PATH}). That’s also the syntax for string interpolation in Nix though, so what’s actually happening is that Nix tries to resolve the variable PATH which isn’t defined. Because of that, your code snippet should give you an evaluation error though, not insert the literal string ${PATH}.
If my assumption is correct, you must escape it using ''$... like this:
"PATH=''${PATH}:${FLUTTER_HOME}/bin:${FLUTTER_HOME}/bin/cache/dart-sdk/bin"# Should work
That would be the case if this was a multi-line string. It is a single line string so \$ is correct. I get error: undefined variable 'PATH' with the example you provided. I am able to verify that the literal ${PATH} value is on path by adding /bin (so I can still access bash).