Add test and support for binder sub-directory
MODIFY
repo2docker/buildpacks/nix/__init__.py
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):

MODIFY
repo2docker/buildpacks/nix/nix-shell-wrapper
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 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 default.nix --command "./binder/start $@" &
-elif [ -f ./start ]; then
+ nix-shell $nixpath --command "./binder/start $*" &
+ else
+ nix-shell $nixpath --command "$*" &
+ fi
+else
+ nixpath="./default.nix";
+ if [ -f ./start ]; then
chmod u+x ./start
- nix-shell default.nix --command "./start $@" &
+ nix-shell $nixpath --command "./start $*" &
else
- nix-shell default.nix --command "$@" &
+ nix-shell $nixpath --command "$*" &
+ fi
fi
PID=$!
-echo 'waiting'
-
wait "$PID"

MODIFY
tests/nix/binder-dir/README.rst
tests/nix/binder-dir/README.rst
+<<<<<<< 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 <https://nixos.org/nix/manual/#sec-nix-shell>`_.
+>>>>>>> 983b7f5... Add test and support for binder sub-directory

ADD
tests/nix/binder-dir/binder/default.nix
+let
+ # Pinning nixpkgs to specific release
+ # To get sha256 use "nix-prefetch-git <url> --rev <commit>"
+ 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}:."
+ '';
+}

ADD
tests/nix/binder-dir/verify
+#!/usr/bin/env python
+
+import numpy

MODIFY
tests/nix/simple/default.nix
tests/nix/simple/default.nix
@@ -11,6 +11,7 @@ in
pkgs.mkShell {
buildInputs = with pkgs; [
python36Packages.numpy
+ python36Packages.notebook
];
shellHook = ''

MODIFY
tests/nix/start/default.nix
tests/nix/start/default.nix
@@ -11,6 +11,7 @@ in
pkgs.mkShell {
buildInputs = with pkgs; [
python36Packages.numpy
+ python36Packages.notebook
];
shellHook = ''

Add test and support for binder sub-directory