Cannot run basic shell using writeShellScriptBin

Hello,
I did not find the answer here, sorry if I missed it.

(This is done using Home-Manager)

I don’t understand why this works:

(pkgs.writeShellScriptBin "myscript" ''
   #!/usr/bin/env bash
   echo "hello"
'')

but the same content in a file loaded by:

(pkgs.writeShellScriptBin "myscript1" ./bash/myscript.sh)

produces a
/nix/store/c7d6kwci1l2c7rkfgmshir25zzdvgrjb-myscript.sh: Permission denied

I suspect it happens because the file is created as

74099114 -r--r--r-- 1 0 0 36  1 janv.  1970 /nix/store/77zqc8sml6sysrrfs4cblpjcmmamff98-myscript.sh

So, how to make it executable automatically?

Thanks!

1 Like

./bash/myscript.sh is a path, which gets turned into a string /nix/store/c7d6kwci1l2c7rkfgmshir25zzdvgrjb-myscript.sh, it is permission denied probably because the file is not executable. I think you might be looking for (pkgs.writeShellScriptBin "myscript1" (builtins.readFile ./bash/myscript.sh))

1 Like

Exactly - Thank you !

1 Like