80 lines
3.1 KiB
Nix
80 lines
3.1 KiB
Nix
|
{
|
||
|
description = "Valkyrie server, written in Typescript.";
|
||
|
|
||
|
inputs = {
|
||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||
|
flake-utils.url = "github:numtide/flake-utils";
|
||
|
};
|
||
|
|
||
|
outputs = { self, nixpkgs, flake-utils }:
|
||
|
flake-utils.lib.eachSystem flake-utils.lib.allSystems (system:
|
||
|
let
|
||
|
pkgs = import nixpkgs {
|
||
|
inherit system;
|
||
|
};
|
||
|
hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json);
|
||
|
lib = pkgs.lib;
|
||
|
in rec {
|
||
|
packages.default = pkgs.buildNpmPackage {
|
||
|
pname = "valkyrie-server-ts";
|
||
|
name = "valkyrie-server-ts";
|
||
|
|
||
|
meta = with lib; {
|
||
|
description = "Valkyrie server, a FOSS reimplementation of the Discord backend.";
|
||
|
homepage = "https://toastielab.dev/ValkyrieChat/Server";
|
||
|
license = licenses.agpl3Plus;
|
||
|
platforms = platforms.all;
|
||
|
mainProgram = "start-bundle";
|
||
|
};
|
||
|
|
||
|
src = ./.;
|
||
|
nativeBuildInputs = with pkgs; [ python3 ];
|
||
|
npmDepsHash = hashesFile.npmDepsHash;
|
||
|
makeCacheWritable = true;
|
||
|
postPatch = ''
|
||
|
substituteInPlace package.json --replace 'npx patch-package' '${pkgs.nodePackages.patch-package}/bin/patch-package'
|
||
|
'';
|
||
|
installPhase = ''
|
||
|
runHook preInstall
|
||
|
set -x
|
||
|
#remove packages not needed for production, or at least try to...
|
||
|
npm prune --omit dev --no-save $npmInstallFlags "''${npmInstallFlagsArray[@]}" $npmFlags "''${npmFlagsArray[@]}"
|
||
|
find node_modules -maxdepth 1 -type d -empty -delete
|
||
|
|
||
|
mkdir -p $out/node_modules/
|
||
|
cp -r node_modules/* $out/node_modules/
|
||
|
cp -r dist/ $out/node_modules/@valkyrie
|
||
|
for i in dist/**/start.js
|
||
|
do
|
||
|
makeWrapper ${pkgs.nodejs-slim}/bin/node $out/bin/start-`dirname ''${i/dist\//}` --prefix NODE_PATH : $out/node_modules --add-flags $out/node_modules/@valkyrie`dirname ''${i/dist/}`/start.js
|
||
|
done
|
||
|
set +x
|
||
|
substituteInPlace package.json --replace 'dist/' 'node_modules/@valkyrie/'
|
||
|
find $out/node_modules/@valkyrie/ -type f -name "*.js" | while read srcFile; do
|
||
|
echo Patching imports in ''${srcFile/$out\/node_modules\/@valkyrie//}...
|
||
|
substituteInPlace $srcFile --replace 'require("./' 'require(__dirname + "/'
|
||
|
substituteInPlace $srcFile --replace 'require("../' 'require(__dirname + "/../'
|
||
|
substituteInPlace $srcFile --replace ', "assets"' ', "..", "assets"'
|
||
|
#substituteInPlace $srcFile --replace 'require("@valkyrie/' 'require("
|
||
|
done
|
||
|
set -x
|
||
|
cp -r assets/ $out/
|
||
|
cp package.json $out/
|
||
|
rm -v $out/assets/openapi.json
|
||
|
#rm -v $out/assets/schemas.json
|
||
|
|
||
|
#debug utils:
|
||
|
#cp $out/node_modules/@valkyrie/ $out/build_output -r
|
||
|
set +x
|
||
|
runHook postInstall
|
||
|
'';
|
||
|
};
|
||
|
devShell = pkgs.mkShell {
|
||
|
buildInputs = with pkgs; [
|
||
|
nodejs
|
||
|
nodePackages.typescript
|
||
|
];
|
||
|
};
|
||
|
}
|
||
|
);
|
||
|
}
|