2021-03-23 00:58:18 +00:00
|
|
|
{ config, options, depot, lib, pkgs, ... }:
|
2021-03-22 02:43:17 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (depot.ops) secrets;
|
|
|
|
sock = "/run/fup.sock";
|
|
|
|
pkg = depot.web.fup;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = with lib; {
|
|
|
|
my.fup.listen = lib.mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ "127.0.0.1" "[::1]" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = let
|
|
|
|
nginxListen = (map (addr: {
|
|
|
|
inherit addr;
|
|
|
|
port = 80;
|
|
|
|
ssl = false;
|
|
|
|
}) config.my.fup.listen) ++ (map (addr: {
|
|
|
|
inherit addr;
|
|
|
|
port = 443;
|
|
|
|
ssl = true;
|
|
|
|
}) config.my.fup.listen);
|
|
|
|
in {
|
2022-03-07 00:52:03 +00:00
|
|
|
my.vault.acmeCertificates."p.lukegb.com" = {
|
2022-03-17 23:31:55 +00:00
|
|
|
hostnames = [ "p.lukegb.com" ];
|
2022-03-07 00:52:03 +00:00
|
|
|
nginxVirtualHosts = [ "p.lukegb.com" ];
|
2021-03-22 02:43:17 +00:00
|
|
|
};
|
|
|
|
services.nginx = {
|
|
|
|
enable = lib.mkDefault true;
|
|
|
|
virtualHosts."p.lukegb.com" = {
|
|
|
|
listen = nginxListen;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://unix:${sock}";
|
2021-03-22 13:56:16 +00:00
|
|
|
extraConfig = ''
|
|
|
|
proxy_redirect off;
|
|
|
|
client_max_body_size 0;
|
|
|
|
proxy_buffering off;
|
|
|
|
'';
|
2021-03-22 02:43:17 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-10 00:37:37 +00:00
|
|
|
users.users.fup = { isSystemUser = true; group = "fup"; };
|
|
|
|
users.groups.fup = {};
|
|
|
|
|
2021-03-22 02:43:17 +00:00
|
|
|
systemd.sockets.fup = {
|
|
|
|
listenStreams = [ sock ];
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
socketConfig = {
|
|
|
|
SocketUser = config.services.nginx.user;
|
|
|
|
SocketGroup = config.services.nginx.group;
|
|
|
|
SocketMode = "0700";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.fup = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "network.target" ];
|
|
|
|
after = [ "network.target" "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
Restart = "always";
|
2022-04-10 00:37:37 +00:00
|
|
|
EnvironmentFile = config.my.vault.secrets.fup-environment.path;
|
|
|
|
ExecStart = "${pkg}/bin/fup serve --config=/etc/fup.yaml";
|
|
|
|
User = "fup";
|
2021-03-22 02:43:17 +00:00
|
|
|
};
|
|
|
|
};
|
2022-04-10 00:37:37 +00:00
|
|
|
environment.etc."fup.yaml".source = config.my.vault.secrets.fup-config.path;
|
|
|
|
my.vault.secrets.fup-config = {
|
|
|
|
reloadOrRestartUnits = ["fup.service"];
|
|
|
|
group = "fup";
|
|
|
|
template = ''
|
|
|
|
{{ with secret "kv/apps/fup" }}
|
|
|
|
{{ .Data.data.config }}
|
|
|
|
{{ end }}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
my.vault.secrets.fup-environment = {
|
|
|
|
reloadOrRestartUnits = ["fup.service"];
|
|
|
|
group = "fup";
|
|
|
|
template = ''
|
|
|
|
{{ with secret "kv/apps/fup" }}
|
|
|
|
{{ .Data.data.environment }}
|
|
|
|
{{ end }}
|
|
|
|
'';
|
|
|
|
};
|
2021-03-22 02:43:17 +00:00
|
|
|
};
|
|
|
|
}
|