{config, ...}: let
  vars = import ../../../../vars.nix;
in {
  virtualisation.arion = {
    projects.stats.settings = {
      imports = [./arion-compose.nix];
    };
  };

  systemd.services.add-loki-logging-driver = {
    description = "Add grafana loki docker driver";
    after = ["network.target"];
    wantedBy = ["multi-user.target"];

    serviceConfig.Type = "oneshot";
    script = let
      dockercli = "${config.virtualisation.docker.package}/bin/docker";
    in ''
      # Put a true at the end to prevent getting non-zero return code, which will
      # crash the whole service.
      check=$(${dockercli} plugin ls | grep "loki" || true)
      if [ -z "$check" ]; then
        ${dockercli} plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
      else
        echo "loki docker driver already exists in docker"
      fi
    '';
  };

  virtualisation.docker.daemon.settings = {
    debug = true;
    log-driver = "loki";
    log-opts = {
      loki-url = "http://localhost:3100/loki/api/v1/push";
      # loki-url = "http://host.docker.internal:3100/loki/api/v1/push";
    };
  };
}