tracks-storage-server-go.nix (2373B)
1 { 2 config, 3 lib, 4 pkgs, 5 ... 6 }: 7 8 with lib; 9 10 let 11 cfg = config.services.tracks-storage-server-go; 12 in 13 { 14 options.services.tracks-storage-server-go = { 15 enable = mkEnableOption "tracks-storage-server-go"; 16 package = mkPackageOption pkgs "tracks-storage-server-go" { }; 17 address = mkOption { 18 type = types.str; 19 default = "127.0.0.1"; 20 description = "IP address to listen on."; 21 }; 22 port = mkOption { 23 type = types.port; 24 default = 8080; 25 description = "Server port."; 26 }; 27 nginx = mkOption { 28 default = { }; 29 description = '' 30 Configuration for nginx reverse proxy. 31 ''; 32 type = types.submodule { 33 options = { 34 enable = mkOption { 35 type = types.bool; 36 default = false; 37 description = '' 38 Configure the nginx reverse proxy settings. 39 ''; 40 }; 41 hostName = mkOption { 42 type = types.str; 43 description = '' 44 The hostname use to setup the virtualhost configuration 45 ''; 46 }; 47 }; 48 }; 49 }; 50 }; 51 52 config = mkIf cfg.enable (mkMerge [ 53 { 54 systemd.services.tracks-storage-server-go = { 55 after = [ "network.target" ]; 56 wantedBy = [ "multi-user.target" ]; 57 environment.LISTEN_ADDR = "${cfg.address}:${toString cfg.port}"; 58 serviceConfig = { 59 DynamicUser = true; 60 LogsDirectory = "tracks-storage-server-go"; 61 ExecStart = "${getExe cfg.package}"; 62 Restart = "always"; 63 }; 64 }; 65 } 66 (mkIf cfg.nginx.enable { 67 services.nginx = { 68 enable = true; 69 virtualHosts."${cfg.nginx.hostName}" = { 70 locations."/" = { 71 proxyPass = "http://${cfg.address}:${toString cfg.port}"; 72 extraConfig = '' 73 more_clear_headers Access-Control-Allow-Origin; 74 more_clear_headers Access-Control-Allow-Credentials; 75 more_set_headers 'Access-Control-Allow-Origin: $http_origin'; 76 more_set_headers 'Access-Control-Allow-Credentials: true'; 77 more_set_headers 'Cache-Control: max-age=315360000'; 78 more_set_headers 'Expires: Thu, 31 Dec 2037 23:55:55 GMT'; 79 more_set_headers 'Vary: Origin'; 80 ''; 81 }; 82 }; 83 }; 84 }) 85 ]); 86 }
