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
This commit is contained in:
parent
18b4ae9f28
commit
948f308025
1 changed files with 27 additions and 3 deletions
|
@ -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
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue