draupnir: remove usage of mkYarnPackage, modernize (#463630)
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"yarn_offline_cache_hash": "sha256-kTdJ6zKNjH5CxcM9EvXzbz2Phrp5xI0+pvNwMLRmLgQ="
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
{
|
||||
"name": "draupnir",
|
||||
"version": "2.8.0",
|
||||
"description": "A moderation tool for Matrix",
|
||||
"main": "lib/index.js",
|
||||
"repository": "https://github.com/the-draupnir-project/Draupnir.git",
|
||||
"author": "Gnuxie",
|
||||
"license": "AFL-3.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsc --project test/tsconfig.json && tsc > /dev/null 2>&1 && corepack yarn copy-assets",
|
||||
"copy-assets": "cp src/protections/DraupnirNews/news.json lib/protections/DraupnirNews/news.json",
|
||||
"postbuild": "corepack yarn describe-version",
|
||||
"describe-version": "(git describe > version.txt.tmp && mv version.txt.tmp version.txt) || true && rm -f version.txt.tmp",
|
||||
"remove-tests-from-lib": "rm -rf lib/test/ && cp -r lib/src/* lib/ && rm -rf lib/src/",
|
||||
"lint": "corepack yarn eslint --cache src test && corepack yarn prettier --cache --ignore-unknown --check src test",
|
||||
"start:dev": "corepack yarn build && node --async-stack-traces lib/index.js",
|
||||
"test:unit": "mocha --require './test/tsnode.cjs' --forbid-only 'test/unit/**/*.{ts,tsx}'",
|
||||
"test:unit:single": "mocha --require test/tsnode.cjs",
|
||||
"test:integration": "NODE_ENV=harness mocha --require test/tsnode.cjs --async-stack-traces --forbid-only --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json \"test/integration/**/*Test.ts\"",
|
||||
"test:integration:single": "NODE_ENV=harness corepack yarn mocha --require test/tsnode.cjs --require test/integration/fixtures.ts --timeout 300000 --project ./tsconfig.json",
|
||||
"test:appservice:integration": "NODE_ENV=harness mocha --require test/tsnode.cjs --async-stack-traces --forbid-only --timeout 300000 --project ./tsconfig.json \"test/appservice/integration/**/*Test.ts\"",
|
||||
"test:appservice:integration:single": "NODE_ENV=harness corepack yarn mocha --require test/tsnode.cjs --timeout 300000 --project ./tsconfig.json",
|
||||
"test:manual": "NODE_ENV=harness ts-node test/integration/manualLaunchScript.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.7.0",
|
||||
"@types/better-sqlite3": "^7.6.9",
|
||||
"@types/config": "^3.3.1",
|
||||
"@types/crypto-js": "^4.2.2",
|
||||
"@types/eslint__js": "^8.42.3",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/html-to-text": "^8.0.1",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/jsdom": "21.1.7",
|
||||
"@types/mocha": "^10.0.7",
|
||||
"@types/nedb": "^1.8.16",
|
||||
"@types/node": "^20.14.11",
|
||||
"@types/pg": "^8.6.5",
|
||||
"@types/request": "^2.48.12",
|
||||
"crypto-js": "^4.2.0",
|
||||
"eslint": "^9.7.0",
|
||||
"expect": "^29.7.0",
|
||||
"mocha": "^10.7.0",
|
||||
"prettier": "^3.3.3",
|
||||
"ts-auto-mock": "^3.7.4",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.5.3",
|
||||
"typescript-eslint": "^7.16.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gnuxie/typescript-result": "^1.0.0",
|
||||
"@sentry/node": "^7.17.2",
|
||||
"@sinclair/typebox": "0.34.13",
|
||||
"@the-draupnir-project/interface-manager": "4.2.5",
|
||||
"@the-draupnir-project/matrix-basic-types": "1.4.1",
|
||||
"@the-draupnir-project/mps-interface-adaptor": "0.5.2",
|
||||
"better-sqlite3": "^9.4.3",
|
||||
"body-parser": "^1.20.2",
|
||||
"config": "^3.3.9",
|
||||
"express": "^4.19",
|
||||
"html-to-text": "^8.0.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsdom": "^24.0.0",
|
||||
"matrix-appservice-bridge": "^10.3.1",
|
||||
"matrix-bot-sdk": "npm:@vector-im/matrix-bot-sdk@^0.7.1-element.6",
|
||||
"matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@5.1.0",
|
||||
"matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@4.0.2",
|
||||
"pg": "^8.8.0",
|
||||
"yaml": "^2.3.2"
|
||||
},
|
||||
"overrides": {
|
||||
"matrix-bot-sdk": "$@vector-im/matrix-bot-sdk",
|
||||
"@vector-im/matrix-bot-sdk": "npm:@vector-im/matrix-bot-sdk@^0.7.1-element.6",
|
||||
"@the-draupnir-project/matrix-basic-types": "$the-draupnir-project/matrix-basic-types",
|
||||
"@the-draupnir-project/interface-manager": "$the-draupnir-project/interface-manager",
|
||||
"matrix-protection-suite": "$matrix-protection-suite"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
|
||||
}
|
||||
@@ -1,107 +1,103 @@
|
||||
{
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
makeWrapper,
|
||||
makeBinaryWrapper,
|
||||
nodejs,
|
||||
matrix-sdk-crypto-nodejs,
|
||||
python3,
|
||||
sqlite,
|
||||
srcOnly,
|
||||
removeReferencesTo,
|
||||
mkYarnPackage,
|
||||
fetchYarnDeps,
|
||||
stdenv,
|
||||
cctools,
|
||||
nixosTests,
|
||||
yarnBuildHook,
|
||||
yarnConfigHook,
|
||||
nix-update-script,
|
||||
}:
|
||||
|
||||
# docs: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#yarn2nix-javascript-yarn2nix
|
||||
let
|
||||
hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json);
|
||||
nodeSources = srcOnly nodejs;
|
||||
in
|
||||
mkYarnPackage rec {
|
||||
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "draupnir";
|
||||
version = "2.8.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "the-draupnir-project";
|
||||
repo = "Draupnir";
|
||||
tag = "v${version}";
|
||||
tag = "v${finalAttrs.version}";
|
||||
hash = "sha256-I9DYiNxD95pzHVsgZ/hJwHfrsVqE/eBALNiePVNDpy0=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
makeWrapper
|
||||
makeBinaryWrapper
|
||||
sqlite
|
||||
];
|
||||
python3
|
||||
yarnConfigHook
|
||||
yarnBuildHook
|
||||
nodejs
|
||||
]
|
||||
++ lib.optional stdenv.hostPlatform.isDarwin cctools.libtool;
|
||||
|
||||
offlineCache = fetchYarnDeps {
|
||||
name = "${pname}-yarn-offline-cache";
|
||||
yarnLock = src + "/yarn.lock";
|
||||
hash = hashesFile.yarn_offline_cache_hash;
|
||||
};
|
||||
|
||||
packageJSON = ./package.json;
|
||||
|
||||
pkgConfig = {
|
||||
"@matrix-org/matrix-sdk-crypto-nodejs" = {
|
||||
postInstall = ''
|
||||
# replace with the existing package in nixpkgs
|
||||
cd ..
|
||||
rm -r matrix-sdk-crypto-nodejs
|
||||
ln -s ${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/* ./
|
||||
'';
|
||||
};
|
||||
|
||||
better-sqlite3 = {
|
||||
nativeBuildInputs = [ python3 ] ++ lib.optional stdenv.hostPlatform.isDarwin cctools.libtool;
|
||||
postInstall = ''
|
||||
# build native sqlite bindings
|
||||
npm run build-release --offline --nodedir="${nodeSources}"
|
||||
find build -type f -exec \
|
||||
${lib.getExe removeReferencesTo} -t "${nodeSources}" {} \;
|
||||
'';
|
||||
};
|
||||
inherit (finalAttrs) src;
|
||||
hash = "sha256-kTdJ6zKNjH5CxcM9EvXzbz2Phrp5xI0+pvNwMLRmLgQ=";
|
||||
};
|
||||
|
||||
preBuild = ''
|
||||
# install proper version info
|
||||
mkdir --parents deps/draupnir/
|
||||
echo "${version}-nix" > deps/draupnir/version.txt
|
||||
echo "${finalAttrs.version}-nix" > version.txt
|
||||
|
||||
# makes network requests
|
||||
sed -i 's/corepack //g' deps/draupnir/package.json
|
||||
sed -i 's/corepack //g' package.json
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
yarn --offline --verbose build
|
||||
|
||||
runHook postBuild
|
||||
postBuild = ''
|
||||
yarn --offline run copy-assets
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
postInstall = ''
|
||||
# Re-install only production dependencies
|
||||
yarn install --frozen-lockfile --force --production --offline --non-interactive \
|
||||
--ignore-engines --ignore-platform --ignore-scripts --no-progress
|
||||
|
||||
mkdir --parents $out/share
|
||||
cp --archive . $out/share/draupnir
|
||||
# Replace matrix-sdk-crypto-nodejs with nixpkgs version
|
||||
nodeCryptoPath="node_modules/@matrix-org/matrix-sdk-crypto-nodejs"
|
||||
rm -rf "$nodeCryptoPath"
|
||||
cp -r ${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/matrix-sdk-crypto-nodejs \
|
||||
"$nodeCryptoPath"
|
||||
chmod -R a+rwx "$nodeCryptoPath"
|
||||
|
||||
# build better-sqlite3
|
||||
betterSqlitePath="node_modules/better-sqlite3"
|
||||
pushd "$betterSqlitePath"
|
||||
npm run build-release --offline --nodedir="${nodeSources}"
|
||||
rm -rf build/Release/{.deps,obj,obj.target,test_extension.node}
|
||||
find build -type f -exec \
|
||||
${lib.getExe removeReferencesTo} -t "${nodeSources}" {} \;
|
||||
popd
|
||||
|
||||
|
||||
mkdir -p $out/lib/node_modules/draupnir
|
||||
mkdir $out/bin
|
||||
# Install outputs
|
||||
mv ./lib ./version.txt ./node_modules ./package.json $out/lib/node_modules/draupnir
|
||||
|
||||
# Create wrapper executable
|
||||
makeWrapper ${lib.getExe nodejs} $out/bin/draupnir \
|
||||
--add-flags $out/share/draupnir/deps/draupnir/lib/index.js
|
||||
--add-flags "--enable-source-maps" \
|
||||
--add-flags "$out/lib/node_modules/draupnir/lib/index.js"
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
distPhase = "true";
|
||||
|
||||
passthru = {
|
||||
tests = { inherit (nixosTests) draupnir; };
|
||||
updateScript = ./update.sh;
|
||||
updateScript = nix-update-script { };
|
||||
};
|
||||
|
||||
meta = with lib; {
|
||||
meta = {
|
||||
description = "Moderation tool for Matrix";
|
||||
homepage = "https://github.com/the-draupnir-project/Draupnir";
|
||||
longDescription = ''
|
||||
@@ -118,8 +114,8 @@ mkYarnPackage rec {
|
||||
A Synapse module is also available to apply the same rulesets the bot
|
||||
uses across an entire homeserver.
|
||||
'';
|
||||
license = licenses.afl3;
|
||||
maintainers = with maintainers; [ RorySys ];
|
||||
license = lib.licenses.afl3;
|
||||
maintainers = with lib.maintainers; [ RorySys ];
|
||||
mainProgram = "draupnir";
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p curl common-updater-scripts coreutils jq prefetch-yarn-deps git
|
||||
|
||||
set -euo pipefail
|
||||
set -x
|
||||
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
|
||||
TMPDIR=$(mktemp -d)
|
||||
|
||||
echo "Getting versions..."
|
||||
latestVersion="$(curl -sL "https://api.github.com/repos/the-draupnir-project/Draupnir/releases?per_page=1" | jq -r '.[0].tag_name | ltrimstr("v")')"
|
||||
echo " --> Latest version: ${latestVersion}"
|
||||
currentVersion=$(nix-instantiate --eval -E "with import ./. {}; draupnir.version or (lib.getVersion draupnir)" | tr -d '"')
|
||||
echo " --> Current version: ${currentVersion}"
|
||||
if [[ "$currentVersion" == "$latestVersion" ]]; then
|
||||
echo "Draupnir is up-to-date: $currentVersion"
|
||||
exit 0
|
||||
else
|
||||
echo "We are out of date..."
|
||||
fi
|
||||
|
||||
curl https://raw.githubusercontent.com/the-draupnir-project/Draupnir/v$latestVersion/package.json -o pkgs/by-name/dr/draupnir/package.json
|
||||
|
||||
update-source-version draupnir "$latestVersion"
|
||||
|
||||
# Update yarn offline cache hash
|
||||
cd $TMPDIR
|
||||
|
||||
curl https://raw.githubusercontent.com/the-draupnir-project/Draupnir/v$latestVersion/yarn.lock -o yarn.lock
|
||||
TMP_PREFETCH_HASH=`prefetch-yarn-deps yarn.lock`
|
||||
NEW_YARN_OFFLINE_HASH=`nix --extra-experimental-features nix-command hash to-sri --type sha256 $TMP_PREFETCH_HASH`
|
||||
|
||||
cd -
|
||||
echo "New yarn offline hash: $NEW_YARN_OFFLINE_HASH"
|
||||
|
||||
TMPFILE=$(mktemp)
|
||||
jq '.yarn_offline_cache_hash = "'$NEW_YARN_OFFLINE_HASH'"' pkgs/by-name/dr/draupnir/hashes.json > $TMPFILE
|
||||
mv -- "$TMPFILE" pkgs/by-name/dr/draupnir/hashes.json
|
||||
Reference in New Issue
Block a user