Skip to content

Commit

Permalink
chore(operations): Verify building of the Nix package (#1432)
Browse files Browse the repository at this point in the history
* Verify building of Nix package

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Fix script name

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Use version from the template

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Generate `cargoSha256` automatically

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Run `make generate`

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>

* Run Vector tests during building of the package

Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
  • Loading branch information
a-rodin authored Jan 9, 2020
1 parent 0a11a36 commit b0819fd
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,15 @@ jobs:
make build-docker
no_output_timeout: 30m

verify-nixos:
<<: *docker-machine
steps:
- checkout
- run:
name: Test on NixOS
command: |
./scripts/docker-run.sh verifier-nixos ./scripts/verify-nix.sh
test-install-script-on-amazon-linux-1:
docker:
- image: timberiodev/vector-verifier-amazonlinux-1:latest
Expand Down Expand Up @@ -827,6 +836,7 @@ require-tests-checks-and-verifications: &require-tests-checks-and-verifications
- verify-deb-artifact-on-ubuntu-19-04
- verify-zip-artifact-on-wine
- verify-docker
- verify-nixos
- verify-rpm-artifact-on-amazon-linux-1
- verify-rpm-artifact-on-amazon-linux-2
- verify-rpm-artifact-on-centos-7
Expand Down Expand Up @@ -896,6 +906,7 @@ workflows:
- build-x86_64-unknown-linux-musl-archive-and-deb-package
- build-aarch64-unknown-linux-musl-archive-and-deb-package
- build-armv7-unknown-linux-musleabihf-archive-and-deb-package
- verify-nixos
- verify-rpm-artifact-on-amazon-linux-1:
requires:
- package-rpm-x86_64-unknown-linux-musl
Expand Down Expand Up @@ -984,6 +995,8 @@ workflows:
- build-x86_64-unknown-linux-musl-archive-and-deb-package
- build-aarch64-unknown-linux-musl-archive-and-deb-package
- build-armv7-unknown-linux-musleabihf-archive-and-deb-package
- verify-nixos:
<<: *release-filters
- verify-rpm-artifact-on-amazon-linux-1:
<<: *release-filters
requires:
Expand Down Expand Up @@ -1078,6 +1091,7 @@ workflows:
- build-x86_64-unknown-linux-musl-archive-and-deb-package
- build-aarch64-unknown-linux-musl-archive-and-deb-package
- build-armv7-unknown-linux-musleabihf-archive-and-deb-package
- verify-nixos
- verify-rpm-artifact-on-amazon-linux-1:
requires:
- package-rpm-x86_64-unknown-linux-musl
Expand Down
67 changes: 67 additions & 0 deletions distribution/nix/default.nix.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Taken from https://github.com/nixos/nixpkgs

{ stdenv, lib, fetchFromGitHub, rustPlatform
, openssl, pkgconfig, protobuf
, Security, libiconv, rdkafka, cmake
, tzdata

, features ?
(if stdenv.isAarch64
then [ "shiplift/unix-socket" "jemallocator" "rdkafka" "rdkafka/dynamic_linking" ]
else [ "leveldb" "leveldb/leveldb-sys-2" "shiplift/unix-socket" "jemallocator" "rdkafka" "rdkafka/dynamic_linking" ])
}:

rustPlatform.buildRustPackage rec {
pname = "vector";
version = "<%=
require "toml-rb"
TomlRB.load_file("Cargo.toml")["package"]["version"]
%>";

src = <% if ENV.has_key?("GITHUB_SHA256") %>fetchFromGitHub {
owner = "timberio";
repo = pname;
rev = "refs/tags/v${version}";
sha256 = "<%= ENV["GITHUB_SHA256"] %>";
}<% else %><%= Dir.getwd %><% end %>;

cargoSha256 = "<%=
# The only offical way to calculate `cargoSha256` is to set it arbitrarily,
# run the build, and then extract the correct checksum from the error
# message. See
# https://nixos.org/nixpkgs/manual/#compiling-rust-applications-with-cargo
# for details.

if ENV.has_key?("CARGO_SHA256")
ENV["CARGO_SHA256"]
else
require 'open3'

_, output, _ = Open3.capture3({ "CARGO_SHA256" => "1" * 52 }, "./scripts/verify-nix.sh")
expected_sha256 = output
.split("\n")
.select { |s| s =~ /got:.*sha256:/ }
.map { |s| s.split(":")[-1] }
.first

expected_sha256
end
%>";
buildInputs = [ openssl pkgconfig protobuf rdkafka cmake ]
++ stdenv.lib.optional stdenv.isDarwin [ Security libiconv ];

# needed for internal protobuf c wrapper library
PROTOC="${protobuf}/bin/protoc";
PROTOC_INCLUDE="${protobuf}/include";

cargoBuildFlags = [ "--no-default-features" "--features" "${lib.concatStringsSep "," features}" ];
checkPhase = "TZDIR=${tzdata}/share/zoneinfo cargo test --no-default-features --features ${lib.concatStringsSep "," features}";

meta = with stdenv.lib; {
description = "A high-performance logs, metrics, and events router";
homepage = "https://github.com/timberio/vector";
license = with licenses; [ asl20 ];
maintainers = with maintainers; [ thoughtpolice ];
platforms = platforms.all;
};
}
7 changes: 7 additions & 0 deletions scripts/ci-docker-images/verifier-nixos/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM nixos/nix:latest

RUN nix-env -i git ruby

COPY verifier-nixos/Gemfile Gemfile
RUN bundle install
RUN rm Gemfile
2 changes: 2 additions & 0 deletions scripts/ci-docker-images/verifier-nixos/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'toml-rb', '~> 1.1'
3 changes: 2 additions & 1 deletion scripts/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def url_valid?(url)
erb_paths =
Dir.glob("#{ROOT_DIR}/**/*.erb", File::FNM_DOTMATCH).
to_a.
filter { |path| !path.start_with?("#{ROOT_DIR}/scripts") }
filter { |path| !path.start_with?("#{ROOT_DIR}/scripts") }.
filter { |path| !path.start_with?("#{ROOT_DIR}/distribution/nix") }

#
# Create missing .md files
Expand Down
8 changes: 8 additions & 0 deletions scripts/verify-nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

mkdir -p /tmp
nixpkgs=/tmp/nixpkgs
git clone --depth=1 https://github.com/nixos/nixpkgs $nixpkgs
erb < distribution/nix/default.nix.erb > $nixpkgs/pkgs/tools/misc/vector/default.nix

nix-env -f $nixpkgs -iA vector

0 comments on commit b0819fd

Please sign in to comment.