writeScriptBin variable expansion or quoting

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?

you can escape that $ with echo "hello ''${HOME}" (this kind of escape if for double single-quoted strings ''some string ''${SOMEENV}'' , for double-quoted strings use simple backslash
check this Nix Pills | Nix & NixOS

2 Likes