nixpkgs/pkgs/servers/matrix-appservice-discord/default.nix
pacien 895da4caae matrix-appservice-discord: 1.0.0 -> 3.1.0
- This also takes into account the transfer of the project and repository
  to the matrix-org organisation on GitHub.

- The Node version assertion has been removed because our `pkgs.nodejs`
  already points to version 18.

- This replaces the `.nix` lock file (generated with `yarn2nix`) with a
  hash-pinned fixed-output derivation, which is simpler to work with.

- This replaces the old "generate.sh" script with one that updates all the
  version info and hashes (package.json, source version, source hash,
  and Yarn dependencies hash).
  This is inspired by the update script used for the
  "matrix-appservice-slack" package.

- This switches to srcOnly for node sources.

- Added pkgs.matrix-sdk-crypto-nodejs new required native dependency.
2022-11-15 23:26:00 -05:00

100 lines
2.3 KiB
Nix

{ lib
, mkYarnPackage
, fetchYarnDeps
, fetchFromGitHub
, srcOnly
, makeWrapper
, removeReferencesTo
, python3
, nodejs
, matrix-sdk-crypto-nodejs
}:
let
pin = lib.importJSON ./pin.json;
nodeSources = srcOnly nodejs;
in mkYarnPackage rec {
pname = "matrix-appservice-discord";
inherit (pin) version;
src = fetchFromGitHub {
owner = "matrix-org";
repo = "matrix-appservice-discord";
rev = "v${version}";
sha256 = pin.srcSha256;
};
packageJSON = ./package.json;
offlineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
sha256 = pin.yarnSha256;
};
pkgConfig = {
"@matrix-org/matrix-sdk-crypto-nodejs" = {
postInstall = ''
# replace with the built package
cd ..
rm -r matrix-sdk-crypto-nodejs
ln -s ${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/* ./
'';
};
better-sqlite3 = {
nativeBuildInputs = [ python3 ];
postInstall = ''
# build native sqlite bindings
npm run build-release --offline --nodedir="${nodeSources}"
find build -type f -exec \
${removeReferencesTo}/bin/remove-references-to \
-t "${nodeSources}" {} \;
'';
};
};
nativeBuildInputs = [ makeWrapper ];
buildPhase = ''
# compile TypeScript sources
yarn --offline build
'';
doCheck = true;
checkPhase = ''
# the default 2000ms timeout is sometimes too short on our busy builders
yarn --offline test --timeout 10000
'';
postInstall = ''
OUT_JS_DIR="$out/${passthru.nodeAppDir}/build"
# server wrapper
makeWrapper '${nodejs}/bin/node' "$out/bin/${pname}" \
--add-flags "$OUT_JS_DIR/src/discordas.js"
# admin tools wrappers
for toolPath in $OUT_JS_DIR/tools/*; do
makeWrapper '${nodejs}/bin/node' \
"$out/bin/${pname}-$(basename $toolPath .js)" \
--add-flags "$toolPath"
done
'';
# don't generate the dist tarball
doDist = false;
passthru = {
nodeAppDir = "libexec/${pname}/deps/${pname}";
updateScript = ./update.sh;
};
meta = {
description = "A bridge between Matrix and Discord";
homepage = "https://github.com/Half-Shot/matrix-appservice-discord";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ pacien ];
platforms = lib.platforms.linux;
};
}