fix: 💚 Fix the Nix build, remove dependency on PNPM

This commit is contained in:
Jesse Wierzbinski 2025-07-06 02:25:06 +02:00
parent 30bb801f9f
commit eb096c5991
No known key found for this signature in database
8 changed files with 71 additions and 6899 deletions

View file

@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1750365781, "lastModified": 1751637120,
"narHash": "sha256-XE/lFNhz5lsriMm/yjXkvSZz5DfvKJLUjsS6pP8EC50=", "narHash": "sha256-xVNy/XopSfIG9c46nRmPaKfH1Gn/56vQ8++xWA8itO4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "08f22084e6085d19bcfb4be30d1ca76ecb96fe54", "rev": "5c724ed1388e53cc231ed98330a60eb2f7be4be3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -34,27 +34,10 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-bun": {
"locked": {
"lastModified": 1749427688,
"narHash": "sha256-mMfhQsEYlfOvtjMs6BNPduuRc4YP/+Mj3G+/KYLQLUw=",
"owner": "0xdsqr",
"repo": "nixpkgs",
"rev": "09f139e43b59756fcbd9437b3a8726238fa62880",
"type": "github"
},
"original": {
"owner": "0xdsqr",
"ref": "add-bun-support",
"repo": "nixpkgs",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs"
"nixpkgs-bun": "nixpkgs-bun"
} }
}, },
"systems": { "systems": {

View file

@ -3,7 +3,6 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-bun.url = "github:0xdsqr/nixpkgs/add-bun-support";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
@ -11,21 +10,14 @@
outputs = { outputs = {
self, self,
nixpkgs, nixpkgs,
nixpkgs-bun,
flake-utils, flake-utils,
... ...
}: }:
{ {
overlays.default = final: prev: rec { overlays.default = final: prev: rec {
versia-server = final.callPackage ./nix/package.nix { versia-server =
inherit final.callPackage ./nix/package.nix {
(nixpkgs-bun.legacyPackages.x86_64-linux) };
fetchBunDeps
bunConfigHook
bunInstallHook
bunBuildHook
;
};
versia-server-worker = final.callPackage ./nix/package-worker.nix { versia-server-worker = final.callPackage ./nix/package-worker.nix {
inherit versia-server; inherit versia-server;
}; };
@ -64,7 +56,6 @@
buildInputs = with pkgs; [ buildInputs = with pkgs; [
bun bun
vips vips
pnpm
nodePackages.typescript nodePackages.typescript
nodePackages.typescript-language-server nodePackages.typescript-language-server
nix-ld nix-ld

View file

@ -2,14 +2,8 @@
{versia-server, ...}: {versia-server, ...}:
versia-server.overrideAttrs (oldAttrs: { versia-server.overrideAttrs (oldAttrs: {
pname = "${oldAttrs.pname}-worker"; pname = "${oldAttrs.pname}-worker";
buildPhase = ''
runHook preBuild
bun run packages/worker/build.ts buildType = "worker";
runHook postBuild
'';
entrypointPath = "packages/worker/index.js";
meta = meta =
oldAttrs.meta oldAttrs.meta

View file

@ -5,10 +5,8 @@
nodejs, nodejs,
vips, vips,
makeWrapper, makeWrapper,
fetchBunDeps, stdenvNoCC,
bunConfigHook, writableTmpDirAsHomeHook,
bunInstallHook,
bunBuildHook,
... ...
}: let }: let
packageJson = builtins.fromJSON (builtins.readFile ../package.json); packageJson = builtins.fromJSON (builtins.readFile ../package.json);
@ -19,23 +17,70 @@ in
src = ../.; src = ../.;
bunOfflineCache = fetchBunDeps { node_modules = stdenvNoCC.mkDerivation {
bunLock = finalAttrs.src + "/bun.lock"; pname = "${finalAttrs.pname}-node_modules";
hash = "sha256-8R+LzgqAiqRGCMDBw2R7QO6hbdNrtIwzSjR3A8xhfVw="; inherit (finalAttrs) version src;
};
bunBuildScript = "packages/api/build.ts"; nativeBuildInputs = [
bun
nodejs
writableTmpDirAsHomeHook
];
dontConfigure = true;
buildPhase = ''
runHook preBuild
export BUN_INSTALL_CACHE_DIR=$(mktemp -d)
bun install \
--force \
--frozen-lockfile \
--no-progress
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/node_modules
cp -R ./node_modules $out
runHook postInstall
'';
# Required else we get errors that our fixed-output derivation references store paths
dontFixup = true;
outputHash = "sha256-/RQv87hjLdH6+41yR7+bGp3j200DVhIrKWoI1MKIqJs=";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
};
nativeBuildInputs = [ nativeBuildInputs = [
bun bun
nodejs
makeWrapper makeWrapper
bunConfigHook
bunInstallHook
bunBuildHook
]; ];
entrypointPath = "packages/api/index.js"; configurePhase = ''
runHook preConfigure
cp -R ${finalAttrs.node_modules}/node_modules .
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
bun run build ${finalAttrs.buildType}
runHook postBuild
'';
buildType = "api";
installPhase = let installPhase = let
libPath = lib.makeLibraryPath [ libPath = lib.makeLibraryPath [
@ -53,7 +98,7 @@ in
cp -r dist $out/${finalAttrs.pname} cp -r dist $out/${finalAttrs.pname}
makeWrapper ${lib.getExe bun} $out/bin/${finalAttrs.pname} \ makeWrapper ${lib.getExe bun} $out/bin/${finalAttrs.pname} \
--add-flags "run $out/${finalAttrs.pname}/${finalAttrs.entrypointPath}" \ --add-flags "run $out/${finalAttrs.pname}/${finalAttrs.buildType}.js" \
--set NODE_PATH $out/${finalAttrs.pname}/node_modules \ --set NODE_PATH $out/${finalAttrs.pname}/node_modules \
--set MSGPACKR_NATIVE_ACCELERATION_DISABLED true \ --set MSGPACKR_NATIVE_ACCELERATION_DISABLED true \
--prefix PATH : ${binPath} \ --prefix PATH : ${binPath} \

View file

@ -123,6 +123,7 @@
"test": "bun test", "test": "bun test",
"build": "bun run --filter \"*\" build && bun run build.ts", "build": "bun run --filter \"*\" build && bun run build.ts",
"detect-circular": "bunx madge --circular --extensions ts ./", "detect-circular": "bunx madge --circular --extensions ts ./",
"update-nix-hashes": "bash scripts/update-nix.sh",
"run-api": "bun run build api && cd dist && ln -s ../config config && bun run api.js", "run-api": "bun run build api && cd dist && ln -s ../config config && bun run api.js",
"run-worker": "bun run build worker && cd dist && ln -s ../config config && bun run worker.js", "run-worker": "bun run build worker && cd dist && ln -s ../config config && bun run worker.js",
"dev": "bun run --hot api.ts", "dev": "bun run --hot api.ts",

File diff suppressed because it is too large Load diff

View file

@ -1,86 +0,0 @@
packages:
- packages/*
onlyBuiltDependencies:
- esbuild
- msgpackr-extract
- sharp
shamefullyHoist: true
catalog:
{
"@biomejs/biome": "2.0.0-beta.5",
"@types/bun": "^1.2.16",
"@types/html-to-text": "^9.0.4",
"@types/markdown-it-container": "^2.0.10",
"@types/mime-types": "^3.0.1",
"@types/qs": "^6.14.0",
"@types/web-push": "^3.6.4",
"bun-bagel": "^1.2.0",
"drizzle-kit": "^0.31.1",
"mitt": "^3.0.1",
"markdown-it-image-figures": "^2.1.1",
"ts-prune": "^0.10.3",
"typescript": "^5.8.3",
"vitepress": "^1.6.3",
"vitepress-plugin-tabs": "^0.7.1",
"vitepress-sidebar": "^1.31.1",
"vue": "^3.5.16",
"zod-to-json-schema": "^3.24.5",
"@bull-board/api": "^6.10.1",
"@bull-board/hono": "^6.10.1",
"@clerc/plugin-completions": "^0.44.0",
"@clerc/plugin-friendly-error": "^0.44.0",
"@clerc/plugin-help": "^0.44.0",
"@clerc/plugin-not-found": "^0.44.0",
"@clerc/plugin-version": "^0.44.0",
"@hackmd/markdown-it-task-lists": "^2.1.4",
"@hono/zod-validator": "^0.7.0",
"@inquirer/confirm": "^5.1.12",
"@logtape/file": "^0.12.0",
"@logtape/logtape": "^0.12.0",
"@scalar/hono-api-reference": "^0.9.4",
"@sentry/bun": "^9.29.0",
"altcha-lib": "^1.3.0",
"blurhash": "^2.0.5",
"bullmq": "^5.53.3",
"chalk": "^5.4.1",
"clerc": "^0.44.0",
"confbox": "^0.2.2",
"drizzle-orm": "^0.44.2",
"feed": "^5.1.0",
"hono": "^4.7.11",
"hono-openapi": "^0.4.8",
"hono-rate-limiter": "^0.4.2",
"html-to-text": "^9.0.5",
"ioredis": "^5.6.1",
"ip-matching": "^2.1.2",
"iso-639-1": "^3.1.5",
"jose": "^6.0.11",
"linkify-html": "^4.3.1",
"linkify-string": "^4.3.1",
"linkifyjs": "^4.3.1",
"magic-regexp": "^0.10.0",
"markdown-it": "^14.1.0",
"markdown-it-anchor": "^9.2.0",
"markdown-it-container": "^4.0.0",
"markdown-it-mathjax3": "^4.3.2",
"markdown-it-toc-done-right": "^4.2.0",
"mime-types": "^3.0.1",
"mitata": "^1.0.34",
"oauth4webapi": "^3.5.2",
"ora": "^8.2.0",
"qs": "^6.14.0",
"sharp": "^0.34.2",
"sonic-channel": "^1.3.1",
"string-comparison": "^1.3.0",
"stringify-entities": "^4.0.4",
"unicode-emoji-json": "^0.8.0",
"uqr": "^0.1.2",
"web-push": "^3.6.7",
"xss": "^1.0.15",
"youch": "^4.1.0-beta.7",
"zod": "^3.25.64",
"zod-openapi": "^4.2.4",
"zod-validation-error": "^3.5.0",
}

View file

@ -1,11 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
# Step 1: Run pnpm install
pnpm i --lockfile-only
# Step 2: Blank the hash in package.nix # Step 2: Blank the hash in package.nix
sed -i 's/hash = ".*";/hash = lib.fakeHash;/g' nix/package.nix sed -i 's/outputHash = ".*";/outputHash = lib.fakeHash;/g' nix/package.nix
echo "Running nix build to get the correct hash..." echo "Running nix build to get the correct hash..."
@ -18,7 +15,7 @@ corrected_hash=$(echo "$build_output" | grep 'got:' | awk '{print $2}')
echo "Corrected hash: $corrected_hash" echo "Corrected hash: $corrected_hash"
# Step 5: Replace the blank hash with the corrected one # Step 5: Replace the blank hash with the corrected one
sed -i "s/hash = lib.fakeHash;/hash = \"$corrected_hash\";/g" nix/package.nix sed -i "s/outputHash = lib.fakeHash;/outputHash = \"$corrected_hash\";/g" nix/package.nix
echo "Rebuilding with the corrected hash..." echo "Rebuilding with the corrected hash..."