1
Fork 0
mirror of https://github.com/RGBCube/Site synced 2025-07-31 13:07:46 +00:00

Add url option

This commit is contained in:
RGBCube 2024-01-10 17:51:13 +03:00
parent 90d744ac15
commit 81f236e18d
No known key found for this signature in database
2 changed files with 21 additions and 8 deletions

View file

@ -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.

View file

@ -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;