From c006338aecca09a928b60d3211df584f3616772c Mon Sep 17 00:00:00 2001 From: Daniel Frank Date: Sun, 11 Aug 2019 16:25:29 +0200 Subject: [PATCH] hopglass: test if hopglass works on nixos --- configuration.nix | 1 + hopglass-frontend.config.json | 63 +++++++++++++++++++++++++++++++++++ hopglass-frontend.nix | 21 ++++++++++++ pkg-hopglass-fe.nix | 44 ++++++++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 hopglass-frontend.config.json create mode 100644 hopglass-frontend.nix create mode 100644 pkg-hopglass-fe.nix diff --git a/configuration.nix b/configuration.nix index d4e5d33..be16b80 100644 --- a/configuration.nix +++ b/configuration.nix @@ -14,6 +14,7 @@ ./variables.nix ./mailserver.nix ./borgbackup.nix + ./hopglass-frontend.nix ]; # Configuration options for the mailserver diff --git a/hopglass-frontend.config.json b/hopglass-frontend.config.json new file mode 100644 index 0000000..2dcf598 --- /dev/null +++ b/hopglass-frontend.config.json @@ -0,0 +1,63 @@ +{ + "dataPath": "https://hopglass-backend.hamburg.freifunk.net/", + "siteName": "Freifunk Hamburg", + "mapSigmaScale": 1.1, + "showContact": false, + "maxAge": 30, + "mapLayers": [ + { + "name": "OpenStreetMap", + "url": "https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png", + "config": { + "maxZoom": 18, + "attribution": "© OpenStreetMap" + } + }, + { + "name": "Satellitenbild", + "url": "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}", + "config": { + "attribution": "Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community" + } + }, + { + "name": "Stamen (TonerLite)", + "url": "https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.png", + "config": { + "maxZoom": 20, + "attribution": "Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap" + } + } + ], + "nodeInfos": [ + { + "name": "Clientstatistik", + "href": "https://statistik.hamburg.freifunk.net/dashboard/db/freifunk-knoteninfo-knoten-id?var-region=ffhh&var-knoten={NODE_ID}", + "thumbnail": "https://statistik.hamburg.freifunk.net/render/dashboard-solo/db/freifunk-knoteninfo-knoten-id?panelId=1&var-region=ffhh&var-knoten={NODE_ID}&theme=light&width=530&height=332&from=now-3d", + "caption": "Verbundene Clients in den letzten 3 Tage an Knoten {NODE_ID}" + } + ], + "globalInfos": [ + { + "name": "Clientstatistik (gesamt)", + "href": "https://statistik.hamburg.freifunk.net/dashboard/db/freifunk-ubersicht?var-region=ffhh", + "thumbnail": "https://statistik.hamburg.freifunk.net/render/dashboard-solo/db/freifunk-ubersicht?panelId=1&var-region=ffhh&theme=light&width=530&height=332&from=now-3d", + "caption": "Verbundene Clients in den letzten 3 Tagen" + } + ], + "linkInfos": [], + "siteNames": [ + { "site": "ffhh", "name": "Hamburg" }, + { "site": "ffhh-nowe", "name": "Hamburg-NordWest" }, + { "site": "ffhh-ost", "name": "Hamburg-Ost" }, + { "site": "ffhh-sued", "name": "Hamburg-Sued" }, + { "site": "ffhh-west", "name": "Hamburg-West" } + ], + "domainNames": [ + { "domain": "ffhh_nowe", "name": "Hamburg-NordWest" }, + { "domain": "ffhh_ost", "name": "Hamburg-Ost" }, + { "domain": "ffhh_sued", "name": "Hamburg-Sued" }, + { "domain": "ffhh_west", "name": "Hamburg-West" } + ], + "hwImg": [] +} diff --git a/hopglass-frontend.nix b/hopglass-frontend.nix new file mode 100644 index 0000000..9c5890f --- /dev/null +++ b/hopglass-frontend.nix @@ -0,0 +1,21 @@ +{ config, lib, pkgs, ... }: + +let + hopglass-fe = (pkgs.callPackage ./pkg-hopglass-fe.nix { + conf = ./hopglass-frontend.config.json; + } ); +in +{ + services.nginx.virtualHosts."map2.hamburg.freifunk.net" = { + forceSSL = true; + enableACME = true; + root = "${hopglass-fe}"; + locations."/" = { + extraConfig = '' + index index.html; + etag off; + add_header etag "\"${builtins.substring 11 32 hopglass-fe}\""; + ''; + }; + }; +} diff --git a/pkg-hopglass-fe.nix b/pkg-hopglass-fe.nix new file mode 100644 index 0000000..8ec270c --- /dev/null +++ b/pkg-hopglass-fe.nix @@ -0,0 +1,44 @@ +{ stdenv, lib, pkgs, python, nodejs-11_x, fetchFromGitHub, fetchzip, fetchurl, conf }: +let + nodejs = nodejs-11_x; + yarn2nix = import (fetchFromGitHub { + rev = "3f2dbb08724bf8841609f932bfe1d61a78277232"; + owner = "moretea"; + repo = "yarn2nix"; + sha256 = "142av7dwviapsnahgj8r6779gs2zr17achzhr8b97s0hsl08dcl2"; + }) { inherit pkgs nodejs; }; + origPackage = builtins.fromJSON (builtins.readFile ./package.json); + src = fetchFromGitHub { + rev = "fc09b591dc2b9dd867559ea008f1177d52a824dd"; + owner = "hopglass"; + repo = "hopglass"; + sha256 = "0s9x466jqn7swbd35kjiaqk2lmcy9fnykhcnb1b10a2l35q655cl"; + }; +in +yarn2nix.mkYarnPackage { + name = "hopglass-frontend"; + src = src; + installPhase = '' + echo ---------------------------------------------------------------------------- installPhase + set -x + #yarn --offline build + ls -l + cp -R $src/. . + node_modules/.bin/grunt --force + mkdir -p $out + set +x + ''; + distPhase = '' + cp -Rv build/* $out/ + ln -s "$conf" $out/config.json + ''; + allowedReferences = [ "out" ]; + yarnPreBuild = '' + mkdir -p $HOME/.node-gyp/${nodejs.version} + echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion + ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version} + ''; + # work around some purity problems in nix + #yarnLock = ./yarn.lock; + #packageJSON = ./package.json; +}