{ depot, pkgs, lib, ... }:

let
  bins = depot.nix.getBins pkgs.alacritty [ "alacritty" ]
    // depot.nix.getBins pkgs.coreutils [ "mkdir" "cp" "install" ];

  # https://github.com/alacritty/alacritty-theme
  themes = {
    # dark = "alacritty_0_12";
    dark = "google";
    light = "dayfox";
  };

  config =
    {
      config = {
        # sets the theme for this config (autogenerated file)
        general.import = [ "~/.config/alacritty/alacritty-colors-autogen.toml" ];
        font.size = 18;
        scrolling.history = 100000;
      };
      #  This disables the dpi-sensitive scaling (cause otherwise the font will be humongous on my laptop screen)
      alacritty-env.WINIT_X11_SCALE_FACTOR = 1;
    };

  alacritty = depot.nix.writeExecline "alacritty" { } (
    (lib.concatLists (lib.mapAttrsToList (k: v: [ "export" k (toString v) ]) config.alacritty-env))
    ++ [
      "backtick"
      "-E"
      "config"
      [ depot.users.Profpatsch.xdg-config-home ]

      bins.alacritty
      "--config-file"
      ((pkgs.formats.toml { }).generate "alacritty.conf" config.config)
      "$@"
    ]
  );

  alacritty-themes-upstream = pkgs.fetchFromGitHub {
    owner = "alacritty";
    repo = "alacritty-theme";
    rev = "95a7d695605863ede5b7430eb80d9e80f5f504bc";
    sha256 = "sha256-D37MQtNS20ESny5UhW1u6ELo9czP4l+q0S8neH7Wdbc=";
  };

  alacritty-themes-modes-ef = pkgs.fetchFromGitHub {
    owner = "anhsirk0";
    repo = "alacritty-themes";
    rev = "5a2c194a682ec75d46553f9a9d6c43fbf39c689d";
    sha256 = "sha256-x5QrtSXNc05DNexM+ZtRzd8T9FdthZUzjW/2uEBdRCk=";
  };

  alacritty-themes = depot.nix.runExecline "alacritty-themes-merged" { } [
    "importas"
    "out"
    "out"
    "if"
    [ bins.mkdir "-p" "$\{out}/themes" ]
    "if"
    [
      "elglob"
      "-0"
      "themes"
      "${alacritty-themes-upstream}/themes/*"
      bins.install
      "-m644"
      "-t"
      "\${out}/themes"
      "$themes"
    ]
    "if"
    [
      "elglob"
      "-0"
      "themes"
      "${alacritty-themes-modes-ef}/themes/*"
      bins.install
      "-m644"
      "-t"
      "\${out}/themes"
      "$themes"
    ]
  ];
in
{
  inherit
    alacritty
    alacritty-themes
    themes;

}
