mirror of
https://github.com/versia-pub/server.git
synced 2026-03-12 21:39:15 +01:00
build: 🏗️ Make Nix build great again
This commit is contained in:
parent
1679585c4c
commit
5a4ce29206
13 changed files with 6773 additions and 194 deletions
|
|
@ -1,33 +1,34 @@
|
|||
diff --git a/build.ts b/build.ts
|
||||
index 3b3ebe9..9531121 100644
|
||||
index a4ad17b2..516b55bf 100644
|
||||
--- a/build.ts
|
||||
+++ b/build.ts
|
||||
@@ -1,10 +1,10 @@
|
||||
@@ -1,12 +1,12 @@
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { $ } from "bun";
|
||||
import { build } from "bun";
|
||||
-import ora from "ora";
|
||||
+// import ora from "ora";
|
||||
import { routes } from "~/routes";
|
||||
|
||||
|
||||
-const buildSpinner = ora("Building").start();
|
||||
+// const buildSpinner = ora("Building").start();
|
||||
|
||||
-await $`rm -rf dist && mkdir dist`;
|
||||
+// await $`rm -rf dist && mkdir dist`;
|
||||
|
||||
await Bun.build({
|
||||
entrypoints: [
|
||||
@@ -25,7 +25,7 @@ await Bun.build({
|
||||
}
|
||||
|
||||
await $`rm -rf dist && mkdir dist`;
|
||||
|
||||
// Get all directories under the plugins/ directory
|
||||
const pluginDirs = await readdir("plugins", { withFileTypes: true });
|
||||
@@ -31,7 +31,7 @@ await build({
|
||||
external: ["acorn", "@bull-board/ui"],
|
||||
});
|
||||
|
||||
|
||||
-buildSpinner.text = "Transforming";
|
||||
+// buildSpinner.text = "Transforming";
|
||||
|
||||
// Copy Drizzle migrations to dist
|
||||
await $`cp -r drizzle dist/drizzle`;
|
||||
@@ -49,4 +49,4 @@ await $`cp package.json dist/package.json`;
|
||||
// Copy cli/theme.json
|
||||
await $`cp cli/theme.json dist/cli/theme.json`;
|
||||
|
||||
|
||||
// Fix Bun incorrectly transforming aliased imports
|
||||
await $`sed -i 's/var serveStatic = (options) => {/var serveStaticBase = (options) => {/g' dist/*.js`;
|
||||
@@ -63,4 +63,4 @@ await $`cp beemovie.txt dist/beemovie.txt`;
|
||||
// Copy package.json
|
||||
await $`cp package.json dist/package.json`;
|
||||
|
||||
-buildSpinner.stop();
|
||||
+// buildSpinner.stop();
|
||||
|
|
|
|||
155
nix/package.nix
155
nix/package.nix
|
|
@ -1,97 +1,88 @@
|
|||
{
|
||||
lib,
|
||||
stdenv,
|
||||
pnpm,
|
||||
bun,
|
||||
callPackage,
|
||||
modulesSrc ? callPackage ./source.nix {},
|
||||
nodePackages_latest,
|
||||
makeBinaryWrapper,
|
||||
}:
|
||||
nodejs,
|
||||
vips,
|
||||
makeWrapper,
|
||||
}: let
|
||||
packageJson = builtins.fromJSON (builtins.readFile ../package.json);
|
||||
in
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
pname = packageJson.name;
|
||||
version = packageJson.version;
|
||||
|
||||
assert lib.assertMsg (
|
||||
with builtins; hashFile "sha256" ../bun.lockb == hashFile "sha256" "${modulesSrc.src}/bun.lockb"
|
||||
) "bun.lockb has changed. Please run 'nix run .#apps.x86_64-linux.update-modules'";
|
||||
src = ../.;
|
||||
patches = [./fix-build-spinner.patch];
|
||||
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "versiajs";
|
||||
version = "0.7.0";
|
||||
# Fixes the build script mv usage
|
||||
pnpmInstallFlags = ["--shamefully-hoist"];
|
||||
|
||||
src = ../.;
|
||||
pnpmDeps = pnpm.fetchDeps {
|
||||
inherit (finalAttrs) pname version src pnpmInstallFlags;
|
||||
hash = "sha256-As7RBxTWgk8HlWr4/xn2j3rqf3N7r0VvFGMbMHjyCKA=";
|
||||
};
|
||||
|
||||
versiajsModules = stdenv.mkDerivation (modulesAttrs: {
|
||||
pname = "${finalAttrs.pname}-modules";
|
||||
nativeBuildInputs = [
|
||||
pnpm
|
||||
pnpm.configHook
|
||||
bun
|
||||
nodejs
|
||||
makeWrapper
|
||||
];
|
||||
|
||||
inherit (finalAttrs) version;
|
||||
|
||||
src = modulesSrc.src;
|
||||
|
||||
nativeBuildInputs = with nodePackages_latest; [ bun nodejs typescript ];
|
||||
|
||||
dontConfigure = true;
|
||||
buildInputs = [
|
||||
vips
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
bun install --production --no-progress --ignore-scripts --frozen-lockfile
|
||||
runHook preBuild
|
||||
|
||||
bun run build
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/node_modules
|
||||
cp -r node_modules $out
|
||||
installPhase = let
|
||||
libPath = lib.makeLibraryPath [
|
||||
vips
|
||||
stdenv.cc.cc.lib
|
||||
];
|
||||
|
||||
binPath = lib.makeBinPath [
|
||||
bun
|
||||
];
|
||||
in ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p $out
|
||||
cp -r dist $out/${finalAttrs.pname}
|
||||
|
||||
makeWrapper ${lib.getExe bun} $out/bin/${finalAttrs.pname} \
|
||||
--add-flags "run $out/${finalAttrs.pname}/index.js" \
|
||||
--set NODE_PATH $out/${finalAttrs.pname}/node_modules \
|
||||
--prefix PATH : ${binPath} \
|
||||
--prefix LD_LIBRARY_PATH : ${libPath}
|
||||
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
dontFixup = true;
|
||||
|
||||
outputHash = modulesSrc.outputHash.${stdenv.system};
|
||||
outputHashMode = "recursive";
|
||||
});
|
||||
|
||||
nativeBuildInputs = [ bun ];
|
||||
|
||||
buildInputs = [ bun nodePackages_latest.nodejs makeBinaryWrapper ];
|
||||
|
||||
patches = [ ./fix-build-spinner.patch ];
|
||||
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
|
||||
cp -r ${finalAttrs.versiajsModules}/node_modules .
|
||||
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
bun run build
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
cp -r dist/ $out
|
||||
|
||||
mkdir -p $out/bin
|
||||
|
||||
makeBinaryWrapper ${bun}/bin/bun $out/bin/versiajs \
|
||||
--prefix PATH : ${lib.makeBinPath [ bun ]} \
|
||||
--set NODE_ENV "production" \
|
||||
--add-flags "run --prefer-offline --no-install --cwd $out $out/index.js"
|
||||
|
||||
makeBinaryWrapper ${bun}/bin/bun $out/bin/versiajs-cli \
|
||||
--prefix PATH : ${lib.makeBinPath [ bun ]} \
|
||||
--add-flags "run --prefer-offline --no-install --cwd $out $out/cli/index.js"
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
passthru.updateScript = ./update.sh;
|
||||
|
||||
meta = {
|
||||
description = "A new federated server written with TypeScript and Bun ";
|
||||
homepage = "https://versia.pub";
|
||||
license = with lib.licenses; [ agpl3Plus ];
|
||||
maintainers = with lib.maintainers; [ snaki ];
|
||||
platforms = [ "x86_64-linux" "aarch64-linux" ];
|
||||
};
|
||||
})
|
||||
meta = with lib; {
|
||||
description = packageJson.description;
|
||||
homepage = packageJson.homepage;
|
||||
license = licenses.agpl3Only;
|
||||
maintainers = [
|
||||
{
|
||||
name = "CPlusPatch";
|
||||
email = "contact@cpluspatch.com";
|
||||
github = "CPlusPatch";
|
||||
githubId = 42910258;
|
||||
matrix = "@jesse:cpluspatch.dev";
|
||||
}
|
||||
];
|
||||
platforms = ["x86_64-linux" "aarch64-linux"];
|
||||
mainProgram = finalAttrs.pname;
|
||||
};
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
}: {
|
||||
outputHash.x86_64-linux = lib.fakeHash;
|
||||
outputHash.aarch64-linux = lib.fakeHash;
|
||||
src = fetchFromGitHub {
|
||||
owner = "versia-pub";
|
||||
repo = "server";
|
||||
rev = "fbb845f7f8ee97e51ff57edba3817224341d3078";
|
||||
hash = "sha256-pc5t6z/AE+NPZEzXxTlzT76jq5PF7Mvjh94A0NCBDh8=";
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue