golgi/modules/caddy.nix

117 lines
3.2 KiB
Nix
Raw Permalink Normal View History

2024-01-09 16:55:19 +00:00
{ config, lib, pkgs, ... }:
2022-08-05 12:29:25 +00:00
with lib;
2022-07-29 17:25:12 +00:00
2024-02-16 17:30:32 +00:00
let
domain = "tecosaur.net";
in {
networking.firewall.allowedTCPPorts = [ 80 443 ];
networking.firewall.allowedUDPPorts = [ 443 ];
2022-07-29 17:25:12 +00:00
2022-08-05 12:29:25 +00:00
services.caddy = mkMerge [
{
enable = true;
2024-01-09 16:55:19 +00:00
package = pkgs.callPackage ../packages/caddy.nix {
externalPlugins = [
{name = "caddy-fs-git"; repo = "github.com/tecosaur/caddy-fs-git";
version = "ef9d0ab232f4fe5d7e86312cbba45ff8afea98a1";}
2024-01-09 16:55:19 +00:00
];
};
2024-02-16 17:30:32 +00:00
virtualHosts."${domain}".extraConfig = ''
2022-08-14 07:34:09 +00:00
respond "__ __ _
\ \ / /__| | ___ ___ _ __ ___ ___
\ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \
\ V V / __/ | (_| (_) | | | | | | __/
\_/\_/ \___|_|\___\___/|_| |_| |_|\___|
This is an in-progress replacement for tecosaur.com, done better.
2024-02-16 17:30:32 +00:00
For now, you can find an increasing number of my projects on code.${domain},
2022-08-14 07:34:09 +00:00
this includes the setup for this server, which is being constructed using:
+ NixOS (with flakes and deploy-rs)
+ Caddy (web server)
2023-06-24 05:16:32 +00:00
+ Forgejo (personal software forge)
+ Syncthing (cross-device folder sync tool)
2022-08-14 07:34:09 +00:00
2022-09-20 01:27:10 +00:00
In future, the following may be set up too:
2022-08-14 07:34:09 +00:00
+ Dendrite/Conduit (Matrix servers)
+ My TMiO blog
+ Kopia (backups)
+ Koel (music streaming)
"
2024-01-09 18:25:18 +00:00
'';
2024-02-16 17:30:32 +00:00
virtualHosts."blog.${domain}".extraConfig = ''
2024-01-09 18:25:18 +00:00
redir /tmio /tmio/
handle_path /tmio/* {
file_server {
fs git ${config.services.forgejo.stateDir}/repositories/tec/this-month-in-org.git html
2024-01-09 18:25:18 +00:00
}
}
handle {
respond 404
}
2022-07-29 17:25:12 +00:00
'';
2022-08-05 12:29:25 +00:00
}
2023-12-10 17:23:29 +00:00
(mkIf config.services.syncthing.enable {
2024-02-16 17:30:32 +00:00
virtualHosts."syncthing.${domain}".extraConfig =
''
reverse_proxy ${config.services.syncthing.guiAddress} {
header_up Host {upstream_hostport}
}
'';
})
(mkIf config.services.syncthing.enable {
2024-02-16 17:30:32 +00:00
virtualHosts."public.${domain}".extraConfig =
''
root * ${config.services.syncthing.dataDir}/public/.build
file_server
'';
2023-12-10 17:23:29 +00:00
})
(mkIf config.services.forgejo.enable {
2024-02-16 17:30:32 +00:00
virtualHosts."git.tecosaur.net".extraConfig = "redir https://code.${domain}{uri} 301";
2024-02-16 17:27:56 +00:00
})
(mkIf config.services.forgejo.enable {
2024-02-16 17:30:32 +00:00
virtualHosts."code.${domain}".extraConfig =
''
@not_tec {
not path /tec/*
not header Cookie *caddy_tec_redirect=true*
}
handle @not_tec {
reverse_proxy localhost:${toString config.services.forgejo.settings.server.HTTP_PORT} {
@404 status 404
handle_response @404 {
header +Set-Cookie "caddy_tec_redirect=true; Max-Age=5"
redir * /tec{uri}
}
}
}
@tec_redirect {
path /tec/*
header Cookie *caddy_tec_redirect=true*
}
handle @tec_redirect {
reverse_proxy localhost:${toString config.services.forgejo.settings.server.HTTP_PORT} {
@404 status 404
handle_response @404 {
header +Set-Cookie "caddy_tec_redirect=true; Max-Age=0"
handle_path /tec/* {
redir * {uri}
}
}
}
}
handle {
reverse_proxy localhost:${toString config.services.forgejo.settings.server.HTTP_PORT}
}
'';
2022-08-05 12:29:25 +00:00
})
];
2024-01-09 18:25:18 +00:00
users.users.caddy = {
extraGroups =
lib.optional config.services.syncthing.enable config.services.syncthing.user ++
lib.optional config.services.forgejo.enable config.services.forgejo.user;
2024-01-09 18:25:18 +00:00
};
2022-07-29 17:25:12 +00:00
}