diff --git a/repo2docker/buildpacks/nix/nix-shell-wrapper b/repo2docker/buildpacks/nix/nix-shell-wrapper index 7490d78e..e9c8d71a 100644 --- a/repo2docker/buildpacks/nix/nix-shell-wrapper +++ b/repo2docker/buildpacks/nix/nix-shell-wrapper @@ -8,38 +8,38 @@ _term() { trap _term SIGTERM +# if there is a binder/ sub-directory it takes precedence +# files outside it are ignored # find binder sub-directory (if present) -for dir in "./.binder" "./binder"; do +binder_dir="./" +for dir in "./binder" "./.binder" ; do if [ -e $dir ]; then binder_dir=$dir + break fi done -# if there is a binder/ sub-directory it takes precedence -# files outside it are ignored -if [ -z $binder_dir ]; then - nixpath="$binder_dir/default.nix"; - if [ -f $binder_dir/start ]; then - chmod u+x $binder_dir/start - # Using `$@`` here which is what the internet recommends leads to - # errors when the command is something like `jupyter --ip=0.0.0.0 ...` - # as nix-shell picks that up as an argument to it instead of the command. - # There are several issues on the nix repos discussing this and adding support - # for -- to indicate "all arguments after this are for the command, not nix-shell" - # but it seems they have stalled/not yet produced an implementation. - # So let's use `$*` for now. - nix-shell $nixpath --command "$binder_dir/start $*" & - else - nix-shell $nixpath --command "$*" & - fi +# raise error if both binder and .binder are found +if [[ -d "./binder" && -d "./.binder" ]]; then + echo "Error: Found both binder and .binder directories." + exit 1 +fi + +echo "binder_dir is: $binder_dir" + +nixpath="$binder_dir/default.nix"; +if [ -f $binder_dir/start ]; then + chmod u+x $binder_dir/start + # Using `$@`` here which is what the internet recommends leads to + # errors when the command is something like `jupyter --ip=0.0.0.0 ...` + # as nix-shell picks that up as an argument to it instead of the command. + # There are several issues on the nix repos discussing this and adding support + # for -- to indicate "all arguments after this are for the command, not nix-shell" + # but it seems they have stalled/not yet produced an implementation. + # So let's use `$*` for now. + nix-shell $nixpath --command "$binder_dir/start $*" & else - nixpath="./default.nix"; - if [ -f ./start ]; then - chmod u+x ./start - nix-shell $nixpath --command "./start $*" & - else - nix-shell $nixpath --command "$*" & - fi + nix-shell $nixpath --command "$*" & fi PID=$!