{
  config,
  inputs,
  lib,
  pkgs,
  ...
}:

let
  weddingPackage =
    if inputs.wedding ? packages then
      inputs.wedding.packages.${pkgs.system}.default
    else
      pkgs.buildGoModule {
        pname = "wedding";
        version = "source";
        src = inputs.wedding;
        subPackages = [ "internal/cmd/app" ];
        vendorHash = "sha256-rxaikaR4UGXu2hIuR9ZbOnITBsCq5zEDAlwrhhRudoo=";
        env = {
          CGO_ENABLED = 0;
        };
        ldflags = [
          "-s"
          "-w"
        ];
        postInstall = ''
          mkdir -p $out/share/wedding
          cp -r public $out/share/wedding/public
        '';
      };
in
{
  options.wedding = {
    enable = lib.mkEnableOption "Wedding site";
  };

  config = lib.mkIf config.wedding.enable {
    sops.secrets.gotify_password = { };

    systemd.services.wedding = {
      description = "Wedding site";
      wantedBy = [ "multi-user.target" ];
      after = [ "network-online.target" ];
      wants = [ "network-online.target" ];
      serviceConfig = {
        ExecStart = "${weddingPackage}/bin/app";
        Restart = "on-failure";
        DynamicUser = true;
        WorkingDirectory = "${weddingPackage}/share/wedding";
        Environment = [
          "PUBLIC_DIR=${weddingPackage}/share/wedding/public"
          "GOTIFY_URL=https://message.wastring.com"
		  "GOTIFY_TOKEN=AxlVMOKqqoohYxC"
          "HTTP_ADDR=0.0.0.0:8083"
          "PORT=8083"
        ];
      };
    };

    services.nginx = {
      virtualHosts."wedding.wastring.com" = {
        enableACME = true;
        forceSSL = true;
        locations."/" = {
          proxyPass = "http://localhost:8083";
          proxyWebsockets = true;
        };
      };
    };
  };
}
