about summary refs log tree commit diff
path: root/tools/nixery/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-07-24T17·46+0000
committerVincent Ambo <tazjin@google.com>2019-07-24T17·46+0000
commit948f308025e5d1a3a4575b41d4b20d97f363c5c2 (patch)
treedc6a0515e95216025129fb5af315c0ad6747fbb5 /tools/nixery/default.nix
parent18b4ae9f28ae4b56df1529eaca8039e326df64e1 (diff)
feat(build): Configure Nixery image builder to set up env correctly
When running Nix inside of a container image, there are several
environment-specific details that need to be configured appropriately.

Most importantly, since one of the recent Nix 2.x releases, sandboxing
during builds is enabled by default. This, however, requires kernel
privileges which commonly aren't available to containers.

Nixery's demo instance (for instance, hehe) is deployed on AppEngine
where this type of container configuration is difficult, hence this
change.

Specifically the following were changed:

* additional tools (such as tar/gzip) were introduced into the image
  because the builtins-toolset in Nix does not reference these tools
  via their store paths, which leads to them not being included
  automatically
* Nix sandboxing was disabled in the container image
* the users/groups required by Nix were added to the container setup.
  Note that these are being configured manually instead of via the
  tools from the 'shadow'-package, because the latter requires some
  user information (such as root) to be present already, which is not
  the case inside of the container
Diffstat (limited to 'tools/nixery/default.nix')
-rw-r--r--tools/nixery/default.nix30
1 files changed, 27 insertions, 3 deletions
diff --git a/tools/nixery/default.nix b/tools/nixery/default.nix
index c7f284f033d1..64cb061c308c 100644
--- a/tools/nixery/default.nix
+++ b/tools/nixery/default.nix
@@ -36,7 +36,7 @@ rec {
     meta = {
       description = "Container image build serving Nix-backed images";
       homepage    = "https://github.com/google/nixery";
-      license     = lib.licenses.ascl20;
+      license     = lib.licenses.asl20;
       maintainers = [ lib.maintainers.tazjin ];
     };
   };
@@ -69,13 +69,37 @@ rec {
   # Container image containing Nixery and Nix itself. This image can
   # be run on Kubernetes, published on AppEngine or whatever else is
   # desired.
-  nixery-image = dockerTools.buildLayeredImage {
+  nixery-image = let
+    # Wrapper script for the wrapper script (meta!) which configures
+    # the container environment appropriately.
+    #
+    # Most importantly, sandboxing is disabled to avoid privilege
+    # issues in containers.
+    nixery-launch-script = writeShellScriptBin "nixery" ''
+      set -e
+      export NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
+      mkdir /tmp
+
+      # Create the build user/group required by Nix
+      echo 'nixbld:x:30000:nixbld' >> /etc/group
+      echo 'nixbld:x:30000:30000:nixbld:/tmp:/bin/bash' >> /etc/passwd
+
+      # Disable sandboxing to avoid running into privilege issues
+      mkdir -p /etc/nix
+      echo 'sandbox = false' >> /etc/nix/nix.conf
+
+      exec ${nixery-bin}/bin/nixery
+    '';
+  in dockerTools.buildLayeredImage {
     name = "nixery";
     contents = [
       bashInteractive
+      cacert
       coreutils
       nix
-      nixery-bin
+      nixery-launch-script
+      gnutar
+      gzip
     ];
   };
 }