commit f390f8cfc4e0a0fb0ec30a85947630d140194c3c
parent 26e9333fba7e9dedb84ebfa2141eaef361253bc7
Author: Nikolay Korotkiy <sikmir@disroot.org>
Date: Fri, 21 Aug 2026 03:04:33 +0400
Add tracks-storage-server-go module
Diffstat:
2 files changed, 87 insertions(+), 0 deletions(-)
diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix
@@ -3,4 +3,5 @@
level0 = ./services/level0.nix;
mbtileserver = ./services/mbtileserver.nix;
tracks-storage-server = ./services/tracks-storage-server.nix;
+ tracks-storage-server-go = ./services/tracks-storage-server-go.nix;
}
diff --git a/modules/nixos/services/tracks-storage-server-go.nix b/modules/nixos/services/tracks-storage-server-go.nix
@@ -0,0 +1,86 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+
+with lib;
+
+let
+ cfg = config.services.tracks-storage-server-go;
+in
+{
+ options.services.tracks-storage-server-go = {
+ enable = mkEnableOption "tracks-storage-server-go";
+ package = mkPackageOption pkgs "tracks-storage-server-go" { };
+ address = mkOption {
+ type = types.str;
+ default = "127.0.0.1";
+ description = "IP address to listen on.";
+ };
+ port = mkOption {
+ type = types.port;
+ default = 8080;
+ description = "Server port.";
+ };
+ 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.tracks-storage-server-go = {
+ after = [ "network.target" ];
+ wantedBy = [ "multi-user.target" ];
+ environment.LISTEN_ADDR = "${cfg.address}:${toString cfg.port}";
+ serviceConfig = {
+ DynamicUser = true;
+ LogsDirectory = "tracks-storage-server-go";
+ ExecStart = "${getExe cfg.package}";
+ 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=315360000';
+ more_set_headers 'Expires: Thu, 31 Dec 2037 23:55:55 GMT';
+ more_set_headers 'Vary: Origin';
+ '';
+ };
+ };
+ };
+ })
+ ]);
+}