{ pkgs, ... }:
let
  wantedSans = pkgs.stdenvNoCC.mkDerivation {
    pname = "wanted-sans";
    version = "1.0.3";

    src = pkgs.fetchzip {
      url = "https://github.com/wanteddev/wanted-sans/releases/download/v1.0.3/WantedSans-1.0.3.zip";
      hash = "sha256-uksJ7Qmwv0kQw/mXyI179XaFHGMI8fuumcitD/XpA/w=";
      stripRoot = false;
    };

    installPhase = ''
      runHook preInstall
      install -Dm644 variable/*.ttf -t $out/share/fonts/truetype
      install -Dm644 otf/*.otf -t $out/share/fonts/opentype
      runHook postInstall
    '';
  };

  suit-font = pkgs.stdenvNoCC.mkDerivation {
    pname = "suit-font";
    version = "v2.0.5";

    # name을 다르게 지정하여 unpack 시 충돌을 방지합니다.
    srcs = [
      (pkgs.fetchzip {
        name = "suit-variable";
        url = "https://github.com/sun-typeface/SUIT/releases/download/v2.0.5/SUIT-Variable-ttf.zip";
        hash = "sha256-oRZGxT/v6jBa5cOsYWG8qHfdPIRBqPAyt6hjfBTD1jo=";
        stripRoot = false;
      })
      (pkgs.fetchzip {
        name = "suit-static";
        url = "https://github.com/sun-typeface/SUIT/releases/download/v2.0.5/SUIT-otf.zip";
        hash = "sha256-YDyBKU5P+tlMsK4L2dEn6ibOo6UxDK2B507rm/zy2FA=";
        stripRoot = false;
      })
    ];

    sourceRoot = ".";

    installPhase = ''
      runHook preInstall
      mkdir -p $out/share/fonts/truetype $out/share/fonts/opentype

      # 각 소스가 suit-variable, suit-static 디렉토리에 풀려 있으므로 전체 탐색하여 복사
      find . -name "__MACOSX" -prune -o -name "*.ttf" -exec cp {} $out/share/fonts/truetype/ \;
      find . -name "__MACOSX" -prune -o -name "*.otf" -exec cp {} $out/share/fonts/opentype/ \;

      runHook postInstall
    '';
  };
in
{
  fonts = {
    packages = with pkgs; [
      liberation_ttf
      fira-code
      fira-code-symbols
      dejavu_fonts
      pretendard
      pretendard-jp
      nanum-gothic-coding
      nerd-fonts.jetbrains-mono
      wantedSans
      suit-font
    ];
  };
}
