first commit
This commit is contained in:
83
nix/packages/bifrost-http.nix
Normal file
83
nix/packages/bifrost-http.nix
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
pkgs,
|
||||
inputs,
|
||||
src,
|
||||
version,
|
||||
bifrost-ui,
|
||||
}:
|
||||
let
|
||||
lib = pkgs.lib;
|
||||
|
||||
# Bifrost requires Go 1.26 (go.mod/go.work). Force Go 1.26 for buildGoModule.
|
||||
buildGoModule = pkgs.callPackage "${inputs.nixpkgs}/pkgs/build-support/go/module.nix" {
|
||||
go = pkgs.go_1_26 or pkgs.go;
|
||||
};
|
||||
|
||||
transportsLocalReplaces = ''
|
||||
if [ -f transports/go.mod ]; then
|
||||
cat >> transports/go.mod <<'EOF'
|
||||
|
||||
replace github.com/maximhq/bifrost/core => ../core
|
||||
replace github.com/maximhq/bifrost/framework => ../framework
|
||||
replace github.com/maximhq/bifrost/plugins/governance => ../plugins/governance
|
||||
replace github.com/maximhq/bifrost/plugins/compat => ../plugins/compat
|
||||
replace github.com/maximhq/bifrost/plugins/logging => ../plugins/logging
|
||||
replace github.com/maximhq/bifrost/plugins/maxim => ../plugins/maxim
|
||||
replace github.com/maximhq/bifrost/plugins/otel => ../plugins/otel
|
||||
replace github.com/maximhq/bifrost/plugins/semanticcache => ../plugins/semanticcache
|
||||
replace github.com/maximhq/bifrost/plugins/telemetry => ../plugins/telemetry
|
||||
EOF
|
||||
fi
|
||||
'';
|
||||
in
|
||||
buildGoModule {
|
||||
pname = "bifrost-http";
|
||||
inherit version;
|
||||
inherit src;
|
||||
|
||||
modRoot = "transports";
|
||||
subPackages = [ "bifrost-http" ];
|
||||
vendorHash = "sha256-Ck1cwv/DYI9EXmp7U2ZSNXlU+Qok8BFn5bcN1Pv7Nmc=";
|
||||
|
||||
doCheck = false;
|
||||
|
||||
overrideModAttrs = final: prev: {
|
||||
postPatch = (prev.postPatch or "") + transportsLocalReplaces;
|
||||
};
|
||||
|
||||
env = {
|
||||
CGO_ENABLED = "1";
|
||||
};
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
gcc
|
||||
];
|
||||
buildInputs = [ pkgs.sqlite ];
|
||||
|
||||
postPatch = transportsLocalReplaces;
|
||||
|
||||
preBuild = ''
|
||||
# Provide UI assets for //go:embed all:ui
|
||||
rm -rf bifrost-http/ui
|
||||
mkdir -p bifrost-http/ui
|
||||
if [ -d "${bifrost-ui}/ui" ]; then
|
||||
cp -R --no-preserve=mode,ownership,timestamps "${bifrost-ui}/ui/." bifrost-http/ui/
|
||||
else
|
||||
printf '%s\n' '<!doctype html><meta charset="utf-8"><title>Bifrost</title>' > bifrost-http/ui/index.html
|
||||
fi
|
||||
'';
|
||||
|
||||
ldflags = [
|
||||
"-s"
|
||||
"-w"
|
||||
"-X main.Version=${version}"
|
||||
];
|
||||
|
||||
meta = {
|
||||
mainProgram = "bifrost-http";
|
||||
description = "Bifrost HTTP gateway";
|
||||
homepage = "https://github.com/maximhq/bifrost";
|
||||
license = lib.licenses.asl20;
|
||||
};
|
||||
}
|
||||
48
nix/packages/bifrost-ui.nix
Normal file
48
nix/packages/bifrost-ui.nix
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
pkgs,
|
||||
src,
|
||||
version,
|
||||
}:
|
||||
pkgs.buildNpmPackage {
|
||||
pname = "bifrost-ui";
|
||||
inherit version;
|
||||
inherit src;
|
||||
sourceRoot = "source/ui";
|
||||
|
||||
npmDepsHash = "sha256-+tI2NUJtpHwvI9sAYMXO7r00Y3Pb1E62ms1ZSd3O0hM=";
|
||||
|
||||
# Next's `next/font/google` requires network access at build time.
|
||||
# Nix builds are sandboxed (no network), so patch the layout to avoid
|
||||
# fetching Google Fonts.
|
||||
postPatch = ''
|
||||
cat > app/layout.tsx <<'EOF'
|
||||
import "./globals.css"
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="en" suppressHydrationWarning>
|
||||
<head>
|
||||
<link rel="dns-prefetch" href="https://getbifrost.ai" />
|
||||
<link rel="preconnect" href="https://getbifrost.ai" />
|
||||
</head>
|
||||
<body className="font-sans antialiased">{children}</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
EOF
|
||||
'';
|
||||
|
||||
# Avoid the upstream build script's copy step (writes outside $PWD).
|
||||
npmBuildScript = "build-enterprise";
|
||||
env.NEXT_TELEMETRY_DISABLED = "1";
|
||||
env.NEXT_DISABLE_ESLINT = "1";
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p "$out/ui"
|
||||
cp -R --no-preserve=mode,ownership,timestamps out/. "$out/ui/"
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user