From 81f236e18dc61632ed2fea160d21404878c54d36 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 10 Jan 2024 17:51:13 +0300 Subject: [PATCH] Add url option --- README.md | 7 +++++++ flake.nix | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 76227a7..46bb678 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ Specifies the log level that the site service will log stuff with. Default: info. +### `services.site.url` + +The url the site is running at. +Should not have a protocol speficier or trailing slashes. + +Required. + ### `services.site.configureNginx` Whether to configure Nginx and set the reverse proxy settings. diff --git a/flake.nix b/flake.nix index 178107e..c746251 100644 --- a/flake.nix +++ b/flake.nix @@ -127,6 +127,15 @@ ''; }; + url = mkOption { + type = types.str; + example = "rgbcu.be"; + description = mdDoc '' + The url the site is running at. + Should not have a protocol speficier or trailing slashes. + ''; + }; + configureNginx = mkOption { type = types.bool; default = false; @@ -138,10 +147,7 @@ }; 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 { + services.nginx = mkIf cfg.configureNginx { enable = true; recommendedGzipSettings = mkDefault true; @@ -149,25 +155,25 @@ recommendedProxySettings = mkDefault true; recommendedTlsSettings = mkDefault true; - virtualHosts.${urlStripped} = { + virtualHosts.${cfg.url} = { enableACME = true; forceSSL = true; locations."/".proxyPass = "http://localhost:${toString cfg.port}"; }; - virtualHosts."www.${urlStripped}" = { + virtualHosts."www.${cfg.url}" = { forceSSL = true; enableACME = true; locations."/".extraConfig = '' - return 301 https://${urlStripped}$request_uri; + return 301 https://${cfg.url}$request_uri; ''; }; virtualHosts._ = { forceSSL = true; - useACMEHost = urlStripped; + useACMEHost = cfg.url; locations."/".extraConfig = '' proxy_pass http://localhost:${toString cfg.port}/404;