{ lib, buildGo126Module, fetchPnpmDeps, nodejs_24, pnpm, pnpmConfigHook, stdenvNoCC, }: let version = "dev"; frontendSource = lib.fileset.toSource { root = ../.; fileset = lib.fileset.unions [ ../package.json ../pnpm-lock.yaml ../pnpm-workspace.yaml ../frontend/package.json ../frontend/index.html ../frontend/eslint.config.js ../frontend/tsconfig.json ../frontend/tsconfig.node.json ../frontend/vite.config.ts ../frontend/src ]; }; frontend = stdenvNoCC.mkDerivation (finalAttrs: { pname = "vibe-proxy-frontend"; inherit version; src = frontendSource; pnpmDeps = fetchPnpmDeps { inherit (finalAttrs) pname version src; fetcherVersion = 4; hash = "sha256-vWBgw08KLHoih2DE/o9e8G4JQMjJBnFEwsCaiag8FNc="; }; nativeBuildInputs = [ nodejs_24 pnpm pnpmConfigHook ]; buildPhase = '' runHook preBuild pnpm --dir frontend exec tsc pnpm --dir frontend exec vite build runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out/share/vibe-proxy/frontend cp -r frontend/dist/. $out/share/vibe-proxy/frontend/ runHook postInstall ''; meta = { description = "Vibe Proxy management frontend"; license = lib.licenses.mit; platforms = lib.platforms.all; }; }); backendRoot = toString ../backend; backendSource = lib.cleanSourceWith { src = ../backend; filter = path: type: let relative = lib.removePrefix "${backendRoot}/" (toString path); in lib.cleanSourceFilter path type && relative != "cli-proxy-api" && relative != ".dev" && !lib.hasPrefix ".dev/" relative && !lib.hasPrefix "internal/managementasset/dist/" relative; }; buildBackend = { embedFrontend }: buildGo126Module { pname = if embedFrontend then "vibe-proxy" else "vibe-proxy-backend"; inherit version; src = backendSource; vendorHash = "sha256-6t1V6NIdK/QLevTMtt8MoRJiJT1DT1R67xHjYaVmyA4="; subPackages = [ "cmd/server" ]; tags = lib.optional embedFrontend "frontend"; preBuild = lib.optionalString embedFrontend '' rm -rf internal/managementasset/dist mkdir -p internal/managementasset/dist cp -r ${frontend}/share/vibe-proxy/frontend/. internal/managementasset/dist/ ''; ldflags = [ "-s" "-w" "-X main.Version=${version}" "-X main.Commit=nix" "-X main.BuildDate=reproducible" ]; postInstall = '' mv $out/bin/server $out/bin/vibe-proxy mkdir -p $out/share/vibe-proxy cp config.example.yaml $out/share/vibe-proxy/config.example.yaml ''; meta = { description = "OpenAI-compatible proxy server${lib.optionalString embedFrontend " with an embedded management UI"}"; homepage = "https://github.com/router-for-me/CLIProxyAPI"; license = lib.licenses.mit; mainProgram = "vibe-proxy"; platforms = lib.platforms.linux; }; }; in { inherit frontend; backend = buildBackend { embedFrontend = false; }; combined = buildBackend { embedFrontend = true; }; }