diff options
Diffstat (limited to 'host/Spacebar-nginx/containers/spacebar-server-dev-nix/services')
3 files changed, 189 insertions, 0 deletions
diff --git a/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/nginx.nix b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/nginx.nix new file mode 100755 index 0000000..d5b8366 --- /dev/null +++ b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/nginx.nix @@ -0,0 +1,115 @@ +{ config, pkgs, lib, spacebar-server, ... }: + +{ + services = { + nginx = { + enable = true; + package = pkgs.nginxQuic; + recommendedProxySettings = true; + recommendedZstdSettings = true; + recommendedGzipSettings = true; + recommendedBrotliSettings = true; + recommendedOptimisation = true; + appendConfig = '' + worker_processes 16; + ''; + eventsConfig = '' + #use kqueue; + worker_connections 512; + ''; + appendHttpConfig = '' + #sendfile on; + disable_symlinks off; + ''; + additionalModules = with pkgs.nginxModules; [ + moreheaders + ]; + virtualHosts = { + "dev-nix.server.spacebar.chat" = { + locations."= /.well-known/spacebarchat/client".extraConfig = '' + more_set_headers 'Content-Type application/json'; + more_set_headers 'Access-Control-Allow-Origin *'; + return 200 '${builtins.toJSON { + cdn = "cdn.dev-nix.server.spacebar.chat"; + gateway = "gateway.dev-nix.server.spacebar.chat"; + api = "api.dev-nix.server.spacebar.chat"; + }}'; + ''; + }; + "api.dev-nix.server.spacebar.chat" = { + locations."/" = { + proxyPass = "http://127.0.0.1:3001"; + extraConfig = '' + if ($request_method = 'OPTIONS') { + more_set_headers 'Access-Control-Allow-Origin: *'; + more_set_headers 'Access-Control-Allow-Methods: *'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + more_set_headers 'Access-Control-Allow-Headers: *'; + # + # Tell client that this pre-flight info is valid for 20 days + # + more_set_headers 'Access-Control-Max-Age: 1728000'; + more_set_headers 'Content-Type: text/plain; charset=utf-8'; + more_set_headers 'Content-Length: 0'; + return 204; + } + ''; + }; + }; + "cdn.dev-nix.server.spacebar.chat" = { + locations."/" = { + proxyPass = "http://127.0.0.1:3003"; + extraConfig = '' + if ($request_method = 'OPTIONS') { + more_set_headers 'Access-Control-Allow-Origin: *'; + more_set_headers 'Access-Control-Allow-Methods: *'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + more_set_headers 'Access-Control-Allow-Headers: *'; + # + # Tell client that this pre-flight info is valid for 20 days + # + more_set_headers 'Access-Control-Max-Age: 1728000'; + more_set_headers 'Content-Type: text/plain; charset=utf-8'; + more_set_headers 'Content-Length: 0'; + return 204; + } + ''; + }; + }; + "gateway.dev-nix.server.spacebar.chat" = { + locations."/" = { + proxyPass = "http://127.0.0.1:3002"; + extraConfig = '' + if ($request_method = 'OPTIONS') { + more_set_headers 'Access-Control-Allow-Origin: *'; + more_set_headers 'Access-Control-Allow-Methods: *'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + more_set_headers 'Access-Control-Allow-Headers: *'; + # + # Tell client that this pre-flight info is valid for 20 days + # + more_set_headers 'Access-Control-Max-Age: 1728000'; + more_set_headers 'Content-Type: text/plain; charset=utf-8'; + more_set_headers 'Content-Length: 0'; + return 204; + } + ''; + }; + }; + }; + }; + }; + systemd.services.nginx.serviceConfig = { + LimitNOFILE=5000000; + }; + security.acme.acceptTerms = true; + security.acme.defaults.email = "root@rory.gay"; + + system.stateVersion = "22.11"; # DO NOT EDIT! +} diff --git a/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/postgres.nix b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/postgres.nix new file mode 100644 index 0000000..97ea3e6 --- /dev/null +++ b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/postgres.nix @@ -0,0 +1,30 @@ +{ config, pkgs, lib, ... }: + +{ + #systemd.tmpfiles.rules = [ "d /data/pg 0750 postgres postgres" ]; + + services.postgresql = { + enable = true; + package = pkgs.postgresql_15; + enableTCPIP = true; + authentication = pkgs.lib.mkOverride 10 '' + # TYPE, DATABASE, USER, ADDRESS, METHOD + local all all trust + host all all 127.0.0.1/32 trust + host all all ::1/128 trust + host all all 0.0.0.0/0 md5 + ''; + initialScript = pkgs.writeText "backend-initScript" '' + CREATE ROLE spacebar WITH LOGIN PASSWORD 'spacebar' CREATEDB; + CREATE DATABASE spacebar; + GRANT ALL PRIVILEGES ON DATABASE spacebar TO spacebar; + ''; + #dataDir = "/data/pg"; + settings = { + "max_connections" = "100"; + "shared_buffers" = "128MB"; + "max_wal_size" = "1GB"; + "min_wal_size" = "80MB"; + }; + }; +} \ No newline at end of file diff --git a/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/spacebar-server.nix b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/spacebar-server.nix new file mode 100755 index 0000000..d207687 --- /dev/null +++ b/host/Spacebar-nginx/containers/spacebar-server-dev-nix/services/spacebar-server.nix @@ -0,0 +1,44 @@ +{ config, pkgs, lib, spacebar-server, ... }: + +{ + systemd.services = { + "spacebar-server-api" = { + wantedBy = [ "multi-user.target" ]; + after = [ "resolvconf.target" ]; + serviceConfig = { + ExecStart = '' + ${spacebar-server.packages.${pkgs.system}.default}/bin/start-api + ''; + #Restart = "never"; + User = "root"; + WorkingDirectory = "/var/lib/spacebar-server"; + }; + }; + "spacebar-server-gateway" = { + wantedBy = [ "multi-user.target" ]; + after = [ "resolvconf.target" ]; + serviceConfig = { + ExecStart = '' + ${spacebar-server.packages.${pkgs.system}.default}/bin/start-gateway + ''; + #Restart = "never"; + User = "root"; + WorkingDirectory = "/var/lib/spacebar-server"; + }; + }; + "spacebar-server-cdn" = { + wantedBy = [ "multi-user.target" ]; + after = [ "resolvconf.target" ]; + serviceConfig = { + ExecStart = '' + ${spacebar-server.packages.${pkgs.system}.default}/bin/start-cdn + ''; + #Restart = "never"; + User = "root"; + WorkingDirectory = "/var/lib/spacebar-server"; + }; + }; + }; + + system.stateVersion = "22.11"; # DO NOT EDIT! +} |