70 lines
1.7 KiB
Nix
70 lines
1.7 KiB
Nix
{
|
|
lib,
|
|
buildNpmPackage,
|
|
importNpmLock,
|
|
nodejs_22,
|
|
makeWrapper,
|
|
# linked to lib/bug-tv-discord/activity, config.js's default activityDir
|
|
activity ? null,
|
|
}:
|
|
|
|
let
|
|
nodejs = nodejs_22;
|
|
|
|
src = lib.fileset.toSource {
|
|
root = ../.;
|
|
fileset = lib.fileset.unions [
|
|
../src
|
|
../package.json
|
|
../package-lock.json
|
|
];
|
|
};
|
|
|
|
pkgJson = lib.importJSON ../package.json;
|
|
in
|
|
|
|
buildNpmPackage {
|
|
pname = "bug-tv-discord";
|
|
inherit (pkgJson) version;
|
|
inherit src nodejs;
|
|
|
|
# deps are fetched per-package from package-lock.json, no hash to keep in sync
|
|
npmDeps = importNpmLock { npmRoot = src; };
|
|
npmConfigHook = importNpmLock.npmConfigHook;
|
|
|
|
# esbuild's postinstall is only needed for the activity bundle (built with pkgs.esbuild)
|
|
npmFlags = [ "--ignore-scripts" ];
|
|
dontNpmBuild = true;
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
# the activity SDK and esbuild are dev deps; the bot only needs discord.js and ws
|
|
npm prune --omit=dev --ignore-scripts --offline --no-audit --no-fund
|
|
find node_modules -mindepth 1 -maxdepth 1 -type d -empty -delete
|
|
|
|
mkdir -p $out/lib/bug-tv-discord
|
|
cp -r src node_modules package.json $out/lib/bug-tv-discord/
|
|
|
|
makeWrapper ${lib.getExe nodejs} $out/bin/bug-tv-discord \
|
|
--add-flags $out/lib/bug-tv-discord/src/index.js \
|
|
--set-default NODE_ENV production
|
|
'' + lib.optionalString (activity != null) ''
|
|
ln -s ${activity} $out/lib/bug-tv-discord/activity
|
|
'' + ''
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
passthru = { inherit activity; };
|
|
|
|
meta = {
|
|
inherit (pkgJson) description;
|
|
homepage = "https://git.bug.tools/bug/tv-discord";
|
|
mainProgram = "bug-tv-discord";
|
|
platforms = lib.platforms.linux;
|
|
};
|
|
}
|