commit d6dbe6533f864da5222babab8961da6508c59bae parent 2572eaccff0ad5a9c0c7f6ec8c35813da4b2db0b Author: Nikolay Korotkiy <sikmir@disroot.org> Date: Tue, 12 Nov 2024 20:02:47 +0400 Update mbtileserver module Diffstat:
M | modules/nixos/services/mbtileserver.nix | | | 85 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ |
1 file changed, 72 insertions(+), 13 deletions(-)
diff --git a/modules/nixos/services/mbtileserver.nix b/modules/nixos/services/mbtileserver.nix @@ -13,20 +13,79 @@ in { options.services.mbtileserver = { enable = mkEnableOption "mbtileserver"; - }; - - config = mkIf cfg.enable { - systemd.services.mbtileserver = { - description = "MBTiles server"; - after = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - environment.TILE_DIR = "/srv/tilesets"; - serviceConfig = { - DynamicUser = true; - LogsDirectory = "mbtileserver"; - ExecStart = "${pkgs.mbtileserver}/bin/mbtileserver --enable-reload-signal --tiles-only"; - Restart = "always"; + package = mkOption { + type = types.package; + default = pkgs.mbtileserver; + defaultText = literalMD "pkgs.mbtileserver"; + description = "Which mbtileserver package to use."; + }; + tileDir = mkOption { + type = types.path; + default = "/srv/tilesets"; + description = "The path where *.mbtiles files stored."; + }; + nginx = mkOption { + default = { }; + description = '' + Configuration for nginx reverse proxy. + ''; + type = types.submodule { + options = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Configure the nginx reverse proxy settings. + ''; + }; + hostName = mkOption { + type = types.str; + description = '' + The hostname use to setup the virtualhost configuration + ''; + }; + }; }; }; }; + + config = mkIf cfg.enable (mkMerge [ + { + systemd.services.mbtileserver = { + description = "MBTiles server"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + environment.TILE_DIR = cfg.tileDir; + serviceConfig = { + DynamicUser = true; + LogsDirectory = "mbtileserver"; + ExecStart = "${lib.getBin cfg.package}/bin/mbtileserver --enable-reload-signal --tiles-only"; + Restart = "always"; + }; + }; + } + (mkIf cfg.nginx.enable { + services.nginx = { + enable = true; + virtualHosts."${cfg.nginx.hostName}" = { + locations."/" = { + root = cfg.tileDir; + extraConfig = '' + autoindex on; + autoindex_exact_size off; + ''; + }; + locations."/services" = { + proxyPass = "http://localhost:8000"; + extraConfig = '' + #proxy_set_header Host ''$host; + #proxy_set_header X-Forwarded-Host ''$server_name; + #proxy_set_header X-Real-IP ''$remote_addr; + add_header Cache-Control 'public, max-age=3600, must-revalidate'; + ''; + }; + }; + }; + }) + ]); }