feat: Refactor web-servers module and move common configuration to common.nix
This commit is contained in:
parent
7093a338f4
commit
e5f942acbe
7 changed files with 94 additions and 76 deletions
|
@ -1,15 +1,25 @@
|
||||||
{ config, ... }:
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib) mkMerge mkIf mkEnableOption;
|
||||||
|
cfg = config.server.web-servers;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
config = {
|
options.server.web-servers = {
|
||||||
security.acme = {
|
enableSSL = mkEnableOption "";
|
||||||
acceptTerms = true;
|
};
|
||||||
defaults = {
|
|
||||||
email = "rafiq@rrv.sh";
|
config = mkMerge [
|
||||||
dnsProvider = "cloudflare";
|
(mkIf cfg.enableSSL {
|
||||||
credentialFiles = {
|
security.acme = {
|
||||||
"CLOUDFLARE_DNS_API_TOKEN_FILE" = config.sops.secrets."keys/cloudflare".path;
|
acceptTerms = true;
|
||||||
|
defaults = {
|
||||||
|
inherit (config.system.mainUser) email;
|
||||||
|
dnsProvider = "cloudflare";
|
||||||
|
credentialFiles = {
|
||||||
|
"CLOUDFLARE_DNS_API_TOKEN_FILE" = config.sops.secrets."keys/cloudflare".path;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
})
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,49 @@
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let
|
let
|
||||||
|
inherit (lib) mkOption mkEnableOption mkIf;
|
||||||
|
inherit (lib.pantheon) mkStrOption;
|
||||||
|
inherit (builtins) listToAttrs map;
|
||||||
|
inherit (config.server.web-servers) enableSSL;
|
||||||
cfg = config.server.web-servers.nginx;
|
cfg = config.server.web-servers.nginx;
|
||||||
|
defaultSink = mkIf cfg.enableDefaultSink {
|
||||||
|
"_" = {
|
||||||
|
default = true;
|
||||||
|
rejectSSL = mkIf enableSSL true;
|
||||||
|
locations."/" = {
|
||||||
|
return = "444";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
proxyPasses = listToAttrs (
|
||||||
|
map (proxy: {
|
||||||
|
name = proxy.source;
|
||||||
|
value = {
|
||||||
|
forceSSL = mkIf enableSSL true;
|
||||||
|
enableACME = mkIf enableSSL true;
|
||||||
|
acmeRoot = mkIf enableSSL null;
|
||||||
|
locations."/" = {
|
||||||
|
proxyPass = proxy.target;
|
||||||
|
} // proxy.extraConfig;
|
||||||
|
};
|
||||||
|
}) cfg.proxies
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.server.web-servers.nginx = {
|
options.server.web-servers.nginx = {
|
||||||
enable = lib.mkEnableOption "the Nginx server";
|
enable = mkEnableOption "the Nginx server";
|
||||||
proxies = lib.mkOption {
|
openFirewall = mkEnableOption "" // {
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
enableDefaultSink = mkEnableOption "" // {
|
||||||
|
default = true;
|
||||||
|
};
|
||||||
|
proxies = mkOption {
|
||||||
type =
|
type =
|
||||||
with lib.types;
|
with lib.types;
|
||||||
listOf (submodule {
|
listOf (submodule {
|
||||||
options = {
|
options = {
|
||||||
source = lib.pantheon.mkStrOption;
|
source = mkStrOption;
|
||||||
target = lib.pantheon.mkStrOption;
|
target = mkStrOption;
|
||||||
extraConfig = lib.mkOption {
|
extraConfig = lib.mkOption {
|
||||||
type = attrs;
|
type = attrs;
|
||||||
default = { };
|
default = { };
|
||||||
|
@ -30,36 +62,14 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
networking.firewall.allowedTCPPorts = [
|
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [
|
||||||
443
|
443
|
||||||
80
|
80
|
||||||
];
|
];
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
||||||
virtualHosts =
|
virtualHosts = defaultSink // proxyPasses;
|
||||||
{
|
|
||||||
"_" = {
|
|
||||||
default = true;
|
|
||||||
rejectSSL = true;
|
|
||||||
locations."/" = {
|
|
||||||
return = "444";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// (builtins.listToAttrs (
|
|
||||||
builtins.map (proxy: {
|
|
||||||
name = proxy.source;
|
|
||||||
value = {
|
|
||||||
forceSSL = true;
|
|
||||||
enableACME = true;
|
|
||||||
acmeRoot = null;
|
|
||||||
locations."/" = {
|
|
||||||
proxyPass = proxy.target;
|
|
||||||
} // proxy.extraConfig;
|
|
||||||
};
|
|
||||||
}) cfg.proxies
|
|
||||||
));
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
hostname = lib.pantheon.mkStrOption;
|
hostname = lib.pantheon.mkStrOption;
|
||||||
mainUser.name = lib.pantheon.mkStrOption;
|
mainUser.name = lib.pantheon.mkStrOption;
|
||||||
mainUser.publicKey = lib.pantheon.mkStrOption;
|
mainUser.publicKey = lib.pantheon.mkStrOption;
|
||||||
|
mainUser.email = lib.pantheon.mkStrOption;
|
||||||
bootloader = lib.pantheon.mkStrOption;
|
bootloader = lib.pantheon.mkStrOption;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
|
imports = lib.singleton ../common.nix;
|
||||||
|
|
||||||
system = {
|
system = {
|
||||||
hostname = "apollo";
|
hostname = "apollo";
|
||||||
mainUser.name = "rafiq";
|
|
||||||
mainUser.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n";
|
|
||||||
bootloader = "systemd-boot";
|
bootloader = "systemd-boot";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
server = {
|
server = {
|
||||||
enableDDNS = true;
|
enableDDNS = true;
|
||||||
mountHelios = true;
|
|
||||||
databases = {
|
databases = {
|
||||||
mongodb.enable = true;
|
mongodb.enable = true;
|
||||||
mysql.enable = true;
|
mysql.enable = true;
|
||||||
|
@ -32,22 +31,25 @@
|
||||||
mattermost.enable = true;
|
mattermost.enable = true;
|
||||||
mattermost.url = "mm.bwfiq.com";
|
mattermost.url = "mm.bwfiq.com";
|
||||||
};
|
};
|
||||||
web-servers.nginx.enable = true;
|
web-servers = {
|
||||||
web-servers.nginx.proxies = [
|
nginx = {
|
||||||
{
|
enable = true;
|
||||||
source = "aenyrathia.wiki";
|
proxies = [
|
||||||
target = "http://helios:5896";
|
{
|
||||||
}
|
source = "aenyrathia.wiki";
|
||||||
{
|
target = "http://helios:5896";
|
||||||
source = "chat.bwfiq.com";
|
}
|
||||||
target = "http://localhost:3080";
|
{
|
||||||
}
|
#TODO: merge into librechat module
|
||||||
{
|
source = "chat.bwfiq.com";
|
||||||
source = "il.bwfiq.com";
|
target = "http://localhost:3080";
|
||||||
target = "http://helios:2283";
|
}
|
||||||
}
|
{
|
||||||
];
|
source = "il.bwfiq.com";
|
||||||
|
target = "http://helios:2283";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
|
||||||
}
|
}
|
||||||
|
|
9
systems/x86_64-linux/common.nix
Normal file
9
systems/x86_64-linux/common.nix
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
system.mainUser = {
|
||||||
|
name = "rafiq";
|
||||||
|
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n";
|
||||||
|
email = "rafiq@rrv.sh";
|
||||||
|
};
|
||||||
|
server.mountHelios = true;
|
||||||
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
|
}
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
system = {
|
system = {
|
||||||
hostname = "mellinoe";
|
hostname = "mellinoe";
|
||||||
mainUser.name = "rafiq";
|
|
||||||
mainUser.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n";
|
|
||||||
bootloader = "systemd-boot";
|
bootloader = "systemd-boot";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,10 +30,4 @@
|
||||||
refresh-rate = "60";
|
refresh-rate = "60";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
server = {
|
|
||||||
mountHelios = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
|
imports = lib.singleton ../common.nix;
|
||||||
|
|
||||||
system = {
|
system = {
|
||||||
hostname = "nemesis";
|
hostname = "nemesis";
|
||||||
mainUser.name = "rafiq";
|
|
||||||
mainUser.publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILdsZyY3gu8IGB8MzMnLdh+ClDxQQ2RYG9rkeetIKq8n";
|
|
||||||
bootloader = "systemd-boot";
|
bootloader = "systemd-boot";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,16 +41,10 @@
|
||||||
enableSunshine = true;
|
enableSunshine = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
server = {
|
|
||||||
mountHelios = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
tor = {
|
tor = {
|
||||||
enable = true;
|
enable = true;
|
||||||
client.enable = true;
|
client.enable = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue