kopia lustrzana https://github.com/jupyterhub/repo2docker
Inherit from BaseImage instead of BuildPack
rodzic
5ea4e31347
commit
046b744785
|
@ -1,10 +1,10 @@
|
||||||
"""BuildPack for nixpkgs environments"""
|
"""BuildPack for nixpkgs environments"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ..base import BuildPack
|
from ..base import BuildPack, BaseImage
|
||||||
|
|
||||||
|
|
||||||
class NixBuildPack(BuildPack):
|
class NixBuildPack(BaseImage):
|
||||||
"""A nix Package Manager BuildPack"""
|
"""A nix Package Manager BuildPack"""
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self):
|
||||||
|
@ -57,12 +57,14 @@ class NixBuildPack(BuildPack):
|
||||||
('${NB_USER}', """
|
('${NB_USER}', """
|
||||||
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs && \
|
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs && \
|
||||||
nix-channel --update && \
|
nix-channel --update && \
|
||||||
nix-shell default.nix --command "command -v jupyter"
|
nix-shell default.nix
|
||||||
""")
|
""")
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_start_script(self):
|
def get_start_script(self):
|
||||||
"""The path to a script to be executed as ENTRYPOINT"""
|
"""The path to a script to be executed as ENTRYPOINT"""
|
||||||
|
# the shell wrapper script duplicates the behaviour of other buildpacks
|
||||||
|
# when it coems to the `start` script
|
||||||
return "/usr/local/bin/nix-shell-wrapper"
|
return "/usr/local/bin/nix-shell-wrapper"
|
||||||
|
|
||||||
def detect(self):
|
def detect(self):
|
||||||
|
|
|
@ -5,7 +5,7 @@ set -ex
|
||||||
NIX_VERSION="2.1.1"
|
NIX_VERSION="2.1.1"
|
||||||
NIX_SHA256="ad10b4da69035a585fe89d7330037c4a5d867a372bb0e52a1542ab95aec67999"
|
NIX_SHA256="ad10b4da69035a585fe89d7330037c4a5d867a372bb0e52a1542ab95aec67999"
|
||||||
|
|
||||||
wget https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-x86_64-linux.tar.bz2
|
wget --quiet https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-x86_64-linux.tar.bz2
|
||||||
echo "$NIX_SHA256 nix-2.1.1-x86_64-linux.tar.bz2" | sha256sum -c
|
echo "$NIX_SHA256 nix-2.1.1-x86_64-linux.tar.bz2" | sha256sum -c
|
||||||
tar xjf nix-*-x86_64-linux.tar.bz2
|
tar xjf nix-*-x86_64-linux.tar.bz2
|
||||||
sh nix-*-x86_64-linux/install
|
sh nix-*-x86_64-linux/install
|
||||||
|
|
|
@ -8,8 +8,20 @@ _term() {
|
||||||
|
|
||||||
trap _term SIGTERM
|
trap _term SIGTERM
|
||||||
|
|
||||||
echo "$*"
|
echo 'command:' "$@"
|
||||||
nix-shell default.nix --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 $@" &
|
||||||
|
else
|
||||||
|
nix-shell default.nix --command "$@" &
|
||||||
|
fi
|
||||||
|
|
||||||
PID=$!
|
PID=$!
|
||||||
|
echo 'waiting'
|
||||||
|
|
||||||
wait "$PID"
|
wait "$PID"
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
default.nix in a binder/ directory
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
Check we find and use `default.nix` when it is in a `binder/` sub-directory.
|
|
@ -11,8 +11,6 @@ in
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
python36Packages.numpy
|
python36Packages.numpy
|
||||||
python36Packages.scipy
|
|
||||||
python36Packages.jupyterlab
|
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import numpy
|
import numpy
|
||||||
import scipy
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
Check `start` works with nix
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
In this example we set a environment variable in the `start` script and check
|
||||||
|
it works when using the nix build pack.
|
|
@ -0,0 +1,19 @@
|
||||||
|
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
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
export NIX_PATH="nixpkgs=${nixpkgs}:."
|
||||||
|
'';
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export TEST_START_VAR="var is set"
|
||||||
|
|
||||||
|
exec "$@"
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# set value of TEST_START_VAR to empty string when it is not defined
|
||||||
|
if [ "${TEST_START_VAR:-}" != "var is set" ]
|
||||||
|
then
|
||||||
|
echo "TEST_START_VAR is not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
Ładowanie…
Reference in New Issue