{ pkgs, lib, config, ... }:
let
  cfg = config.mods.server.share;
  port = config.mods.server.nginx.ports.share;
in with lib; {
  options.mods.server = {
    share = {
      enable = mkEnableOption {
        default = false;
        description = "enables zipline server";
      };
    };
  };

  config = mkIf cfg.enable {
    users.groups.zipline = { };
    users.users.zipline = {
      isSystemUser = true;
      group = "zipline";
    };
    services.zipline = {
      enable = true;
      settings = {
        CORE_HOST = "0.0.0.0";
        CORE_PORT = port;
      };
      environmentFiles = [ "/run/secrets/zipline-secret" ];
    };
  };
}
