forked from jupyterhub/repo2docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jupyterhub#407 from costrouc/costrouc/nix-buildpack
Adding support for nix buildpack in repo2docker
- Loading branch information
Showing
10 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""BuildPack for nixpkgs environments""" | ||
import os | ||
|
||
from ..base import BuildPack | ||
|
||
|
||
class NixBuildPack(BuildPack): | ||
"""A nix Package Manager BuildPack""" | ||
|
||
def get_path(self): | ||
"""Return paths to be added to PATH environemnt variable | ||
""" | ||
return super().get_path() + [ | ||
'/home/${NB_USER}/.nix-profile/bin' | ||
] | ||
|
||
def get_env(self): | ||
"""Ordered list of environment variables to be set for this image""" | ||
return super().get_env() + [ | ||
('NIX_PATH', "nixpkgs=/home/${NB_USER}/.nix-defexpr/channels/nixpkgs"), | ||
('NIX_SSL_CERT_FILE', '/etc/ssl/certs/ca-certificates.crt'), | ||
('GIT_SSL_CAINFO', '/etc/ssl/certs/ca-certificates.crt') | ||
] | ||
|
||
def get_build_scripts(self): | ||
""" | ||
Return series of build-steps common to all nix repositories. | ||
Notice how only root privileges are needed for creating nix | ||
directory. | ||
- create nix directory for user nix installation | ||
- install nix package manager for user | ||
""" | ||
return super().get_build_scripts() + [ | ||
("root", """ | ||
mkdir -m 0755 /nix && \ | ||
chown -R ${NB_USER}:${NB_USER} /nix /usr/local/bin/nix-shell-wrapper /home/${NB_USER} | ||
"""), | ||
("${NB_USER}", """ | ||
bash /home/${NB_USER}/.local/bin/install-nix.bash && \ | ||
rm /home/${NB_USER}/.local/bin/install-nix.bash | ||
""") | ||
] | ||
|
||
def get_build_script_files(self): | ||
"""Dict of files to be copied to the container image for use in building | ||
""" | ||
return { | ||
"nix/install-nix.bash": "/home/${NB_USER}/.local/bin/install-nix.bash", | ||
"nix/nix-shell-wrapper": "/usr/local/bin/nix-shell-wrapper" | ||
} | ||
|
||
def get_assemble_scripts(self): | ||
"""Return series of build-steps specific to this source repository. | ||
""" | ||
return super().get_assemble_scripts() + [ | ||
('${NB_USER}', """ | ||
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs && \ | ||
nix-channel --update && \ | ||
nix-shell default.nix --command "command -v jupyter" | ||
""") | ||
] | ||
|
||
def get_start_script(self): | ||
"""The path to a script to be executed as ENTRYPOINT""" | ||
return "/usr/local/bin/nix-shell-wrapper" | ||
|
||
def detect(self): | ||
"""Check if current repo should be built with the nix BuildPack""" | ||
return os.path.exists(self.binder_path('default.nix')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
# This downloads and installs a pinned version of nix | ||
set -ex | ||
|
||
NIX_VERSION="2.1.1" | ||
NIX_SHA256="ad10b4da69035a585fe89d7330037c4a5d867a372bb0e52a1542ab95aec67999" | ||
|
||
wget 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 | ||
tar xjf nix-*-x86_64-linux.tar.bz2 | ||
sh nix-*-x86_64-linux/install | ||
rm -r nix-*-x86_64-linux* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
_term() { | ||
echo "Caught SIGTERM signal!" | ||
# kill -TERM "$PID" 2>/dev/null | ||
exit 0 | ||
} | ||
|
||
trap _term SIGTERM | ||
|
||
echo "$*" | ||
nix-shell default.nix --command "$*" & | ||
|
||
PID=$! | ||
wait "$PID" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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>`_. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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.scipy | ||
python36Packages.jupyterlab | ||
]; | ||
|
||
shellHook = '' | ||
export NIX_PATH="nixpkgs=${nixpkgs}:." | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env python | ||
import numpy | ||
import scipy |