{ pkgs, lib, config, ... }:
let
  cfg = config.mods.server.homebox;
  port = config.mods.server.nginx.ports.homebox;
in with lib; {
  options.mods.server = {
    homebox = {
      enable = mkEnableOption {
        default = false;
        description = "enables homebox server";
      };
      location = mkOption {
        default = "/srv/homebox";
        description = "location for homebox data";
      };
    };
  };

  config = mkIf cfg.enable {
    services.homebox = {
      enable = true;
      settings = {
        HBOX_WEB_PORT = toString port;
        HBOX_WEB_HOST = "0.0.0.0";
        HBOX_OPTIONS_ALLOW_REGISTRATION = "true";
        HBOX_MODE = "production";
      };
    };
  };
}
