Merge pull request #157720 from jojosch/mjolnir-update

This commit is contained in:
Martin Weinelt 2022-02-18 21:31:08 +01:00 committed by GitHub
commit 88a2ad9746
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 406 additions and 416 deletions

View file

@ -98,7 +98,7 @@
</para>
<para>
To use the Antispam Module, add <package>matrix-synapse-plugins.matrix-synapse-mjolnir-antispam</package>
to the Synapse plugin list and enable the <literal>mjolnir.AntiSpam</literal> module.
to the Synapse plugin list and enable the <literal>mjolnir.Module</literal> module.
</para>
<programlisting>
{
@ -108,7 +108,7 @@
];
extraConfig = ''
modules:
- module: mjolnir.AntiSpam
- module: mjolnir.Module
config:
# Prevent servers/users in the ban lists from inviting users on this
# server to rooms. Default true.

View file

@ -1,16 +1,41 @@
{ lib, buildPythonPackage, fetchFromGitHub, matrix-synapse }:
{ lib, buildPythonPackage, fetchFromGitHub, matrix-synapse, fetchpatch }:
buildPythonPackage rec {
pname = "matrix-synapse-mjolnir-antispam";
version = "1.2.1";
version = "1.3.1";
src = fetchFromGitHub {
owner = "matrix-org";
repo = "mjolnir";
rev = "v${version}";
sha256 = "0fvdzn5l1a6bhr1qzgs30a3kh6nj0byqichnl149sjgr0v4lpkz1";
sha256 = "05O7NgqlsVu4mdx1+0CZgBvwvBCWYg7nSFknJiXxuoc=";
};
patches = [
# Update legacy antispam plugin with newer types. Or it'll just ignore mjolnir 1.3.1 rules.
(fetchpatch {
url = "https://github.com/matrix-org/mjolnir/commit/eb8c5e08b4c2b78e6a796e38e826ac3b7e9dfbaf.patch";
sha256 = "sha256-rfFU45PfxR2YmNRU74eBI9M2hqBVZcNH0Sw8W/cavD4=";
stripLen = 1;
})
# Port to Synapse module API (needs Synapse >= 1.37.0)
(fetchpatch {
url = "https://github.com/matrix-org/mjolnir/commit/9c9bd0e02907412b5fa6b95844e9f53ac07b61fd.patch";
sha256 = "sha256-HR2OvqFnlQwRV7ezfOjseatjo+3P8i9PsV7D+hLD1Yo=";
stripLen = 1;
excludes = [
"README.md"
"mx-tester.yml"
];
})
# Move glob_to_regex into the source
(fetchpatch {
url = "https://github.com/matrix-org/mjolnir/commit/6cb461fed424f07bf50a1fdc0693d40ed8bbee12.patch";
sha256 = "sha256-tqcKXNs+fxwPIvN5sJjdNgcz5KUVHiXgulLHR2redYk=";
stripLen = 1;
})
];
sourceRoot = "./source/synapse_antispam";
propagatedBuildInputs = [ matrix-synapse ];

View file

@ -9,13 +9,13 @@
stdenv.mkDerivation rec {
pname = "mjolnir";
version = "1.2.1";
version = "1.3.1";
src = fetchFromGitHub {
owner = "matrix-org";
repo = "mjolnir";
rev = "v${version}";
sha256 = "4c9LyQb5SZ1IoBayiP0C0ho4hwJDv49DhsuoQIv9bTs=";
sha256 = "05O7NgqlsVu4mdx1+0CZgBvwvBCWYg7nSFknJiXxuoc=";
};
nativeBuildInputs = [

View file

@ -2,11 +2,11 @@
{pkgs ? import <nixpkgs> {
inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}:
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-14_x"}:
let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv lib python2 runCommand writeTextFile;
inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript;
inherit pkgs nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
# This file originates from node2nix
{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile}:
{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}:
let
# Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
@ -40,36 +40,22 @@ let
'';
};
includeDependencies = {dependencies}:
lib.optionalString (dependencies != [])
(lib.concatMapStrings (dependency:
''
# Bundle the dependencies of the package
mkdir -p node_modules
cd node_modules
# Common shell logic
installPackage = writeShellScript "install-package" ''
installPackage() {
local packageName=$1 src=$2
# Only include dependencies if they don't exist. They may also be bundled in the package.
if [ ! -e "${dependency.name}" ]
then
${composePackage dependency}
fi
local strippedName
cd ..
''
) dependencies);
# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
DIR=$(pwd)
local DIR=$PWD
cd $TMPDIR
unpackFile ${src}
unpackFile $src
# Make the base dir in which the target dependency resides first
mkdir -p "$(dirname "$DIR/${packageName}")"
mkdir -p "$(dirname "$DIR/$packageName")"
if [ -f "${src}" ]
if [ -f "$src" ]
then
# Figure out what directory has been unpacked
packageDir="$(find . -maxdepth 1 -type d | tail -1)"
@ -79,28 +65,53 @@ let
chmod -R u+w "$packageDir"
# Move the extracted tarball into the output folder
mv "$packageDir" "$DIR/${packageName}"
elif [ -d "${src}" ]
mv "$packageDir" "$DIR/$packageName"
elif [ -d "$src" ]
then
# Get a stripped name (without hash) of the source directory.
# On old nixpkgs it's already set internally.
if [ -z "$strippedName" ]
then
strippedName="$(stripHash ${src})"
strippedName="$(stripHash $src)"
fi
# Restore write permissions to make building work
chmod -R u+w "$strippedName"
# Move the extracted directory into the output folder
mv "$strippedName" "$DIR/${packageName}"
mv "$strippedName" "$DIR/$packageName"
fi
# Unset the stripped name to not confuse the next unpack step
unset strippedName
# Change to the package directory to install dependencies
cd "$DIR/$packageName"
}
'';
# Include the dependencies of the package
cd "$DIR/${packageName}"
# Bundle the dependencies of the package
#
# Only include dependencies if they don't exist. They may also be bundled in the package.
includeDependencies = {dependencies}:
lib.optionalString (dependencies != []) (
''
mkdir -p node_modules
cd node_modules
''
+ (lib.concatMapStrings (dependency:
''
if [ ! -e "${dependency.name}" ]; then
${composePackage dependency}
fi
''
) dependencies)
+ ''
cd ..
''
);
# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
installPackage "${packageName}" "${src}"
${includeDependencies { inherit dependencies; }}
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
@ -415,6 +426,8 @@ let
passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
installPhase = ''
source ${installPackage}
# Create and enter a root node_modules/ folder
mkdir -p $out/lib/node_modules
cd $out/lib/node_modules
@ -492,6 +505,8 @@ let
passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
installPhase = ''
source ${installPackage}
mkdir -p $out/${packageName}
cd $out/${packageName}

View file

@ -20,7 +20,7 @@ store_src="$(nix-build . -A mjolnir.src --no-out-link)"
cd "$(dirname "${BASH_SOURCE[0]}")"
node2nix \
--nodejs-12 \
--nodejs-14 \
--development \
--node-env ./node-env.nix \
--output ./node-deps.nix \