980f5e2187
Introduces three new types representing each of the possible package sources and moves the logic for specifying the package source to the server. Concrete changes: * Determining whether a specified git reference is a commit vs. a branch/tag is now done in the server, and is done more precisely by using a regular expression. * Package sources now have a new `CacheKey` function which can be used to retrieve a key under which a build manifest can be cached *if* the package source is not a moving target (i.e. a full git commit hash of either nixpkgs or a private repository). This function is not yet used. * Users *must* now specify a package source, Nixery no longer defaults to anything and will fail to launch if no source is configured.
102 lines
3.2 KiB
Nix
102 lines
3.2 KiB
Nix
# Copyright 2019 Google LLC
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
{ pkgs ? import <nixpkgs> { }
|
|
, preLaunch ? ""
|
|
, extraPackages ? [] }:
|
|
|
|
with pkgs;
|
|
|
|
rec {
|
|
# Go implementation of the Nixery server which implements the
|
|
# container registry interface.
|
|
#
|
|
# Users will usually not want to use this directly, instead see the
|
|
# 'nixery' derivation below, which automatically includes runtime
|
|
# data dependencies.
|
|
nixery-server = callPackage ./server { };
|
|
|
|
# Implementation of the image building & layering logic
|
|
nixery-build-image = (import ./build-image {
|
|
srcType = "path";
|
|
srcArgs = <nixpkgs>;
|
|
}).wrapper;
|
|
|
|
# Use mdBook to build a static asset page which Nixery can then
|
|
# serve. This is primarily used for the public instance at
|
|
# nixery.dev.
|
|
nixery-book = callPackage ./docs { };
|
|
|
|
# Wrapper script running the Nixery server with the above two data
|
|
# dependencies configured.
|
|
#
|
|
# In most cases, this will be the derivation a user wants if they
|
|
# are installing Nixery directly.
|
|
nixery-bin = writeShellScriptBin "nixery" ''
|
|
export WEB_DIR="${nixery-book}"
|
|
exec ${nixery-server}/bin/nixery
|
|
'';
|
|
|
|
# Container image containing Nixery and Nix itself. This image can
|
|
# be run on Kubernetes, published on AppEngine or whatever else is
|
|
# desired.
|
|
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
|
|
echo 'root:x:0:0:root:/root:/bin/bash' >> /etc/passwd
|
|
echo 'root:x:0:' >> /etc/group
|
|
|
|
# Disable sandboxing to avoid running into privilege issues
|
|
mkdir -p /etc/nix
|
|
echo 'sandbox = false' >> /etc/nix/nix.conf
|
|
|
|
# In some cases users building their own image might want to
|
|
# customise something on the inside (e.g. set up an environment
|
|
# for keys or whatever).
|
|
#
|
|
# This can be achieved by setting a 'preLaunch' script.
|
|
${preLaunch}
|
|
|
|
exec ${nixery-bin}/bin/nixery
|
|
'';
|
|
in dockerTools.buildLayeredImage {
|
|
name = "nixery";
|
|
config.Cmd = [ "${nixery-launch-script}/bin/nixery" ];
|
|
maxLayers = 96;
|
|
contents = [
|
|
bashInteractive
|
|
cacert
|
|
coreutils
|
|
git
|
|
gnutar
|
|
gzip
|
|
iana-etc
|
|
nix
|
|
nixery-build-image
|
|
nixery-launch-script
|
|
openssh
|
|
zlib
|
|
] ++ extraPackages;
|
|
};
|
|
}
|