1{
2 lib,
3 fetchgit,
4 fetchFromGitHub,
5 fetchFromGitLab,
6 fetchFromGitea,
7 stdenvNoCC,
8 callPackage,
9 ensureNewerSourcesForZipFilesHook,
10 maubot,
11 python3,
12 poetry,
13 formats,
14}:
15
16let
17 # pname: plugin id (example: xyz.maubot.echo)
18 # version: plugin version
19 # other attributes are passed directly to stdenv.mkDerivation (you at least need src)
20 buildMaubotPlugin =
21 attrs@{
22 version,
23 pname,
24 base_config ? null,
25 ...
26 }:
27 stdenvNoCC.mkDerivation (
28 builtins.removeAttrs attrs [ "base_config" ]
29 // {
30 pluginName = "${pname}-v${version}.mbp";
31 nativeBuildInputs = (attrs.nativeBuildInputs or [ ]) ++ [
32 ensureNewerSourcesForZipFilesHook
33 maubot
34 ];
35 buildPhase = ''
36 runHook preBuild
37
38 mbc build
39
40 runHook postBuild
41 '';
42
43 postPatch =
44 lib.optionalString (base_config != null) ''
45 [ -e base-config.yaml ] || (echo "base-config.yaml doesn't exist, can't override it" && exit 1)
46 cp "${
47 if builtins.isPath base_config || lib.isDerivation base_config then
48 base_config
49 else if builtins.isString base_config then
50 builtins.toFile "base-config.yaml" base_config
51 else
52 (formats.yaml { }).generate "base-config.yaml" base_config
53 }" base-config.yaml
54 ''
55 + attrs.postPatch or "";
56
57 installPhase = ''
58 runHook preInstall
59
60 mkdir -p $out/lib/maubot-plugins
61 install -m 444 $pluginName $out/lib/maubot-plugins
62
63 runHook postInstall
64 '';
65 }
66 );
67
68 generated = import ./generated.nix {
69 inherit
70 lib
71 fetchgit
72 fetchFromGitHub
73 fetchFromGitLab
74 fetchFromGitea
75 python3
76 poetry
77 buildMaubotPlugin
78 ;
79 };
80in
81generated
82// {
83 inherit buildMaubotPlugin;
84
85 allOfficialPlugins = builtins.filter (x: x.isOfficial && !x.meta.broken) (
86 builtins.attrValues generated
87 );
88
89 allPlugins = builtins.filter (x: !x.meta.broken) (builtins.attrValues generated);
90}