1
Fork 0
mirror of https://github.com/RGBCube/Site synced 2025-08-01 13:37:49 +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. 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` ### `services.site.configureNginx`
Whether to configure Nginx and set the reverse proxy settings. 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 { configureNginx = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
@ -138,10 +147,7 @@
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
services.nginx = let services.nginx = mkIf cfg.configureNginx {
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
urlStripped = removeSuffix "/" (removePrefix "https://" cargoToml.package.homepage);
in mkIf cfg.configureNginx {
enable = true; enable = true;
recommendedGzipSettings = mkDefault true; recommendedGzipSettings = mkDefault true;
@ -149,25 +155,25 @@
recommendedProxySettings = mkDefault true; recommendedProxySettings = mkDefault true;
recommendedTlsSettings = mkDefault true; recommendedTlsSettings = mkDefault true;
virtualHosts.${urlStripped} = { virtualHosts.${cfg.url} = {
enableACME = true; enableACME = true;
forceSSL = true; forceSSL = true;
locations."/".proxyPass = "http://localhost:${toString cfg.port}"; locations."/".proxyPass = "http://localhost:${toString cfg.port}";
}; };
virtualHosts."www.${urlStripped}" = { virtualHosts."www.${cfg.url}" = {
forceSSL = true; forceSSL = true;
enableACME = true; enableACME = true;
locations."/".extraConfig = '' locations."/".extraConfig = ''
return 301 https://${urlStripped}$request_uri; return 301 https://${cfg.url}$request_uri;
''; '';
}; };
virtualHosts._ = { virtualHosts._ = {
forceSSL = true; forceSSL = true;
useACMEHost = urlStripped; useACMEHost = cfg.url;
locations."/".extraConfig = '' locations."/".extraConfig = ''
proxy_pass http://localhost:${toString cfg.port}/404; proxy_pass http://localhost:${toString cfg.port}/404;