1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
{ stdenv
, fetchFromGitLab
, makeWrapper
, workadventure
, yarn2nix-moretea
, lib
, replace
, settings ? {}
, ... }:
let
# nix is nice enough that we can just convert options written in
# camelCase into CAMEL_CASE to make environment vars out of them,
# which workadventure will use during its build
toCamelCase =
(name: builtins.replaceStrings
(map
(c : "_${c}")
lib.strings.lowerChars)
lib.strings.upperChars
(lib.strings.toLower name));
# helper function for defining optional environment arguments, which
# may be passed to this package through the `settings` argument
envVar =
(name: lib.optionalAttrs
(settings ? ${toCamelCase name})
{ ${name} = settings.${toCamelCase name}; });
# all (currently known) options for workadventure-front. Note that
# some of them are pseudo-options, which are not actually implemented
# by workadventure (yet?) and which are instead handled during the
# patch phase of this derivation.
envVars = envVar "DEBUG_MODE"
// envVar "API_URL"
// envVar "UPLOADER_URL"
// envVar "ADMIN_URL"
// envVar "MAPS_URL"
// envVar "API_HOST"
// envVar "UPLOADER_HOST"
// envVar "ADMIN_HOST"
// envVar "MAPS_HOST"
// envVar "API_PROTOCOL"
// envVar "UPLOADER_PROTOCOL"
// envVar "ADMIN_PROTOCOL"
// envVar "MAPS_PROTOCOL"
// envVar "TURN_SERVER"
// envVar "TURN_USER"
// envVar "TURN_PASSWORD"
// envVar "JITSI_URL"
// envVar "JITSI_PRIVATE_MODE"
// envVar "DEFAULT_MAP_URL"
// envVar "STUN_SERVER";
in
yarn2nix-moretea.mkYarnPackage
(rec {
pname = "workadventurefront";
version = "unstable";
# TODO: perhaps move this into its own file, to make it easily
# replacable across all workadventure packages.
src = fetchFromGitLab {
owner = "fediventure";
repo = "workadventure";
rev = "1bcf0757fd5203132edd17fc806d81e7699111a7";
sha256 = "0wwgfrcrpimpxjhk073yxlkcp1p0bn0glxd9wisyq5kv8s7jw1yz";
} + "/front";
# NOTE: this is optional and generated dynamically if omitted
yarnNix = ./yarn.nix;
nativeBuildInputs = [
makeWrapper
# includes `replace-literal` for patching. This command is
# actually the basis for `substituteInPlace`!
replace
];
dontStrip = true;
patchPhase = ''
# remove google tag manager
replace-literal -efsw '<script async src="https://www.googletagmanager.com/gtag/js?id=UA-10196481-11"></script>' ' ';
# remove quill js cdn
replace-literal -efsr -x .ts 'fileref.setAttribute("href", "https://cdn.quilljs.com/1.3.7/quill.snow.css");' ' ';
replace-literal -efsr '"@types/quill": "^1.3.7",' ' ';
replace-literal -efsr '"quill": "^1.3.7",' ' ';
''
+ (if envVars ? DEFAULT_MAP_URL then ''replace-literal -efs -r -x .ts "/Floor0/floor0.json" ${lib.escapeShellArg envVars.DEFAULT_MAP_URL};'' else "")
+ (if envVars ? STUN_SERVER then ''replace-literal -efs -r -x .ts "stun:stun.l.google.com:19302" ${lib.escapeShellArg envVars.STUN_SERVER};'' else "");
buildPhase = ''
mkdir -p $out
ln -s ${workadventure.messages.outPath}/generated deps/${pname}/src/Messages/generated
HOME=$TMPDIR yarn --offline run build
cp -r deps/${pname}/dist/ $out/
'';
distPhase = ":";
installPhase = ":";
} // envVars)
|