# Auto-generated using compose2nix v0.3.2-pre.
{ pkgs, lib, config, ... }:
let cfg = config.mods.server.vrising;
in with lib; {
  options.mods.server.vrising = {
    enable = mkEnableOption {
      default = false;
      description = "enables docker containers";
    };
  };

  config = mkIf cfg.enable {
    # Runtime
    virtualisation.podman = {
      enable = true;
      autoPrune.enable = true;
      dockerCompat = true;
      defaultNetwork.settings = {
        # Required for container networking to be able to use names.
        dns_enabled = true;
      };
    };

    # Enable container name DNS for non-default Podman networks.
    # https://github.com/NixOS/nixpkgs/issues/226365
    networking.firewall.interfaces."podman+".allowedUDPPorts = [ 53 ];
    networking.firewall.allowedUDPPorts = [ 9876 9877 ];

    virtualisation.oci-containers.backend = "podman";

    # Containers
    virtualisation.oci-containers.containers."vrising-vrising" = {
      image = "trueosiris/vrising";
      environment = { "SERVERNAME" = "yapping at the succ"; };
      volumes = [
        "/srv/vrising/persistentdata:/mnt/vrising/persistentdata:rw"
        "/srv/vrising/server:/mnt/vrising/server:rw"
      ];
      ports = [ "0.0.0.0:9876:9876/udp" "0.0.0.0:9877:9877/udp" ];
      log-driver = "journald";
      extraOptions = [ ];
    };
    systemd.services."podman-vrising-vrising" = {
      serviceConfig = { Restart = lib.mkOverride 90 "always"; };
      partOf = [ "podman-compose-vrising-root.target" ];
      wantedBy = [ "podman-compose-vrising-root.target" ];
    };

    # Root service
    # When started, this will automatically create all resources and start
    # the containers. When stopped, this will teardown all resources.
    systemd.targets."podman-compose-vrising-root" = {
      unitConfig = { Description = "Root target generated by compose2nix."; };
      wantedBy = [ "multi-user.target" ];
    };
  };
}
