From b7db8421fbe6ee544b57b4f0c0d751279568150e Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 10 Jan 2024 10:09:37 +0300 Subject: [PATCH] Set default port to 4777 and add configureNginx option --- README.md | 8 +++++++- flake.nix | 24 +++++++++++++++++++++++- src/main.rs | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e3baf83..76227a7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Default: false. Specifies on which port the site service listens for connections. -Default: 8080. +Default: 4777. ### `services.site.logLevel` @@ -30,6 +30,12 @@ Specifies the log level that the site service will log stuff with. Default: info. +### `services.site.configureNginx` + +Whether to configure Nginx and set the reverse proxy settings. + +Default: false. + ## License All the markdown files under the `src/` directory are licensed diff --git a/flake.nix b/flake.nix index 8413376..8b038ab 100644 --- a/flake.nix +++ b/flake.nix @@ -111,7 +111,7 @@ port = mkOption { type = types.port; - default = 8080; + default = 4777; example = 80; description = mdDoc '' Specifies on which port the site service listens for connections. @@ -126,10 +126,32 @@ Specifies the log level that the site service will log stuff with. ''; }; + + configureNginx = mkOption { + type = types.bool; + default = false; + description = mdDoc '' + Whether to configure Nginx and set the reverse proxy settings. + ''; + }; }; }; config = mkIf cfg.enable { + services.nginx = let + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + urlStripped = removeSuffix "/" (removePrefix "https://" cargoToml.package.homepage); + in mkIf cfg.configureNginx { + enable = true; + + recommendedGzipSettings = mkDefault true; + recommendedOptimisation = mkDefault true; + recommendedProxySettings = mkDefault true; + recommendedTlsSettings = mkDefault true; + + virtualHosts.${urlStripped}.proxyPass = "http://127.0.0.1:${cfg.port}"; + }; + systemd.services.site = { description = "RGBCube's Homepage"; requires = [ "network.target" ]; diff --git a/src/main.rs b/src/main.rs index 3b03692..5e9e35d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use tower_http::trace::TraceLayer; #[command(author, version, about)] struct Cli { /// The port to listen for connections on - #[arg(long, default_value = "8080")] + #[arg(long, default_value = "4777")] port: u16, /// The log level to log stuff with #[arg(long, default_value = "info")]