{
  config,
  lib,
  namespace,
  ...
}:
with lib;
let
  name = "restic";
  cfg = config.${namespace}.services.${name};

  resticConfig = lib.${namespace}.mkModule {
    inherit config name;
    serviceName = "${name}-rest-server";
    description = "restic";
    options = { };
    moduleConfig = {
      # Configure the standard NixOS restic server service
      services.restic.server = {
        enable = true;
        dataDir = "${cfg.dataDir}/backup/restic";
        prometheus = true;
        listenAddress = "${cfg.listenAddress}:${toString cfg.port}";
        htpasswd-file = "${cfg.dataDir}/backup/restic/.htpasswd";
        extraFlags = [ "--no-auth" ];
      };
    };
  };
in
{
  imports = [ resticConfig ];
}
