Skip to content

Commit 5c4c2dc

Browse files
committed
buildpacks/nix: disable sandboxing
The version bump #915 broke the Nix buildpack in case one does a build. Nix 2.3 enables sandboxing by default. Building inside a Docker container, while Nix is having sandboxing enabled is not possible. Thus, sandbox = false should be set in /etc/nix/nix.conf.
1 parent f3229c1 commit 5c4c2dc

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

repo2docker/buildpacks/nix/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ def get_build_scripts(self):
2323
"""
2424
Return series of build-steps common to all nix repositories.
2525
Notice how only root privileges are needed for creating nix
26-
directory.
26+
directory and a nix.conf file.
2727
2828
- create nix directory for user nix installation
29+
- disable sandboxing because its unsupported inside a Docker container
2930
- install nix package manager for user
31+
3032
"""
3133
return super().get_build_scripts() + [
3234
(
3335
"root",
3436
"""
3537
mkdir -m 0755 /nix && \
36-
chown -R ${NB_USER}:${NB_USER} /nix /usr/local/bin/nix-shell-wrapper /home/${NB_USER}
38+
chown -R ${NB_USER}:${NB_USER} /nix /usr/local/bin/nix-shell-wrapper /home/${NB_USER} && \
39+
mkdir -p /etc/nix && \
40+
touch /etc/nix/nix.conf && \
41+
echo "sandbox = false" >> /etc/nix/nix.conf
3742
""",
3843
),
3944
(

tests/nix/test-building/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Check that we can build
2+
-----------------------
3+
4+
Test that actual building instead of substituting (downloading an existing build) works.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let
2+
# Pinning nixpkgs to specific release
3+
# To get sha256 use "nix-prefetch-git <url> --rev <commit>"
4+
commitRev="5574b6a152b1b3ae5f93ba37c4ffd1981f62bf5a";
5+
nixpkgs = builtins.fetchTarball {
6+
url = "https://github.com/NixOS/nixpkgs/archive/${commitRev}.tar.gz";
7+
sha256 = "1pqdddp4aiz726c7qs1dwyfzixi14shp0mbzi1jhapl9hrajfsjg";
8+
};
9+
pkgs = import nixpkgs { config = { allowUnfree = true; }; };
10+
11+
# Test that we can actually build
12+
test-build = pkgs.runCommand "test-build" { } ''
13+
touch $out
14+
'';
15+
16+
in
17+
pkgs.mkShell {
18+
buildInputs = with pkgs; [
19+
python36Packages.numpy
20+
python36Packages.notebook
21+
test-build
22+
];
23+
24+
shellHook = ''
25+
export NIX_PATH="nixpkgs=${nixpkgs}:."
26+
'';
27+
}

tests/nix/test-building/verify

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
3+
import numpy

0 commit comments

Comments
 (0)