From 210a4860ef16f3f00cd5265d238c2a7372a0daa5 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Fri, 26 Feb 2021 21:24:39 +0100 Subject: more options for the frontend --- front/default.nix | 141 ++++++++++++++++++++---------------------------------- 1 file changed, 51 insertions(+), 90 deletions(-) diff --git a/front/default.nix b/front/default.nix index 1851302..440fa00 100644 --- a/front/default.nix +++ b/front/default.nix @@ -5,97 +5,58 @@ , yarn2nix-moretea , lib , replace -, settings ? {} +, environment ? {} , ... }: 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"; + envIf = name: script: if environment ? name then script else ""; 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 = fetchFromGitHub { - owner = "thecodingmachine"; - repo = "workadventure"; - rev = "6e9c71598004dc9cbab9418efb3c0ac892da7ca2"; - sha256 = "0rvra0dy631al4aylacyqldkyd6biawz2shsikgcy30nv5lzc78c"; - } + "/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 '' ' '; - # 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) +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 = fetchFromGitHub { + owner = "thecodingmachine"; + repo = "workadventure"; + rev = "6e9c71598004dc9cbab9418efb3c0ac892da7ca2"; + sha256 = "0rvra0dy631al4aylacyqldkyd6biawz2shsikgcy30nv5lzc78c"; + } + "/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 '' ' '; + # 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",' ' '; + '' + + envIf "RESOLUTION" ''replace-literal -efsr -x .ts 'const RESOLUTION = 2' 'const RESOLUTION = ${environment.RESOLUTION}' '' + + envIf "ZOOM_LEVEL" ''replace-literal -efsr -x .ts 'const ZOOM_LEVEL = 1' 'const ZOOM_LEVEL = ${environment.ZOOM_LEVEL}' '' + + envIf "POSITION_DELAY" ''replace-literal -efsr -x .ts 'const POSITION_DELAY = 200' 'const POSITION_DELAY = ${environment.POSITION_DELAY}' '' + + envIf "MAX_EXTRAPOLATION_TIME" ''replace-literal -efsr -x .ts 'const MAX_EXTRAPOLATION_TIME = 100' 'const MAX_EXTRAPOLATION_TIME = ${environment.MAX_EXTRAPOLATION_TIME}' ''; + + 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 = ":"; + } // environment) -- cgit v1.2.3