From 5860dcc628232eec227a57a026591122776ea444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20S=C3=A1nchez?= Date: Sun, 23 Jun 2024 05:36:59 +0100 Subject: [PATCH 1/3] refactor: nr-otel-collector not using explicit FOD --- pkgs/default.nix | 32 ++----------- pkgs/nr-otel-collector.nix | 76 ++++++++++++++++++++++++++++++ pkgs/nr-otel-collector/default.nix | 38 --------------- pkgs/nr-otel-collector/sources.nix | 40 ---------------- 4 files changed, 81 insertions(+), 105 deletions(-) create mode 100644 pkgs/nr-otel-collector.nix delete mode 100644 pkgs/nr-otel-collector/default.nix delete mode 100644 pkgs/nr-otel-collector/sources.nix diff --git a/pkgs/default.nix b/pkgs/default.nix index eab7526..1b53c65 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -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; }; } diff --git a/pkgs/nr-otel-collector.nix b/pkgs/nr-otel-collector.nix new file mode 100644 index 0000000..54bc5d2 --- /dev/null +++ b/pkgs/nr-otel-collector.nix @@ -0,0 +1,76 @@ +{ + 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 = lib.fakeHash; + + postConfigure = '' + # At this point the `vendor` directory also containing the + # generated sources has been placed. + # Move to the directory that contains the sources + 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; + }; +} diff --git a/pkgs/nr-otel-collector/default.nix b/pkgs/nr-otel-collector/default.nix deleted file mode 100644 index ce53e8d..0000000 --- a/pkgs/nr-otel-collector/default.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ - lib, - pkgs, - buildGoModule, - ocb, -}: -let - distName = "nr-otel-collector"; - distVersion = "0.7.1"; - generated-sources = pkgs.callPackage ./sources.nix { inherit ocb; }; -in -buildGoModule { - pname = distName; - version = distVersion; - - src = generated-sources; - - vendorHash = "sha256-75HGTKvmPpvrnJmZzuGscbDJQAvPid3W6VJogfa4ZWs="; - - ldflags = [ - "-s" - "-w" - ]; - - # The TestGenerateAndCompile tests download new dependencies for a modified go.mod. Nix doesn't allow network access so skipping. - 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; - }; -} diff --git a/pkgs/nr-otel-collector/sources.nix b/pkgs/nr-otel-collector/sources.nix deleted file mode 100644 index e217a08..0000000 --- a/pkgs/nr-otel-collector/sources.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ - pkgs, - stdenv, - fetchFromGitHub, - ocb, -}: -let - distVersion = "0.7.1"; -in -stdenv.mkDerivation { - name = "collector-dist-${distVersion}"; - src = fetchFromGitHub { - owner = "newrelic"; - repo = "opentelemetry-collector-releases"; - rev = "nr-otel-collector-${distVersion}"; - hash = "sha256-h6qxPDdKkyX8/GhOm/V/RfexnV/mbwmQ2hhFJDOXQaY="; - }; - nativeBuildInputs = - (with pkgs; [ - gnumake - go - ]) - ++ [ ocb ]; - buildPhase = '' - # script run by make needs the correct bash location - patchShebangs ./scripts/build.sh - - export HOME=$TMPDIR - chmod -R u+w . - make generate-sources - ''; - installPhase = '' - # Remove log files as they make the build non-reproducible (contain dates) - rm -rf distributions/nr-otel-collector/_build/build.log - cp -r distributions/nr-otel-collector/_build/ $out - ''; - outputHashAlgo = "sha256"; - outputHashMode = "recursive"; - outputHash = "sha256-8mgMqZfSEsOY5gzAk1SA1IwHXPpAWEkfxQObaHHmJbg="; -} From 8b8ecbbfa3d9b774ab0b7eb1e3274d35d9289af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20S=C3=A1nchez?= Date: Sun, 23 Jun 2024 05:39:13 +0100 Subject: [PATCH 2/3] refactor: fix hash --- pkgs/nr-otel-collector.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/nr-otel-collector.nix b/pkgs/nr-otel-collector.nix index 54bc5d2..009f5be 100644 --- a/pkgs/nr-otel-collector.nix +++ b/pkgs/nr-otel-collector.nix @@ -46,7 +46,7 @@ buildGoModule { } ); - vendorHash = lib.fakeHash; + vendorHash = "sha256-AXDG9+kYGxyKhBAY+oXqReiBS9hZNoNp16pmCvyePDs="; postConfigure = '' # At this point the `vendor` directory also containing the From 129e3dc68d27e35fc86d3fbeedac806e179a17a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20S=C3=A1nchez?= Date: Sun, 23 Jun 2024 05:52:26 +0100 Subject: [PATCH 3/3] fix(wip): directory manipulation --- pkgs/nr-otel-collector.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/nr-otel-collector.nix b/pkgs/nr-otel-collector.nix index 009f5be..a1d0c99 100644 --- a/pkgs/nr-otel-collector.nix +++ b/pkgs/nr-otel-collector.nix @@ -50,9 +50,13 @@ buildGoModule { postConfigure = '' # At this point the `vendor` directory also containing the - # generated sources has been placed. - # Move to the directory that contains the sources - cp -r vendor/${generatedDistDir}/* . + # 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 = [