mirror of
https://github.com/versia-pub/server.git
synced 2026-04-27 20:59:15 +02: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
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;
|
||||
};
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue