2022-04-20 16:41:20 +02:00
|
|
|
# Copyright 2022 The TVL Contributors
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2019-09-30 15:19:11 +02:00
|
|
|
|
2022-04-20 16:12:06 +02:00
|
|
|
# This function header aims to provide compatibility between builds of
|
|
|
|
# Nixery taking place inside/outside of the TVL depot.
|
|
|
|
#
|
|
|
|
# In the future, Nixery will transition to using //nix/buildGo for its
|
|
|
|
# build system and this will need some major adaptations to support
|
|
|
|
# that.
|
|
|
|
{ depot ? { nix.readTree.drvTargets = x: x; }
|
2022-04-20 16:41:20 +02:00
|
|
|
, pkgs ? import <nixpkgs> { }
|
2019-08-19 02:10:21 +02:00
|
|
|
, preLaunch ? ""
|
2022-04-20 16:41:20 +02:00
|
|
|
, extraPackages ? [ ]
|
2021-08-06 13:21:47 +02:00
|
|
|
, maxLayers ? 20
|
2022-04-20 15:53:34 +02:00
|
|
|
, commitHash ? null
|
2022-04-20 16:41:20 +02:00
|
|
|
, ...
|
|
|
|
}@args:
|
2019-07-23 22:48:27 +02:00
|
|
|
|
|
|
|
with pkgs;
|
|
|
|
|
2019-10-27 15:33:14 +01:00
|
|
|
let
|
2022-06-16 16:52:36 +02:00
|
|
|
inherit (pkgs) buildGoModule lib;
|
2019-11-11 22:07:16 +01:00
|
|
|
|
2022-04-21 16:28:54 +02:00
|
|
|
# Avoid extracting this from git until we have a way to plumb
|
|
|
|
# through revision numbers.
|
|
|
|
nixery-commit-hash = "depot";
|
2022-04-20 16:41:20 +02:00
|
|
|
in
|
|
|
|
depot.nix.readTree.drvTargets rec {
|
2019-09-29 23:58:52 +02:00
|
|
|
# Implementation of the Nix image building logic
|
2019-11-11 22:07:16 +01:00
|
|
|
nixery-prepare-image = import ./prepare-image { inherit pkgs; };
|
2019-08-04 23:43:22 +02:00
|
|
|
|
2022-10-10 22:17:13 +02:00
|
|
|
# Include the Nixery website into the Nix store, unless its being
|
|
|
|
# overridden to something else. Nixery will serve this as its front
|
|
|
|
# page when visited from a browser.
|
|
|
|
nixery-web = ./web;
|
2019-07-24 00:22:18 +02:00
|
|
|
|
2022-05-13 18:25:59 +02:00
|
|
|
nixery-popcount = callPackage ./popcount { };
|
|
|
|
|
|
|
|
# Build Nixery's Go code, resulting in the binaries used for various
|
|
|
|
# bits of functionality.
|
2019-07-24 00:22:18 +02:00
|
|
|
#
|
2022-05-13 18:25:59 +02:00
|
|
|
# The server binary is wrapped to ensure that required environment
|
|
|
|
# variables are set at runtime.
|
|
|
|
nixery = buildGoModule rec {
|
|
|
|
name = "nixery";
|
|
|
|
src = ./.;
|
|
|
|
doCheck = true;
|
2019-07-24 00:22:18 +02:00
|
|
|
|
2022-05-13 18:25:59 +02:00
|
|
|
# Needs to be updated after every modification of go.mod/go.sum
|
2022-09-26 19:33:05 +02:00
|
|
|
vendorHash = "sha256-io9NCeZmjCZPLmII3ajXIsBWbT40XiW8ncXOuUDabbo=";
|
2022-05-13 18:25:59 +02:00
|
|
|
|
2022-10-02 15:33:10 +02:00
|
|
|
ldflags = [
|
|
|
|
"-s"
|
|
|
|
"-w"
|
|
|
|
"-X"
|
|
|
|
"main.version=${nixery-commit-hash}"
|
2022-05-13 18:25:59 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
postInstall = ''
|
|
|
|
wrapProgram $out/bin/server \
|
2022-10-10 22:17:13 +02:00
|
|
|
--set WEB_DIR "${nixery-web}" \
|
2022-05-13 18:25:59 +02:00
|
|
|
--prefix PATH : ${nixery-prepare-image}/bin
|
|
|
|
'';
|
2022-05-25 18:18:19 +02:00
|
|
|
|
|
|
|
# Nixery is mirrored to Github at tazjin/nixery; this is
|
|
|
|
# automatically updated from CI for canon builds.
|
|
|
|
passthru.meta.ci.extraSteps.github = depot.tools.releases.filteredGitPush {
|
|
|
|
filter = ":/tools/nixery";
|
|
|
|
remote = "git@github.com:tazjin/nixery.git";
|
|
|
|
ref = "refs/heads/master";
|
|
|
|
};
|
2022-05-13 18:25:59 +02:00
|
|
|
};
|
2019-10-31 18:54:31 +01:00
|
|
|
|
2019-07-24 00:22:18 +02:00
|
|
|
# Container image containing Nixery and Nix itself. This image can
|
|
|
|
# be run on Kubernetes, published on AppEngine or whatever else is
|
|
|
|
# desired.
|
2022-04-20 16:41:20 +02:00
|
|
|
nixery-image =
|
|
|
|
let
|
|
|
|
# Wrapper script for the wrapper script (meta!) which configures
|
|
|
|
# the container environment appropriately.
|
2019-08-04 23:45:23 +02:00
|
|
|
#
|
2022-04-20 16:41:20 +02:00
|
|
|
# Most importantly, sandboxing is disabled to avoid privilege
|
|
|
|
# issues in containers.
|
|
|
|
nixery-launch-script = writeShellScriptBin "nixery" ''
|
|
|
|
set -e
|
|
|
|
export PATH=${coreutils}/bin:$PATH
|
|
|
|
export NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt
|
|
|
|
mkdir -p /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}
|
|
|
|
|
2022-05-13 18:25:59 +02:00
|
|
|
exec ${nixery}/bin/server
|
2022-04-20 16:41:20 +02:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
dockerTools.buildLayeredImage {
|
|
|
|
name = "nixery";
|
|
|
|
config.Cmd = [ "${nixery-launch-script}/bin/nixery" ];
|
|
|
|
|
|
|
|
inherit maxLayers;
|
|
|
|
contents = [
|
|
|
|
bashInteractive
|
|
|
|
cacert
|
|
|
|
coreutils
|
|
|
|
git
|
|
|
|
gnutar
|
|
|
|
gzip
|
|
|
|
iana-etc
|
|
|
|
nix
|
|
|
|
nixery-prepare-image
|
|
|
|
nixery-launch-script
|
|
|
|
openssh
|
|
|
|
zlib
|
|
|
|
] ++ extraPackages;
|
|
|
|
};
|
2019-07-23 22:48:27 +02:00
|
|
|
}
|