blumeops/containers/pyroscope/default.nix
Erich Blume ef2385322a Drop embedded frontend from Pyroscope build
The webpack build fails on a @grafana/ui icons glob that doesn't
resolve in the Nix sandbox. Since Grafana is the primary UI via the
pyroscope datasource plugin, the standalone web UI isn't needed.
Build with EMBEDASSETS="" (upstream's build-dev path).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 14:39:34 -07:00

118 lines
3.2 KiB
Nix

# Nix-built Grafana Pyroscope continuous profiling server
# Builds v1.19.1 from forge mirror
# Uses stdenv + make (not buildGoModule) due to multi-module go.work workspace
# with local replace directives (./api, ./lidia)
# Built without embedded frontend — Grafana is the primary UI via the
# grafana-pyroscope-datasource plugin, so the standalone web UI is not needed.
# Built with dockerTools.buildLayeredImage for efficient layer caching
{ pkgs ? import <nixpkgs> { } }:
let
version = "1.19.1";
src = pkgs.fetchgit {
url = "https://forge.ops.eblu.me/mirrors/pyroscope.git";
rev = "v${version}";
hash = "sha256-UPxGimkzXLFACqmAM1hNQIoNjN6OquVibwVmNvP00+s=";
};
# Pre-fetch Go modules for all go.mod files in the workspace (fixed-output derivation)
goModules = pkgs.stdenv.mkDerivation {
pname = "pyroscope-go-modules";
inherit src version;
nativeBuildInputs = with pkgs; [ go git cacert ];
buildPhase = ''
export GOPATH=$TMPDIR/go
export GOFLAGS=-modcacherw
# Download modules for all workspace members
go mod download
cd api && go mod download && cd ..
cd lidia && go mod download && cd ..
'';
installPhase = ''
cp -r $TMPDIR/go/pkg/mod $out
'';
# Disable fixup: patchelf and patchShebangs modify downloaded Go toolchain
# binaries, which makes the fixed-output derivation reference store paths
dontFixup = true;
outputHashMode = "recursive";
outputHash = "sha256-RCWuqz1XaDrS7+GqL/9v7LNA14M4/ohWEtPeTMDkJFc=";
outputHashAlgo = "sha256";
};
pyroscope = pkgs.stdenv.mkDerivation {
inherit src version;
pname = "pyroscope";
nativeBuildInputs = with pkgs; [
go
git
gnumake
cacert
];
buildPhase = ''
runHook preBuild
export HOME=$TMPDIR
export GOPATH=$TMPDIR/go
export GOFLAGS=-modcacherw
# Populate module cache from pre-fetched modules
mkdir -p $GOPATH/pkg
cp -r ${goModules} $GOPATH/pkg/mod
chmod -R u+w $GOPATH/pkg/mod
# Build Go binary without embedded frontend (EMBEDASSETS="")
# Grafana queries Pyroscope via API; standalone web UI not needed
# CGO_ENABLED=0 for static binary (matches upstream)
CGO_ENABLED=0 \
EMBEDASSETS="" \
IMAGE_TAG=v${version} \
make go/bin
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp cmd/pyroscope/pyroscope $out/bin/pyroscope
runHook postInstall
'';
meta = with pkgs.lib; {
description = "Grafana Pyroscope continuous profiling platform";
homepage = "https://grafana.com/docs/pyroscope/";
license = licenses.agpl3Only;
mainProgram = "pyroscope";
};
};
in
pkgs.dockerTools.buildLayeredImage {
name = "blumeops/pyroscope";
contents = [
pyroscope
pkgs.cacert
pkgs.tzdata
];
config = {
Entrypoint = [ "${pyroscope}/bin/pyroscope" ];
Cmd = [ "-config.path=/etc/pyroscope/config.yaml" ];
Env = [
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"TZDIR=${pkgs.tzdata}/share/zoneinfo"
];
ExposedPorts = {
"4040/tcp" = { };
};
User = "65534";
};
}