{
  config,
  lib,
  ...
}: let
  cfg = config.services.keikos.web;
in {
  options.services.keikos.web = with lib;
  with lib.types; {
    enable = mkEnableOption "";
    port = mkOption {
      type = port;
      default = 7331;
    };
    package = mkOption {
      type = package;
      default = config._keikos-flake.pkg;
    };
    user = mkOption {
      type = str;
      default = "keikoswork";
    };
    group = mkOption {
      type = str;
      default = "keikoswork";
    };
  };
  config = with lib;
    mkIf cfg.enable {
      systemd.services."keikoswork" = {
        after = ["network.target"];
        wantedBy = ["multi-user.target"];
        serviceConfig = {
          Type = "simple";
          User = cfg.user;
          Group = cfg.group;
          ExecStart = "${lib.escapeShellArg (lib.getExe cfg.package)} web -port ${toString cfg.port}";
          Restart = "on-success";
        };
      };

      users.users."${cfg.user}" = {
        isSystemUser = true;
        group = cfg.group;
      };
      users.groups."${cfg.group}" = {};
    };
}
