blep
This commit is contained in:
parent
1023e50fb9
commit
30fc5a37e3
3 changed files with 30 additions and 13 deletions
|
@ -11,6 +11,17 @@
|
||||||
../../host-secrets.nix
|
../../host-secrets.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
# Enable modules
|
||||||
|
modules.caddy.enable = true;
|
||||||
|
modules.garage.enable = true;
|
||||||
|
|
||||||
|
modules.caddy = {
|
||||||
|
email = "ana@nekomimi.pet";
|
||||||
|
reverseProxies = {
|
||||||
|
"s3.nkp.pet" = ["valefar:3900" "morax:3900"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
system.stateVersion = "25.05";
|
system.stateVersion = "25.05";
|
||||||
|
|
||||||
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
|
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
fsType = "ext4";
|
fsType = "ext4";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fileSystems."/garage" = {
|
||||||
|
device = "/dev/sda1";
|
||||||
|
fsType = "ext4";
|
||||||
|
};
|
||||||
|
|
||||||
swapDevices = [ ];
|
swapDevices = [ ];
|
||||||
|
|
||||||
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
|
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
|
||||||
|
|
|
@ -12,9 +12,13 @@ let
|
||||||
# Generate Caddyfile content from the proxy configuration
|
# Generate Caddyfile content from the proxy configuration
|
||||||
generateCaddyfile = proxies:
|
generateCaddyfile = proxies:
|
||||||
let
|
let
|
||||||
proxyEntries = mapAttrsToList (domain: upstream: ''
|
proxyEntries = mapAttrsToList (domain: upstreams:
|
||||||
|
let
|
||||||
|
upstreamList = if isList upstreams then upstreams else [upstreams];
|
||||||
|
upstreamStr = concatStringsSep " " upstreamList;
|
||||||
|
in ''
|
||||||
${domain} {
|
${domain} {
|
||||||
reverse_proxy ${upstream}
|
reverse_proxy ${upstreamStr}
|
||||||
|
|
||||||
# Optional: Add some common headers for better proxying
|
# Optional: Add some common headers for better proxying
|
||||||
header_up Host {upstream_hostport}
|
header_up Host {upstream_hostport}
|
||||||
|
@ -33,25 +37,23 @@ in
|
||||||
caddy = {
|
caddy = {
|
||||||
enable = mkEnableOption "Deploy Caddy";
|
enable = mkEnableOption "Deploy Caddy";
|
||||||
|
|
||||||
# New option for reverse proxy configuration
|
|
||||||
reverseProxies = mkOption {
|
reverseProxies = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.attrsOf (types.either types.str (types.listOf types.str));
|
||||||
default = {};
|
default = {};
|
||||||
description = "Attribute set of domain to upstream mappings for reverse proxying";
|
description = "Attribute set of domain to upstream mappings for reverse proxying. Upstreams can be a single string or a list of strings for load balancing.";
|
||||||
example = {
|
example = {
|
||||||
"notes.nekomimi.pet" = "valefar:3009";
|
"notes.nekomimi.pet" = "valefar:3009";
|
||||||
"git.nekomimi.pet" = "morax:3000";
|
"git.nekomimi.pet" = ["morax:3000" "valefar:3000"]; # Load balance between multiple upstreams
|
||||||
|
"api.nekomimi.pet" = ["server1:8080" "server2:8080" "server3:8080"];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Optional: Allow custom Caddyfile content to be appended
|
|
||||||
extraConfig = mkOption {
|
extraConfig = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
description = "Extra Caddyfile configuration to append";
|
description = "Extra Caddyfile configuration to append";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Optional: Email for ACME/Let's Encrypt
|
|
||||||
email = mkOption {
|
email = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
default = null;
|
default = null;
|
||||||
|
@ -64,7 +66,7 @@ in
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
# Allow network access when building
|
# Allow network access when building
|
||||||
# https://mdleom.com/blog/2021/12/27/caddy-plugins-nixos/#xcaddy
|
# https://mdleom.com/blog/2021/12/27/caddy-plugins-nixos/#xcaddy
|
||||||
nix.settings.sandbox = false;
|
#nix.settings.sandbox = false;
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [
|
networking.firewall.allowedTCPPorts = [
|
||||||
80
|
80
|
||||||
|
@ -74,12 +76,11 @@ in
|
||||||
|
|
||||||
services.caddy = {
|
services.caddy = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.caddy.withPlugins {
|
/*package = pkgs.caddy.withPlugins {
|
||||||
plugins = [ "github.com/caddy-dns/cloudflare"];
|
plugins = [ "github.com/caddy-dns/cloudflare@v0.2.1"];
|
||||||
hash = "sha256-1niaf801sijvjrqvw998y8x7b43a0g162h3ry530qwl8lrgkapii";
|
hash = "sha256-1niaf801sijvjrqvw998y8x7b43a0g162h3ry530qwl8lrgkapii";
|
||||||
};
|
};*/
|
||||||
|
|
||||||
# Generate the Caddyfile from our configuration
|
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
${optionalString (cfg.email != null) ''
|
${optionalString (cfg.email != null) ''
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue