diff --git a/repo2docker/buildpacks/nix/__init__.py b/repo2docker/buildpacks/nix/__init__.py index 4b73cf63..707f6d8a 100644 --- a/repo2docker/buildpacks/nix/__init__.py +++ b/repo2docker/buildpacks/nix/__init__.py @@ -57,8 +57,8 @@ class NixBuildPack(BaseImage): ('${NB_USER}', """ nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs && \ nix-channel --update && \ - nix-shell default.nix - """) + nix-shell {} + """.format(self.binder_path('default.nix'))) ] def get_start_script(self): diff --git a/repo2docker/buildpacks/nix/nix-shell-wrapper b/repo2docker/buildpacks/nix/nix-shell-wrapper index 1a69e13c..859123fd 100644 --- a/repo2docker/buildpacks/nix/nix-shell-wrapper +++ b/repo2docker/buildpacks/nix/nix-shell-wrapper @@ -8,20 +8,25 @@ _term() { trap _term SIGTERM -echo 'command:' "$@" - -# a script in the binder sub-directory take precedence -if [ -f ./binder/start ]; then - chmod u+x ./binder/start - nix-shell default.nix --command "./binder/start $@" & -elif [ -f ./start ]; then - chmod u+x ./start - nix-shell default.nix --command "./start $@" & +# if there is a binder/ sub-directory it takes precedence +# files outside it are ignored +if [ -e ./binder ]; then + nixpath="./binder/default.nix"; + if [ -f ./binder/start ]; then + chmod u+x ./binder/start + nix-shell $nixpath --command "./binder/start $*" & + else + nix-shell $nixpath --command "$*" & + fi else - nix-shell default.nix --command "$@" & + nixpath="./default.nix"; + if [ -f ./start ]; then + chmod u+x ./start + nix-shell $nixpath --command "./start $*" & + else + nix-shell $nixpath --command "$*" & + fi fi PID=$! -echo 'waiting' - wait "$PID" diff --git a/tests/nix/binder-dir/README.rst b/tests/nix/binder-dir/README.rst index 6d79746c..8c6ad2a7 100644 --- a/tests/nix/binder-dir/README.rst +++ b/tests/nix/binder-dir/README.rst @@ -1,4 +1,13 @@ +<<<<<<< HEAD default.nix in a binder/ directory ---------------------------------- Check we find and use `default.nix` when it is in a `binder/` sub-directory. +======= +Nix environment - default.nix +----------------------------- + +You can install a nix shell environment using the traditional default.nix. + +Documentation on the syntax and typical setup of a ``nix-shell`` environment can be found `here `_. +>>>>>>> 983b7f5... Add test and support for binder sub-directory diff --git a/tests/nix/binder-dir/binder/default.nix b/tests/nix/binder-dir/binder/default.nix new file mode 100644 index 00000000..990a193a --- /dev/null +++ b/tests/nix/binder-dir/binder/default.nix @@ -0,0 +1,20 @@ +let + # Pinning nixpkgs to specific release + # To get sha256 use "nix-prefetch-git --rev " + commitRev="5574b6a152b1b3ae5f93ba37c4ffd1981f62bf5a"; + nixpkgs = builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/${commitRev}.tar.gz"; + sha256 = "1pqdddp4aiz726c7qs1dwyfzixi14shp0mbzi1jhapl9hrajfsjg"; + }; + pkgs = import nixpkgs { config = { allowUnfree = true; }; }; +in +pkgs.mkShell { + buildInputs = with pkgs; [ + python36Packages.numpy + python36Packages.notebook + ]; + + shellHook = '' + export NIX_PATH="nixpkgs=${nixpkgs}:." + ''; +} diff --git a/tests/nix/binder-dir/verify b/tests/nix/binder-dir/verify new file mode 100755 index 00000000..dbd34b2a --- /dev/null +++ b/tests/nix/binder-dir/verify @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +import numpy diff --git a/tests/nix/simple/default.nix b/tests/nix/simple/default.nix index d417565f..990a193a 100644 --- a/tests/nix/simple/default.nix +++ b/tests/nix/simple/default.nix @@ -11,6 +11,7 @@ in pkgs.mkShell { buildInputs = with pkgs; [ python36Packages.numpy + python36Packages.notebook ]; shellHook = '' diff --git a/tests/nix/start/default.nix b/tests/nix/start/default.nix index d417565f..990a193a 100644 --- a/tests/nix/start/default.nix +++ b/tests/nix/start/default.nix @@ -11,6 +11,7 @@ in pkgs.mkShell { buildInputs = with pkgs; [ python36Packages.numpy + python36Packages.notebook ]; shellHook = ''