nur-packages

My NUR packages
git clone git://git.sikmir.ru/nur-packages
Log | Files | Refs | README | LICENSE

commit 15df343c2415a6c4490d0ff03fef3043fd40ed78
parent ea71890b8a08f27b9abb61a556fed7d651b5bc82
Author: Nikolay Korotkiy <sikmir@disroot.org>
Date:   Fri, 14 Feb 2025 18:22:39 +0400

Add elevation_server module

Diffstat:
Mmodules/nixos/default.nix | 1+
Amodules/nixos/services/elevation_server.nix | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix @@ -1,4 +1,5 @@ { + elevation_server = ./services/elevation_server.nix; level0 = ./services/level0.nix; mbtileserver = ./services/mbtileserver.nix; tracks_storage_server = ./services/tracks_storage_server.nix; diff --git a/modules/nixos/services/elevation_server.nix b/modules/nixos/services/elevation_server.nix @@ -0,0 +1,95 @@ +{ + config, + lib, + pkgs, + ... +}: + +with lib; + +let + cfg = config.services.elevation_server; +in +{ + options.services.elevation_server = { + enable = mkEnableOption "elevation_server"; + package = mkPackageOption pkgs "elevation_server" { }; + address = mkOption { + type = types.str; + default = "127.0.0.1"; + description = "Address to bind to."; + }; + port = mkOption { + type = types.port; + default = 8080; + description = "Port to listen."; + }; + threads = mkOption { + type = types.int; + default = 10; + description = "Maximum number of concurrently served requests."; + }; + demTiles = mkOption { + type = types.path; + default = "/srv/tilesets/dem_tiles"; + description = "The path to file with elevation tile."; + }; + 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.elevation_server = { + description = "Elevation server"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + DynamicUser = true; + LogsDirectory = "elevation_server"; + ExecStart = "${getBin cfg.package}/bin/elevation_server -dem ${cfg.demTiles} -host ${cfg.address} -port ${toString cfg.port} -threads ${toString cfg.threads}"; + Restart = "always"; + }; + }; + } + (mkIf cfg.nginx.enable { + services.nginx = { + enable = true; + virtualHosts."${cfg.nginx.hostName}" = { + locations."/" = { + proxyPass = "http://${cfg.address}:${toString cfg.port}"; + extraConfig = '' + more_clear_headers Access-Control-Allow-Origin; + more_clear_headers Access-Control-Allow-Credentials; + more_set_headers 'Access-Control-Allow-Origin: $http_origin'; + more_set_headers 'Access-Control-Allow-Credentials: true'; + more_set_headers 'Cache-Control: max-age=86400'; + more_set_headers 'Vary: Origin'; + ''; + }; + }; + }; + }) + ]); +}