{ pkgs, lib, config, ... }:
let cfg = config.mods.server;
in with lib; {
  imports = [ ./service.nix ];

  options.mods.server = {
    grav = {
      enable = mkEnableOption {
        default = false;
        description = "enables grav service";
      };
      location = mkOption {
        default = "/srv/grav";
        description = "location for homebox data";
      };
    };
  };

  config = let port = 5001;
  in {
    networking.firewall = { allowedTCPPorts = [ port ]; };
    mods.services.grav = mkIf cfg.grav.enable {
      inherit port;
      enable = true;
      root = cfg.grav.location;
      phpPackage = pkgs.php81;
    };
    users.users.${config.mods.user.name}.extraGroups = lib.mkAfter [ "grav" ];
  };
}
