refactor(radar): build from source instead of prebuilt binary

Replace fetchurl + prebuilt binary with buildGoModule + buildNpmPackage
to compile radar natively from source. Frontend (React/Vite) is built
as a separate derivation, then embedded into the Go binary via go:embed.

Also patches the npm lockfile to add missing resolved URLs for
workspace packages that lacked them, enabling proper dependency fetching.

Closes nix-overlay-qlc
This commit is contained in:
2026-05-11 18:09:02 +03:00
parent 0d6b74045e
commit 3b0bc435c4
2 changed files with 93 additions and 17 deletions

View File

@@ -1 +1,10 @@
{"_type":"issue","id":"nix-overlay-2lr","title":"radar","description":"Используй karpathy-guidelines и Sequential Thinking для планирования шаг за шагом добавления нового пакета https://github.com/skyhook-io/radar.git в данный NIXOS overlay-репозиторий. Разбей задачу на подзадачи, используя beads. В написании кода используй refContext и context7.\n\n\n\n## Required Skills\ncaveman,karpathy-guidelines,nix,nix-flakes","status":"closed","priority":2,"issue_type":"feature","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-05-10T19:28:56Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T08:27:39Z","started_at":"2026-05-10T19:30:31Z","closed_at":"2026-05-11T08:27:39Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-qlc.5","title":"Update package metadata and updateScript","description":"Remove binaryNativeCode sourceProvenance, update meta, adjust updateScript for source build","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-05-11T13:51:22Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T15:01:06Z","started_at":"2026-05-11T14:59:33Z","closed_at":"2026-05-11T15:01:06Z","close_reason":"Closed","dependencies":[{"issue_id":"nix-overlay-qlc.5","depends_on_id":"nix-overlay-qlc","type":"parent-child","created_at":"2026-05-11T16:51:21Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-qlc.4","title":"Test build and verify functionality","description":"Build radar from source and verify it runs correctly","status":"closed","priority":2,"issue_type":"task","owner":"alex@millerson.name","created_at":"2026-05-11T13:51:11Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T14:59:55Z","closed_at":"2026-05-11T14:59:55Z","close_reason":"Closed","dependencies":[{"issue_id":"nix-overlay-qlc.4","depends_on_id":"nix-overlay-qlc","type":"parent-child","created_at":"2026-05-11T16:51:10Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-qlc.3","title":"Handle go:embed frontend assets","description":"Ensure frontend assets are copied to internal/static/dist before Go build so go:embed works correctly","status":"closed","priority":2,"issue_type":"task","owner":"alex@millerson.name","created_at":"2026-05-11T13:51:02Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T14:59:55Z","closed_at":"2026-05-11T14:59:55Z","close_reason":"Closed","dependencies":[{"issue_id":"nix-overlay-qlc.3","depends_on_id":"nix-overlay-qlc","type":"parent-child","created_at":"2026-05-11T16:51:02Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-qlc.2","title":"Configure npm dependencies for frontend build","description":"Set up npmDependencies hash for the Vite/React frontend build within buildGoModule","status":"closed","priority":2,"issue_type":"task","owner":"alex@millerson.name","created_at":"2026-05-11T13:50:53Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T14:59:55Z","closed_at":"2026-05-11T14:59:55Z","close_reason":"Closed","dependencies":[{"issue_id":"nix-overlay-qlc.2","depends_on_id":"nix-overlay-qlc","type":"parent-child","created_at":"2026-05-11T16:50:52Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-qlc.1","title":"Update radar default.nix to use buildGoModule","description":"Change package.nix from stdenv.mkDerivation with fetchurl to buildGoModule pattern","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-05-11T13:50:42Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T14:59:55Z","started_at":"2026-05-11T13:51:49Z","closed_at":"2026-05-11T14:59:55Z","close_reason":"Closed","dependencies":[{"issue_id":"nix-overlay-qlc.1","depends_on_id":"nix-overlay-qlc","type":"parent-child","created_at":"2026-05-11T16:50:41Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-qlc","title":"Rebuild radar package from source instead of prebuilt binary","description":"Current radar package uses prebuilt binary from GitHub releases. Need to rebuild from source using nix native tooling (buildGoModule + npm for frontend). Build pipeline: 1) npm run build for frontend, 2) copy assets to internal/static/dist, 3) CGO_ENABLED=0 go build with embedded assets.","status":"closed","priority":2,"issue_type":"task","owner":"alex@millerson.name","created_at":"2026-05-11T13:50:27Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T15:01:06Z","closed_at":"2026-05-11T15:01:06Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-y8r","title":"nix-overlay-2lr-3 · Approach 3: ручной npm cache + buildGoModule [parent:nix-overlay-2lr]","notes":"BLOCKED: fetchNpmDeps v2 не загружает workspace-scoped пакеты (@vitejs/plugin-react ENOTCACHED) даже с makeCacheWritable=true. Все 3 подхода заблокированы одним ограничением — fetchNpmDeps v2 не поддерживает npm workspaces корректно, вопреки release notes.","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-05-11T09:38:34Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T11:14:40Z","started_at":"2026-05-11T10:23:41Z","closed_at":"2026-05-11T11:14:40Z","dependencies":[{"issue_id":"nix-overlay-y8r","depends_on_id":"nix-overlay-2lr","type":"parent-child","created_at":"2026-05-11T12:42:18Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-dcx","title":"nix-overlay-2lr-2 · Approach 2: bun2nix генерация пакетов [parent:nix-overlay-2lr]","notes":"Skipping bun2nix — требует staging branch, неочевидная поддержка npm lockfiles. Проще перейти к Approach 3 (ручной stdenv.mkDerivation с nodejs/npm).","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-05-11T09:38:06Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T10:23:18Z","started_at":"2026-05-11T10:21:04Z","closed_at":"2026-05-11T10:23:18Z","dependencies":[{"issue_id":"nix-overlay-dcx","depends_on_id":"nix-overlay-2lr","type":"parent-child","created_at":"2026-05-11T12:42:12Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-3ik","title":"nix-overlay-2lr-1 · Approach 1: buildNpmPackage + buildGoModule с npmDepsFetcherVersion=2 [parent:nix-overlay-2lr]","notes":"fetchNpmDeps v2 не resolves workspace-scoped packages (@vitejs/plugin-react ENOTCACHED). Approach blocked — same issue as previous attempt. Moving to Approach 2 (bun2nix).","status":"closed","priority":2,"issue_type":"task","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-05-11T09:37:43Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T10:20:38Z","started_at":"2026-05-11T09:39:05Z","closed_at":"2026-05-11T10:20:38Z","dependencies":[{"issue_id":"nix-overlay-3ik","depends_on_id":"nix-overlay-2lr","type":"parent-child","created_at":"2026-05-11T12:41:54Z","created_by":"Alexander Miroshnichenko","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"nix-overlay-2lr","title":"radar","description":"Используй karpathy-guidelines и Sequential Thinking для планирования шаг за шагом добавления нового пакета https://github.com/skyhook-io/radar.git в данный NIXOS overlay-репозиторий. Разбей задачу на подзадачи, используя beads. В написании кода используй mcp: nixos, refContext и context7.\n\n\n\n## Required Skills\ncaveman,karpathy-guidelines,nix,nix-flakes","notes":"Все 3 подхода провалены. fetchNpmDeps v2 НЕ работает с npm workspaces вопреки release notes - ENOTCACHED для workspace-scoped пакетов (@vitejs/plugin-react). Ручной сбор node_modules без npm ci слишком сложен (требует reimplement fetchNpmDeps). Текущее решение: pre-built binary из GitHub Releases. Нужно дождаться исправления fetchNpmDeps v2 в nixpkgs или upstream поддержки standalone lockfile для web/.","status":"closed","priority":2,"issue_type":"feature","assignee":"Alexander Miroshnichenko","owner":"alex@millerson.name","created_at":"2026-05-10T19:28:56Z","created_by":"Alexander Miroshnichenko","updated_at":"2026-05-11T11:24:40Z","started_at":"2026-05-10T19:30:31Z","closed_at":"2026-05-11T11:24:40Z","dependency_count":0,"dependent_count":0,"comment_count":0}

View File

@@ -1,33 +1,101 @@
{
lib,
stdenv,
fetchurl,
buildGoModule,
buildNpmPackage,
fetchFromGitHub,
}:
let
version = "1.5.10";
in
stdenv.mkDerivation rec {
pname = "radar";
inherit version;
src = fetchurl {
url = "https://github.com/skyhook-io/radar/releases/download/v${version}/radar_v${version}_linux_amd64.tar.gz";
hash = "sha256-B+u3jdnScJUzsnoPAFPEk0dYFNDPe9hhvY1OaXttj9c=";
src = fetchFromGitHub {
owner = "skyhook-io";
repo = "radar";
rev = "v${version}";
hash = "sha256-Xvn1dDqCaBlXY/XD2GoWBDECMhxFlYCGlnVinLR/c1A=";
};
sourceRoot = ".";
# Build the frontend as a separate derivation.
# The lockfile has some workspace packages without resolved URLs,
# so we patch them in postPatch before fetching dependencies.
frontend = buildNpmPackage {
pname = "radar-frontend";
inherit version src;
sourceRoot = "source";
installPhase = ''
mkdir -p $out/bin
cp kubectl-radar $out/bin/radar
chmod +x $out/bin/radar
postPatch = ''
# Fix missing resolved URLs for packages under web/node_modules/
# that are actually external npm packages (not workspace links).
# Insert "resolved" and "integrity" after the "version" field
# for each affected package using sed.
sed -i \
-e '/"web\/node_modules\/@vitejs\/plugin-react"/,/^[[:space:]]*}/{
/"version"/a\
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-6.0.1.tgz",\
"integrity": "sha512-l9X/E3cDb+xY3SWzlG1MOGt2usfEHGMNIaegaUGFsLkb3RCn/k8/TOXBcab+OndDI4TBtktT8/9BwwW8Vi9KUQ==",
}' \
-e '/"web\/node_modules\/@rolldown\/pluginutils"/,/^[[:space:]]*}/{
/"version"/a\
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-rc.7.tgz",\
"integrity": "sha512-qujRfC8sFVInYSPPMLQByRh7zhwkGFS4+tyMQ83srV1qrxL4g8E2tyxVVyxd0+8QeBM1mIk9KbWxkegRr76XzA==",
}' \
-e '/"web\/node_modules\/@types\/diff"/,/^[[:space:]]*}/{
/"version"/a\
"resolved": "https://registry.npmjs.org/@types/diff/-/diff-8.0.0.tgz",\
"integrity": "sha512-o7jqJM04gfaYrdCecCVMbZhNdG6T1MHg/oQoRFdERLV+4d+V7FijhiEAbFu0Usww84Yijk9yH58U4Jk4HbtzZw==",
}' \
package-lock.json
'';
npmDepsHash = "sha256-qOODkgvCeHIcMUMOQpjlrDgnyqjooqQ7NmQH0vE8VQk=";
npmDepsFetcherVersion = 2;
makeCacheWritable = true;
doCheck = false;
# Build the web workspace and install its output
buildPhase = ''
runHook preBuild
cd web
HOME=$TMPDIR ../node_modules/.bin/vite build
cd ..
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r web/dist/* $out/
runHook postInstall
'';
};
in
buildGoModule {
pname = "radar";
inherit version src;
vendorHash = "sha256-bmS4nRzVG4ZmpV3kq2Ih8uerRWL5weq0KP54jT3sh5I=";
# Copy pre-built frontend assets before Go compilation for go:embed
preBuild = ''
mkdir -p internal/static/dist
cp -r ${frontend}/* internal/static/dist/
'';
env.CGO_ENABLED = 0;
subPackages = [ "cmd/explorer" ];
doCheck = false;
postInstall = ''
ln -s $out/bin/explorer $out/bin/radar
'';
passthru = {
category = "Kubernetes";
inherit frontend;
updateScript = [
"nix-update"
"--flake"
@@ -40,8 +108,7 @@ stdenv.mkDerivation rec {
homepage = "https://github.com/skyhook-io/radar";
changelog = "https://github.com/skyhook-io/radar/releases/tag/v${version}";
license = licenses.asl20;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
mainProgram = "radar";
platforms = [ "x86_64-linux" ];
platforms = platforms.linux;
};
}