diff options
Diffstat (limited to 'front/default.nix')
-rw-r--r-- | front/default.nix | 106 |
1 files changed, 74 insertions, 32 deletions
diff --git a/front/default.nix b/front/default.nix index e4192aa..adfbab2 100644 --- a/front/default.nix +++ b/front/default.nix @@ -4,12 +4,33 @@ , workadventure , yarn2nix-moretea , lib -, environment ? {} +, replace +, settings ? {} , ... }: let - envVar = (name: lib.optionalAttrs (environment ? ${name}) { ${name} = environment.${name}; }); + # 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" @@ -27,33 +48,54 @@ let // envVar "TURN_USER" // envVar "TURN_PASSWORD" // envVar "JITSI_URL" - // envVar "JITSI_PRIVATE_MODE"; -in yarn2nix-moretea.mkYarnPackage (rec { - pname = "workadventurefront"; - version = "unstable"; - - 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 ]; - - dontStrip = true; - - 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) + // 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) |