# Auto-generated using compose2nix v0.3.1.
{
  config,
  lib,
  pkgs,
  ...
}:
let
  env = config.secretsSpec.docker.filerun;
in
{
  # Runtime
  virtualisation.docker = {
    enable = true;
    autoPrune.enable = true;
  };
  virtualisation.oci-containers.backend = "docker";

  # Containers
  virtualisation.oci-containers.containers."filerun-db" = {
    image = "mariadb:10.11";
    environment = env;
    volumes = [
      "/pool/filerun/db:/var/lib/mysql:rw"
    ];
    user = "1001:1004";
    log-driver = "journald";
    extraOptions = [
      "--network-alias=db"
      "--network=filerun_default"
    ];
  };
  systemd.services."docker-filerun-db" = {
    serviceConfig = {
      Restart = lib.mkOverride 90 "always";
      RestartMaxDelaySec = lib.mkOverride 90 "1m";
      RestartSec = lib.mkOverride 90 "100ms";
      RestartSteps = lib.mkOverride 90 9;
    };
    after = [
      "docker-network-filerun_default.service"
    ];
    requires = [
      "docker-network-filerun_default.service"
    ];
    partOf = [
      "docker-compose-filerun-root.target"
    ];
    wantedBy = [
      "docker-compose-filerun-root.target"
    ];
  };
  virtualisation.oci-containers.containers."filerun-web" = {
    image = "filerun/filerun:8.1";
    environment = env;
    volumes = [
      "/pool/:/pool:rw"
      "/pool/filerun/html:/var/www/html:rw"
      "/pool/filerun/user-files:/user-files:rw"
    ];
    ports = [
      "8181:80/tcp"
    ];
    dependsOn = [
      "filerun-db"
    ];
    user = "root";
    log-driver = "journald";
    extraOptions = [
      "--network-alias=web"
      "--network=filerun_default"
    ];
  };
  systemd.services."docker-filerun-web" = {
    serviceConfig = {
      Restart = lib.mkOverride 90 "always";
      RestartMaxDelaySec = lib.mkOverride 90 "1m";
      RestartSec = lib.mkOverride 90 "100ms";
      RestartSteps = lib.mkOverride 90 9;
    };
    after = [
      "docker-network-filerun_default.service"
    ];
    requires = [
      "docker-network-filerun_default.service"
    ];
    partOf = [
      "docker-compose-filerun-root.target"
    ];
    wantedBy = [
      "docker-compose-filerun-root.target"
    ];
  };

  # Networks
  systemd.services."docker-network-filerun_default" = {
    path = [ pkgs.docker ];
    serviceConfig = {
      Type = "oneshot";
      RemainAfterExit = true;
      ExecStop = "docker network rm -f filerun_default";
    };
    script = ''
      docker network inspect filerun_default || docker network create filerun_default
    '';
    partOf = [ "docker-compose-filerun-root.target" ];
    wantedBy = [ "docker-compose-filerun-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."docker-compose-filerun-root" = {
    unitConfig = {
      Description = "Root target generated by compose2nix.";
    };
    wantedBy = [ "multi-user.target" ];
  };
}
