Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: nr-otel-collector sources #10

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
# You can build the below packages using 'nix build .#example'
{pkgs}: rec {
infrastructure-agent = pkgs.callPackage ./infrastructure-agent.nix {};
ocb = pkgs.callPackage ./ocb.nix {};

nr-otel-collector = pkgs.callPackage ./nr-otel-collector {
# nr-otel-collector needs a specific version of ocb at this moment, hence this hack
ocb = let
version = "0.86.0";
src = pkgs.fetchFromGitHub {
owner = "open-telemetry";
repo = "opentelemetry-collector";
rev = "cmd/builder/v${version}";
hash = "sha256-Ucp00OjyPtHA6so/NOzTLtPSuhXwz6A2708w2WIZb/E=";
fetchSubmodules = true;
};
in
# For why this was needed, see
# https://discourse.nixos.org/t/inconsistent-vendoring-in-buildgomodule-when-overriding-source/9225/6
ocb.override rec {
buildGoModule = args:
pkgs.buildGoModule (args
// {
inherit src version;
vendorHash = "sha256-MTwD9xkrq3EudppLSoONgcPCBWlbSmaODLH9NtYgVOk=";
});
};
};
{ pkgs }:
rec {
infrastructure-agent = pkgs.callPackage ./infrastructure-agent.nix { };
ocb = pkgs.callPackage ./ocb.nix { };
nr-otel-collector = pkgs.callPackage ./nr-otel-collector.nix { inherit ocb; };
}
80 changes: 80 additions & 0 deletions pkgs/nr-otel-collector.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
lib,
pkgs,
buildGoModule,
fetchFromGitHub,
ocb,
}:
let
distName = "nr-otel-collector";
distVersion = "0.7.1";
sourcesDir = "distributions/nr-otel-collector/_build";
generatedDistDir = "_nrdot_build";
in
buildGoModule {
pname = distName;
version = distVersion;

src = fetchFromGitHub {
owner = "newrelic";
repo = "opentelemetry-collector-releases";
rev = "nr-otel-collector-${distVersion}";
hash = "sha256-h6qxPDdKkyX8/GhOm/V/RfexnV/mbwmQ2hhFJDOXQaY=";
};

overrideModAttrs = (
old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gnumake ] ++ [ ocb ];

preConfigure = ''
# script run by make needs the correct bash location
patchShebangs ./scripts/build.sh

export HOME=$TMPDIR
chmod -R u+w .
OTELCOL_BUILDER_DIR="${ocb}/bin" make generate-sources

cd ${sourcesDir}
'';

postInstall = ''
# Remove log files as they make the build non-reproducible (contain dates)
rm -rf build.log

cp -r ./ $out/${generatedDistDir}
'';
}
);

vendorHash = "sha256-AXDG9+kYGxyKhBAY+oXqReiBS9hZNoNp16pmCvyePDs=";

postConfigure = ''
# At this point the `vendor` directory also containing the
# generated sources has been placed (which also contains vendor!)
# Remove the inner vendor directory and copy the sources into
# the working directory
# FIXME
chmod -R u+w vendor/${generatedDistDir}/vendor
rm -rf vendor/${generatedDistDir}/vendor
cp -r vendor/${generatedDistDir}/* ./
'';

ldflags = [
"-s"
"-w"
];

# TestValidateConfigs is failing for some reason
checkFlags = [ "-skip TestValidateConfigs" ];

CGO_ENABLED = "0";

meta = with lib; {
description = "The New Relic distribution of the OpenTelemetry Collector";
homepage = "https://github.com/newrelic/opentelemetry-collector-releases.git";
license = licenses.asl20;
maintainers = with maintainers; [ DavSanchez ];
mainProgram = "nr-otel-collector";
platforms = platforms.all;
};
}
38 changes: 0 additions & 38 deletions pkgs/nr-otel-collector/default.nix

This file was deleted.

40 changes: 0 additions & 40 deletions pkgs/nr-otel-collector/sources.nix

This file was deleted.

Loading