Unverified Commit 8e0f9052 authored by h7x4's avatar h7x4 Committed by GitHub
Browse files

Merge pull request #322051 from khaneliman/saf

sketchybar-app-font: build from source
parents eeda342e da53b161
Loading
Loading
Loading
Loading
+49 −77
Original line number Diff line number Diff line
let
  artifacts = [ "shell" "lua" "font" ];
in
{ lib
, stdenvNoCC
, fetchurl
, common-updater-scripts
, curl
, jq
, writeShellScript
, artifactList ? artifacts
}:
lib.checkListOfEnum "sketchybar-app-font: artifacts" artifacts artifactList
  stdenvNoCC.mkDerivation
  (finalAttrs:
  let
    selectedSources = map (artifact: builtins.getAttr artifact finalAttrs.passthru.sources) artifactList;
  in
{
  fetchFromGitHub,
  lib,
  pnpm,
  stdenvNoCC,
  nodejs,
  nix-update-script,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "sketchybar-app-font";
  version = "2.0.19";

    srcs = selectedSources;
  src = fetchFromGitHub {
    owner = "kvndrsslr";
    repo = "sketchybar-app-font";
    rev = "v2.0.19";
    hash = "sha256-4D3ONeGSvFYdeD3alzXlDxyLh6EyIC+lr4A6t7YWBaw=";
  };

  pnpmDeps = pnpm.fetchDeps {
    inherit (finalAttrs) pname version src;
    hash = "sha256-u0Rr086p6gotS+p9365+P8uKEqxDNGnWCsZDCaj8eEE=";
  };

  nativeBuildInputs = [
    nodejs
    pnpm.configHook
  ];

    unpackPhase = ''
      runHook preUnpack
  buildPhase = ''
    runHook preBuild

      for s in $selectedSources; do
        b=$(basename $s)
        cp $s ''${b#*-}
      done
    pnpm i
    pnpm run build

      runHook postUnpack
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    '' + lib.optionalString (lib.elem "font" artifactList) ''
      install -Dm644 ${finalAttrs.passthru.sources.font} "$out/share/fonts/truetype/sketchybar-app-font.ttf"

    '' + lib.optionalString (lib.elem "shell" artifactList) ''
      install -Dm755 ${finalAttrs.passthru.sources.shell} "$out/bin/icon_map.sh"

    '' + lib.optionalString (lib.elem "lua" artifactList) ''
      install -Dm644 ${finalAttrs.passthru.sources.lua} "$out/lib/sketchybar-app-font/icon_map.lua"
    install -Dm644 dist/sketchybar-app-font.ttf "$out/share/fonts/truetype/sketchybar-app-font.ttf"
    install -Dm755 dist/icon_map.sh "$out/bin/icon_map.sh"
    install -Dm644 dist/icon_map.lua "$out/lib/sketchybar-app-font/icon_map.lua"

    runHook postInstall
  '';

    passthru = {
      sources = {
        font = fetchurl {
          url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${finalAttrs.version}/sketchybar-app-font.ttf";
          hash = "sha256-AH4Zkaccms1gNt7ZHZRHYPOx/iLpbcA4MiyBStHRDfU=";
        };
        lua = fetchurl {
          url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${finalAttrs.version}/icon_map.lua";
          hash = "sha256-AGcHBgOZY2EBR0WEfaQhEsTRdo8QfEawx6Q2rdBuKIg=";
        };
        shell = fetchurl {
          url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${finalAttrs.version}/icon_map.sh";
          hash = "sha256-fdKnweYF92zCLVBVXTjLWK9vdzMD8FvOHjEo2vqPbhQ=";
        };
      };

      updateScript = writeShellScript "update-sketchybar-app-font" ''
        set -o errexit
        export PATH="${lib.makeBinPath [ curl jq common-updater-scripts ]}"
        NEW_VERSION=$(curl --silent https://api.github.com/repos/kvndrsslr/sketchybar-app-font/releases/latest | jq '.tag_name | ltrimstr("v")' --raw-output)
        if [[ "${finalAttrs.version}" = "$NEW_VERSION" ]]; then
            echo "The new version same as the old version."
            exit 0
        fi
        for artifact in ${lib.escapeShellArgs (lib.mapAttrsToList(a: _: a) finalAttrs.passthru.sources)}; do
          update-source-version "sketchybar-app-font" "$NEW_VERSION" --ignore-same-version --source-key="sources.$artifact"
        done
      '';
    };
  passthru.updateScript = nix-update-script { };

  meta = {
    description = "Ligature-based symbol font and a mapping function for sketchybar";
@@ -86,5 +57,6 @@ lib.checkListOfEnum "sketchybar-app-font: artifacts" artifacts artifactList
    homepage = "https://github.com/kvndrsslr/sketchybar-app-font";
    license = lib.licenses.cc0;
    maintainers = with lib.maintainers; [ khaneliman ];
    platforms = lib.platforms.all;
  };
})