{ outputs, lib, config, ... }: {
  imports = [
    outputs.nixosModules.plex-exporter
  ];

  sops.secrets.plex_token = {
    sopsFile = ../../../secrets/plex/default.yaml;
  };

  sops.templates."plex-exporter-config.yaml" = {
    content = lib.strings.toJSON {
      token = config.sops.placeholder.plex_token;
      servers = [
        {
          baseUrl = "https://localhost:32400";
          insecure = true;
        }
      ];
    };
    owner = "nobody";
  };

  services.plex-exporter = {
    enable = true;
    listenAddress = ":14220";
    configFile = config.sops.templates."plex-exporter-config.yaml".path;
  };

  networking.firewall.allowedTCPPorts = [ 14220 ];
}
