1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 nodejs,
6 yarn-berry,
7 cacert,
8 nix-update-script,
9 formats,
10 baseUrl ? null,
11}:
12
13let
14 config = lib.optionalAttrs (baseUrl != null) { restrictBaseUrl = baseUrl; };
15 configFormat = formats.json { };
16 configFile = configFormat.generate "synapse-admin-config" config;
17in
18
19stdenv.mkDerivation (finalAttrs: {
20 pname = "synapse-admin";
21 version = "0.11.1";
22
23 src = fetchFromGitHub {
24 owner = "Awesome-Technologies";
25 repo = "synapse-admin";
26 tag = finalAttrs.version;
27 hash = "sha256-rK1Tc1K3wx6/1J8TEw5Lb9g09gbt/1HoZdDrEFzxTQQ=";
28 };
29
30 # we cannot use fetchYarnDeps because that doesn't support yarn 2/berry lockfiles
31 yarnOfflineCache = stdenv.mkDerivation {
32 pname = "yarn-deps";
33 inherit (finalAttrs) version src;
34
35 nativeBuildInputs = [ yarn-berry ];
36
37 dontInstall = true;
38
39 env = {
40 YARN_ENABLE_TELEMETRY = 0;
41 NODE_EXTRA_CA_CERTS = "${cacert}/etc/ssl/certs/ca-bundle.crt";
42 };
43
44 supportedArchitectures = builtins.toJSON {
45 os = [
46 "darwin"
47 "linux"
48 ];
49 cpu = [
50 "arm"
51 "arm64"
52 "ia32"
53 "x64"
54 ];
55 libc = [
56 "glibc"
57 "musl"
58 ];
59 };
60
61 configurePhase = ''
62 runHook preConfigure
63
64 export HOME="$NIX_BUILD_TOP"
65 yarn config set enableGlobalCache false
66 yarn config set cacheFolder $out
67 yarn config set --json supportedArchitectures "$supportedArchitectures"
68
69 runHook postConfigure
70 '';
71
72 buildPhase = ''
73 runHook preBuild
74
75 mkdir -p $out
76 yarn install --immutable --mode skip-build
77
78 runHook postBuild
79 '';
80
81 outputHash = "sha256-IiViodAB1KAYsRRr8+zw3vrCbUYp7Mdtazi0Y6SEFNU=";
82 outputHashMode = "recursive";
83 };
84
85 nativeBuildInputs = [
86 nodejs
87 yarn-berry
88 ];
89
90 env = {
91 NODE_ENV = "production";
92 };
93
94 postPatch = ''
95 substituteInPlace vite.config.ts \
96 --replace-fail "git describe --tags" "echo ${finalAttrs.version}"
97 '';
98
99 configurePhase = ''
100 runHook preConfigure
101
102 export HOME="$NIX_BUILD_TOP"
103 yarn config set enableGlobalCache false
104 yarn config set cacheFolder $yarnOfflineCache
105
106 runHook postConfigure
107 '';
108
109 buildPhase = ''
110 runHook preBuild
111
112 yarn install --immutable --immutable-cache
113 yarn build
114
115 runHook postBuild
116 '';
117
118 installPhase = ''
119 runHook preInstall
120
121 cp -r dist $out
122 cp ${configFile} $out/config.json
123
124 runHook postInstall
125 '';
126
127 passthru.updateScript = nix-update-script { };
128
129 meta = {
130 description = "Admin UI for Synapse Homeservers";
131 homepage = "https://github.com/Awesome-Technologies/synapse-admin";
132 changelog = "https://github.com/Awesome-Technologies/synapse-admin/releases/tag/${finalAttrs.version}";
133 license = lib.licenses.asl20;
134 platforms = [
135 "x86_64-linux"
136 "aarch64-linux"
137 "x86_64-darwin"
138 "aarch64-darwin"
139 ];
140 maintainers = with lib.maintainers; [
141 mkg20001
142 ma27
143 ];
144 };
145})