2024-02-19 11:09:50 +01:00
|
|
|
{
|
|
|
|
description = "Spacebar server, written in Typescript.";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
};
|
|
|
|
|
2024-10-28 00:55:34 +01:00
|
|
|
outputs =
|
|
|
|
{
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
flake-utils,
|
|
|
|
}:
|
|
|
|
flake-utils.lib.eachSystem flake-utils.lib.allSystems (
|
|
|
|
system:
|
2024-02-19 11:09:50 +01:00
|
|
|
let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
};
|
|
|
|
hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json);
|
2024-06-28 12:13:17 +02:00
|
|
|
lib = pkgs.lib;
|
2024-10-28 00:55:34 +01:00
|
|
|
in
|
2024-11-17 20:42:23 +01:00
|
|
|
{
|
|
|
|
packages = {
|
|
|
|
default = pkgs.buildNpmPackage {
|
|
|
|
pname = "spacebar-server-ts";
|
|
|
|
name = "spacebar-server-ts";
|
2024-06-28 12:13:17 +02:00
|
|
|
|
2024-11-17 20:42:23 +01:00
|
|
|
meta = with lib; {
|
|
|
|
description = "Spacebar server, a FOSS reimplementation of the Discord backend.";
|
|
|
|
homepage = "https://github.com/spacebarchat/server";
|
|
|
|
license = licenses.agpl3Plus;
|
|
|
|
platforms = platforms.all;
|
|
|
|
mainProgram = "start-bundle";
|
|
|
|
};
|
2024-06-28 12:13:17 +02:00
|
|
|
|
2024-11-17 20:42:23 +01:00
|
|
|
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
|
2024-02-19 11:09:50 +01:00
|
|
|
|
2024-11-17 20:42:23 +01:00
|
|
|
mkdir -p $out
|
|
|
|
cp -r assets dist node_modules package.json $out/
|
|
|
|
for i in dist/**/start.js
|
|
|
|
do
|
|
|
|
makeWrapper ${pkgs.nodejs}/bin/node $out/bin/start-`dirname ''${i/dist\//}` --prefix NODE_PATH : $out/node_modules --add-flags $out/$i
|
|
|
|
done
|
2024-10-28 00:55:34 +01:00
|
|
|
|
2024-11-17 20:42:23 +01:00
|
|
|
set +x
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
};
|
2024-10-28 00:55:34 +01:00
|
|
|
|
2024-11-17 20:42:23 +01:00
|
|
|
update-nix = pkgs.writeShellApplication {
|
|
|
|
name = "update-nix";
|
|
|
|
runtimeInputs = with pkgs; [
|
|
|
|
prefetch-npm-deps
|
|
|
|
nix
|
|
|
|
jq
|
|
|
|
];
|
|
|
|
text = ''
|
|
|
|
nix flake update --extra-experimental-features 'nix-command flakes'
|
|
|
|
DEPS_HASH=$(prefetch-npm-deps package-lock.json)
|
|
|
|
TMPFILE=$(mktemp)
|
|
|
|
jq '.npmDepsHash = "'"$DEPS_HASH"'"' hashes.json > "$TMPFILE"
|
|
|
|
mv -- "$TMPFILE" hashes.json
|
|
|
|
'';
|
|
|
|
};
|
2024-02-19 11:09:50 +01:00
|
|
|
};
|
2024-11-17 20:42:23 +01:00
|
|
|
|
2024-02-19 11:09:50 +01:00
|
|
|
devShell = pkgs.mkShell {
|
|
|
|
buildInputs = with pkgs; [
|
|
|
|
nodejs
|
|
|
|
nodePackages.typescript
|
2024-10-29 20:59:02 +01:00
|
|
|
nodePackages.ts-node
|
|
|
|
nodePackages.patch-package
|
|
|
|
nodePackages.prettier
|
2024-02-19 11:09:50 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|