Files
9router/flake.nix
T
asepharyana 7001bd17ea chore(nix): add flake.nix + bun.lock so 9router builds/deploys from this repo
Migrate the Nix build + deploy source from /home/code/9router-repo (a pure
upstream mirror, now deleted) to this repo, which carries the MIBP fork
merge (freebuff, cline free models, proxy-pool fitness). flake.lock and
flake.nix copied verbatim from 9router-repo; bun.lock generated from the
merged dependency set. The cron updater (9router-update.sh) now points at
/home/code/9router with a keep-ours conflict policy.
2026-09-23 11:51:11 +07:00

94 lines
3.3 KiB
Nix

{
description = "9Router — AI routing gateway + Next.js dashboard (Nix build)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(self: super: {
bun = super.bun.overrideAttrs (old: rec {
version = "1.4.0";
src = super.fetchzip {
url = "https://github.com/oven-sh/bun/releases/download/bun-v1.4.0/bun-linux-x64.zip";
sha256 = "sha256:Poy0vf7yJ/hzk33QiQj5gnshI5Q7dfbaMD7xgwiyDKw=";
};
});
})
];
};
nodejs = pkgs.nodejs_22;
in {
packages.default = pkgs.stdenv.mkDerivation {
pname = "9router";
version = "0.5.86";
src = ./.;
nativeBuildInputs = [
pkgs.bun
pkgs.git
pkgs.python3
pkgs.gnumake
pkgs.gcc
pkgs.cacert
pkgs.makeBinaryWrapper
];
buildPhase = ''
export HOME=$TMPDIR/home
export npm_config_cache=$TMPDIR/npm-cache
mkdir -p "$npm_config_cache" "$HOME"
# SSL/TLS certs (Nix sandbox doesn't have system CA bundle)
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
export NODE_EXTRA_CA_CERTS=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
echo "=== bun install ==="
bun install 2>&1
echo "=== bun run build (next build --webpack) ==="
bun run build 2>&1
echo "=== Build complete ==="
'';
installPhase = ''
mkdir -p $out/bin $out/lib/9router
# Next.js standalone output (self-contained server + traced node_modules)
cp -r .next/standalone/* $out/lib/9router/
# Full node_modules from bun install — standalone trace can miss deps
# (e.g. undici for /v1/chat executor); overwrite traced subset
rm -rf $out/lib/9router/node_modules
cp -r node_modules $out/lib/9router/node_modules
# Full .next build (BUILD_ID, server chunks, static) — standalone output
# may omit it depending on Next version; the server requires it at runtime
cp -r .next $out/lib/9router/.next
rm -rf $out/lib/9router/.next/cache $out/lib/9router/.next/standalone
# Runtime engine + source dirs the standalone server traces/fetches
cp -r open-sse $out/lib/9router/open-sse 2>/dev/null || true
cp -r src $out/lib/9router/src 2>/dev/null || true
# Public assets
cp -r public $out/lib/9router/public 2>/dev/null || true
# Custom server (IP derivation, header sanitisation)
cp custom-server.js $out/lib/9router/custom-server.js
# Wrapper — cd into lib dir so process.cwd() resolves (Drizzle/relative lookups)
cat > $out/bin/9router << WRAPPER
#!${pkgs.runtimeShell}
export PATH=${nodejs}/bin:\$PATH
cd $out/lib/9router
exec ${nodejs}/bin/node custom-server.js
WRAPPER
chmod +x $out/bin/9router
'';
};
});
}