{ lib, buildGoModule, fetchFromGitHub, installShellFiles, testers, nixosTests, opentelemetry-collector-builder, pkgs, go, git, cacert, stdenv, }: let # This is the tool OTEL uses to build their distributions. builder = "${opentelemetry-collector-builder}/bin/ocb"; # Keep the version in sync with the builder. rev = opentelemetry-collector-builder.src.rev; version = lib.removePrefix "cmd/builder/v" rev; # This is a weird meta-repo where all the open-telemetry collectors are. src = fetchFromGitHub { owner = "open-telemetry"; repo = "opentelemetry-collector-releases"; rev = "v${version}"; hash = "sha256-/I6kYm/j2hO2OAZaWVIRYI1ejBTGMI3PzTjRLcmwziQ="; }; # Then from this src, we use the tool to generate some go code, including # the go.mod and go.sum files. # # The output depends on which release. mkDistributionSource = { name, hash, }: stdenv.mkDerivation { inherit name; nativeBuildInputs = [ cacert git go ]; inherit src; outputHash = hash; outputHashMode = "recursive"; outputHashAlgo = if hash == "" then "sha256" else null; patchPhase = '' patchShebangs . ''; configurePhase = '' export HOME=$NIX_BUILD_TOP/home export GIT_SSL_CAINFO=$NIX_SSL_CERT_FILE ''; buildPhase = '' # Only generate the go code, skip compilation ./scripts/build.sh -d ${name} -b ${builder} -s true ''; installPhase = '' mv ./distributions/${name}/_build $out # Make it reproducible rm $out/build.log ''; }; # Then, finally, we build the project as a normal go module package. mkDistribution = { name, sourceHash, vendorHash, proxyVendor ? false, }: let package = buildGoModule { pname = name; inherit version; src = mkDistributionSource { inherit name; hash = sourceHash; }; inherit proxyVendor vendorHash; nativeBuildInputs = [ installShellFiles ]; # upstream strongly recommends disabling CGO # additionally dependencies have had issues when GCO was enabled that weren't caught upstream # https://github.com/open-telemetry/opentelemetry-collector/blob/main/CONTRIBUTING.md#using-cgo env.CGO_ENABLED = 0; ldflags = [ "-s" "-w" ]; postInstall = '' # Fix binary name mv $out/bin/* $out/bin/$pname installShellCompletion --cmd ${name} \ --bash <($out/bin/${name} completion bash) \ --fish <($out/bin/${name} completion fish) \ --zsh <($out/bin/${name} completion zsh) ''; passthru.tests = { version = testers.testVersion { inherit package version; command = "${name} -v"; }; }; meta = with lib; { homepage = "https://github.com/open-telemetry/opentelemetry-collector-releases"; description = "OpenTelemetry Collector Official Releases"; longDescription = '' The OpenTelemetry Collector offers a vendor-agnostic implementation on how to receive, process and export telemetry data. In addition, it removes the need to run, operate and maintain multiple agents/collectors in order to support open-source telemetry data formats (e.g. Jaeger, Prometheus, etc.) sending to multiple open-source or commercial back-ends. ''; license = licenses.asl20; maintainers = with maintainers; [ uri-canva jk zimbatm ]; mainProgram = name; }; }; in package; in lib.recurseIntoAttrs { otelcol = mkDistribution { name = "otelcol"; sourceHash = "sha256-XGQIHkRfCSdEnZlhodN38BKZGkgOPuUnxveG4yX0rMw="; vendorHash = "sha256-0i+eHVBwYvEKf4kXfyOuN/gEkDk2/5s7+3HQjYCtI94="; }; otelcol-contrib = mkDistribution { name = "otelcol-contrib"; sourceHash = "sha256-87VmiafluGem4p5hRP+UmPuSJeXdXjZkubWzqhXtyJg="; vendorHash = "sha256-/qSXvt8oQ0C3V49an7TNUw0bcNVnXd5Qmz5oCRp+KTE="; proxyVendor = true; # hash mismatch between linux and darwin }; otelcol-k8s = mkDistribution { name = "otelcol-k8s"; sourceHash = "sha256-B5NbbQBIz3RZ/+jSxNhuY+zpfhHlg26cvUlMqlYXtq0="; vendorHash = "sha256-2dGNrsskrCh76bTMuPYcRH+bMl/sE+KVn2mOqcF2PeI="; }; otelcol-otlp = mkDistribution { name = "otelcol-otlp"; sourceHash = "sha256-c83fzhC4XbvRHZ3XwXQgwsyW1TDiDs0T/bX3h53n2RE="; vendorHash = "sha256-QVNQFsaACvlByQWwpl2emSIrL+how78WtU51YJ2AvAU="; }; }