depot/ops/nixos/lib/fup.nix

77 lines
2 KiB
Nix
Raw Permalink Normal View History

{ 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]" ];
};
};
2024-10-20 16:21:54 +00:00
config = {
my.vault.acmeCertificates."p.lukegb.com" = {
hostnames = [ "p.lukegb.com" ];
2024-10-20 16:21:54 +00:00
caddyVirtualHosts = [ "p.lukegb.com" ];
2021-03-22 02:43:17 +00:00
};
2024-10-20 16:21:54 +00:00
services.caddy = {
2021-03-22 02:43:17 +00:00
virtualHosts."p.lukegb.com" = {
2024-10-20 16:21:54 +00:00
extraConfig = ''
${lib.optionalString (config.my.fup.listen != []) "bind ${lib.concatStringsSep " " config.my.fup.listen}"}
reverse_proxy unix/${sock}
'';
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 = {
2024-10-20 16:21:54 +00:00
SocketUser = config.services.caddy.user;
SocketGroup = config.services.caddy.group;
2021-03-22 02:43:17 +00:00
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
};
}