From 2384a4eef59e6825ce8c0f7ffd96c4a0d5bb2c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Mon, 11 Oct 2021 20:02:17 +0200 Subject: [PATCH] feat: add serveHtml helper --- configs/bvg.nix | 9 +++------ configs/radio/default.nix | 14 ++------------ lib/default.nix | 6 ++++++ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/configs/bvg.nix b/configs/bvg.nix index 9dc3e2f..02ccd40 100644 --- a/configs/bvg.nix +++ b/configs/bvg.nix @@ -1,11 +1,12 @@ { pkgs, lib, ... }: let + inherit (import ) serveHtml; stations = [ 900068204 # A/M 900068302 # KAS 900068203 # B-P ]; - fahrplanHtml = '' + fahrplan = pkgs.writeText "fahrplan.html" '' Fahrplan ) tmpfilesConfig; + inherit (import ) tmpfilesConfig serveHtml; radioStore = "/var/lib/radio"; htgenPort = 8080; @@ -197,17 +197,7 @@ in forceSSL = true; locations = lib.mkMerge ( [ - { - "/".extraConfig = '' - default_type "text/html"; - root ${pkgs.linkFarm "station-list" [{ - name = "index.html"; - path = import ./station-list.nix { inherit pkgs lib stations; }; - }]}; - index index.html; - ''; - # skip - } + { "/".extraConfig = serveHtml (import ./station-list.nix { inherit pkgs lib stations; }) pkgs; } ] ++ (lib.mapAttrsToList (name: station: { "= /${name}/status".proxyPass = "http://127.0.0.1:${toString htgenPort}"; "= /${name}/listen.ogg".proxyPass = "http://127.0.0.1:${toString station.streamPort}"; diff --git a/lib/default.nix b/lib/default.nix index 1f54d37..98060cd 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -7,6 +7,12 @@ rec { removeRules = lib.concatMapStringsSep "\n" (rule: "iptables -D ${rule} || true"); }; + serveHtml = file: pkgs: '' + default_type "text/html"; + root ${pkgs.linkFarm "fahrplan" [{ name = "index.html"; path = file; }]}; + index index.html; + ''; + sshPort = 22022; colours = import ./colours/mac-os.nix;