1{
2 lib,
3 fetchgit,
4 fetchFromGitHub,
5 fetchFromGitLab,
6 fetchFromGitea,
7 python3,
8 poetry,
9 buildMaubotPlugin,
10}:
11
12let
13 json = builtins.fromJSON (builtins.readFile ./generated.json);
14in
15
16lib.flip builtins.mapAttrs json (
17 name: entry:
18 let
19 inherit (entry) manifest;
20
21 resolveDeps =
22 deps:
23 map (
24 name:
25 let
26 packageName = builtins.head (builtins.match "([^~=<>@]*).*" name);
27 lower = lib.toLower packageName;
28 dash = builtins.replaceStrings [ "_" ] [ "-" ] packageName;
29 lowerDash = builtins.replaceStrings [ "_" ] [ "-" ] lower;
30 in
31 python3.pkgs.${packageName} or python3.pkgs.${lower} or python3.pkgs.${dash}
32 or python3.pkgs.${lowerDash} or null
33 ) (builtins.filter (x: x != "maubot" && x != null) deps);
34
35 reqDeps = resolveDeps (lib.toList (manifest.dependencies or null));
36 optDeps = resolveDeps (lib.toList (manifest.soft_dependencies or null));
37 in
38
39 lib.makeOverridable buildMaubotPlugin (
40 entry.attrs
41 // {
42 pname = manifest.id;
43 inherit (manifest) version;
44
45 src =
46 if entry ? github then
47 fetchFromGitHub entry.github
48 else if entry ? git then
49 fetchgit entry.git
50 else if entry ? gitlab then
51 fetchFromGitLab entry.gitlab
52 else if entry ? gitea then
53 fetchFromGitea entry.gitea
54 else
55 throw "Invalid generated entry for ${manifest.id}: missing source";
56
57 propagatedBuildInputs = builtins.filter (x: x != null) (reqDeps ++ optDeps);
58
59 passthru.isOfficial = entry.isOfficial or false;
60
61 meta = entry.attrs.meta // {
62 license =
63 let
64 spdx = entry.attrs.meta.license or manifest.license or "unfree";
65 spdxLicenses = builtins.listToAttrs (
66 map (x: lib.nameValuePair x.spdxId x) (
67 builtins.filter (x: x ? spdxId) (builtins.attrValues lib.licenses)
68 )
69 );
70 in
71 spdxLicenses.${spdx};
72 broken = builtins.any (x: x == null) reqDeps;
73 };
74 }
75 // lib.optionalAttrs (entry.isPoetry or false) {
76 nativeBuildInputs = [
77 poetry
78 (python3.withPackages (
79 p: with p; [
80 toml
81 ruamel-yaml
82 isort
83 ]
84 ))
85 ];
86
87 preBuild = lib.optionalString (entry ? attrs.preBuild) (entry.attrs.preBuild + "\n") + ''
88 export HOME=$(mktemp -d)
89 [[ ! -d scripts ]] || patchShebangs --build scripts
90 make maubot.yaml
91 '';
92 }
93 )
94)