This seems to be expecting a variable from nix - not the env.
myscript = nixpkgs.writeScriptBin "myscript" ''
#!/usr/bin/env bash
echo "hello ${HOME}"
whoami
'';
What’s the way to have both, shell and nix variable expansion?