diff --git a/pkgs/by-name/ox/oxdraw/font-lookup.patch b/pkgs/by-name/ox/oxdraw/font-lookup.patch new file mode 100644 index 000000000000..1111d0c816da --- /dev/null +++ b/pkgs/by-name/ox/oxdraw/font-lookup.patch @@ -0,0 +1,25 @@ +diff --git a/app/layout.tsx b/app/layout.tsx +index f589fac..56ccb67 100644 +--- a/app/layout.tsx ++++ b/app/layout.tsx +@@ -1,15 +1,15 @@ + import type { Metadata } from "next"; +-import { Geist, Geist_Mono } from "next/font/google"; ++import localFont from "next/font/local"; + import "./globals.css"; + +-const geistSans = Geist({ ++const geistSans = localFont({ ++ src: '../Geist-Regular.otf', + variable: "--font-geist-sans", +- subsets: ["latin"], + }); + +-const geistMono = Geist_Mono({ ++const geistMono = localFont({ ++ src: '../GeistMono-Regular.otf', + variable: "--font-geist-mono", +- subsets: ["latin"], + }); + + export const metadata: Metadata = { diff --git a/pkgs/by-name/ox/oxdraw/package.nix b/pkgs/by-name/ox/oxdraw/package.nix new file mode 100644 index 000000000000..d8fe85772f44 --- /dev/null +++ b/pkgs/by-name/ox/oxdraw/package.nix @@ -0,0 +1,79 @@ +{ + lib, + rustPlatform, + fetchFromGitHub, + pkg-config, + openssl, + buildNpmPackage, + geist-font, + nix-update-script, +}: +rustPlatform.buildRustPackage ( + finalAttrs: + let + # We manually build the frontend because otherwise it'll try to download stuff from within the sandbox and fail + frontend = buildNpmPackage { + pname = "oxdraw-frontend"; + inherit (finalAttrs) version src; + + sourceRoot = "source/frontend"; + + patches = [ + # By default, NextJS tries to fetch fonts from google + # Because of sandboxing, that fails, so we use the + # font from nixpkgs + ./font-lookup.patch + ]; + + buildPhase = '' + runHook preBuild + cp ${geist-font}/share/fonts/opentype/Geist{,Mono}-Regular.otf . + npm run build + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + cp -r out $out + runHook postInstall + ''; + + npmDepsHash = "sha256-Yyox/x78spQqCJDJkPVuzfeAbtd/fdyihDHudIqruo4="; + }; + in + { + pname = "oxdraw"; + version = "0.2.0"; + + src = fetchFromGitHub { + owner = "RohanAdwankar"; + repo = "oxdraw"; + tag = "v${finalAttrs.version}"; + hash = "sha256-2B0G5aWRtUvZiCsX1fOw6M2UhShZaDj11r/fXCemGVc="; + }; + + cargoHash = "sha256-YedNESkXKbfl7FWea7VpDR+59b9WLtZ7GNcyJ7D9yPg="; + + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ openssl ]; + + preBuild = '' + # The build.rs builds the frontend, which we manually build via Nix already + rm build.rs + ''; + + env.OXDRAW_BUNDLED_WEB_DIST = frontend; + + passthru.updateScript = nix-update-script { }; + + meta = { + description = "Diagram as Code Tool Written in Rust with Draggable Editing"; + homepage = "https://github.com/RohanAdwankar/oxdraw"; + changelog = "https://github.com/RohanAdwankar/oxdraw/releases/tag/v${finalAttrs.version}"; + license = lib.licenses.mit; + maintainers = [ lib.maintainers.kilyanni ]; + mainProgram = "oxdraw"; + platforms = lib.platforms.linux; + }; + } +)