about summary refs log tree commit diff
path: root/pkgs/data
diff options
context:
space:
mode:
authorAustin Horstman <khaneliman12@gmail.com>2024-03-27 14:09:50 -0500
committerAustin Horstman <khaneliman12@gmail.com>2024-04-05 20:27:39 -0500
commit4a99c31cd1cbd4ff4f84371d4d36ec606e461670 (patch)
tree8b05f1bb9370fcb6411999e2bf98c91ded959004 /pkgs/data
parent2f21ef168393c9398a4485f4d5234cf017a55db4 (diff)
sketchybar-app-font: add meta.passthru.updateScript
Diffstat (limited to 'pkgs/data')
-rw-r--r--pkgs/data/fonts/sketchybar-app-font/default.nix122
1 files changed, 73 insertions, 49 deletions
diff --git a/pkgs/data/fonts/sketchybar-app-font/default.nix b/pkgs/data/fonts/sketchybar-app-font/default.nix
index a06f8dde820b9..0acd401462be1 100644
--- a/pkgs/data/fonts/sketchybar-app-font/default.nix
+++ b/pkgs/data/fonts/sketchybar-app-font/default.nix
@@ -4,64 +4,88 @@ in
 { lib
 , stdenvNoCC
 , fetchurl
+, common-updater-scripts
+, curl
+, jq
+, writeShellScript
 , artifactList ? artifacts
 }:
-let
-  pname = "sketchybar-app-font";
-  version = "2.0.15";
-
-  selectedSources = map (themeName: builtins.getAttr themeName sources) artifactList;
-  sources = {
-    font = fetchurl {
-      url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${version}/sketchybar-app-font.ttf";
-      hash = "sha256-s1mnoHEozmDNsW0P4z97fupAVElxikia0TYLVHJPAM4=";
-    };
-    lua = fetchurl {
-      url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${version}/icon_map.lua";
-      hash = "sha256-YLr7dlKliKLUEK18uG4ouXfLqodVpcDQzfu+H1+oe/w=";
-    };
-    shell = fetchurl {
-      url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${version}/icon_map.sh";
-      hash = "sha256-ZT/k6Vk/nO6mq1yplXaWyz9HxqwEiVWba+rk+pIRZq4=";
-    };
-  };
-in
-lib.checkListOfEnum "${pname}: artifacts" artifacts artifactList
+lib.checkListOfEnum "sketchybar-app-font: artifacts" artifacts artifactList
   stdenvNoCC.mkDerivation
-{
-  inherit pname version;
+  (finalAttrs:
+  let
+    selectedSources = map (artifact: builtins.getAttr artifact finalAttrs.passthru.sources) artifactList;
+  in
+  {
+    pname = "sketchybar-app-font";
+    version = "2.0.15";
 
-  srcs = selectedSources;
+    srcs = selectedSources;
 
-  unpackPhase = ''
-    for s in $selectedSources; do
-      b=$(basename $s)
-      cp $s ''${b#*-}
-    done
-  '';
+    unpackPhase = ''
+      runHook preUnpack
 
-  installPhase = ''
-    runHook preInstall
+      for s in $selectedSources; do
+        b=$(basename $s)
+        cp $s ''${b#*-}
+      done
 
-  '' + lib.optionalString (lib.elem "font" artifactList) ''
-    install -Dm644 ${sources.font} "$out/share/fonts/truetype/sketchybar-app-font.ttf"
+      runHook postUnpack
+    '';
 
-  '' + lib.optionalString (lib.elem "shell" artifactList) ''
-    install -Dm755 ${sources.shell} "$out/bin/icon_map.sh"
+    installPhase = ''
+      runHook preInstall
 
-  '' + lib.optionalString (lib.elem "lua" artifactList) ''
-    install -Dm644 ${sources.lua} "$out/lib/${pname}/icon_map.lua"
+    '' + lib.optionalString (lib.elem "font" artifactList) ''
+      install -Dm644 ${finalAttrs.passthru.sources.font} "$out/share/fonts/truetype/sketchybar-app-font.ttf"
 
-    runHook postInstall
-  '';
+    '' + lib.optionalString (lib.elem "shell" artifactList) ''
+      install -Dm755 ${finalAttrs.passthru.sources.shell} "$out/bin/icon_map.sh"
 
-  meta = {
-    description = "A ligature-based symbol font and a mapping function for sketchybar";
-    longDescription = ''
-      A ligature-based symbol font and a mapping function for sketchybar, inspired by simple-bar's usage of community-contributed minimalistic app icons.
+    '' + lib.optionalString (lib.elem "lua" artifactList) ''
+      install -Dm644 ${finalAttrs.passthru.sources.lua} "$out/lib/sketchybar-app-font/icon_map.lua"
+
+      runHook postInstall
     '';
-    homepage = "https://github.com/kvndrsslr/sketchybar-app-font";
-    license = lib.licenses.cc0;
-    maintainers = with lib.maintainers; [ khaneliman ];
-  };
-}
+
+    passthru = {
+      sources = {
+        font = fetchurl {
+          url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${finalAttrs.version}/sketchybar-app-font.ttf";
+          hash = "sha256-s1mnoHEozmDNsW0P4z97fupAVElxikia0TYLVHJPAM4=";
+        };
+        lua = fetchurl {
+          url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${finalAttrs.version}/icon_map.lua";
+          hash = "sha256-YLr7dlKliKLUEK18uG4ouXfLqodVpcDQzfu+H1+oe/w=";
+        };
+        shell = fetchurl {
+          url = "https://github.com/kvndrsslr/sketchybar-app-font/releases/download/v${finalAttrs.version}/icon_map.sh";
+          hash = "sha256-ZT/k6Vk/nO6mq1yplXaWyz9HxqwEiVWba+rk+pIRZq4=";
+        };
+      };
+
+      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" "0" "${lib.fakeHash}" --source-key="sources.$artifact"
+          update-source-version "sketchybar-app-font" "$NEW_VERSION" --source-key="sources.$artifact"
+        done
+      '';
+    };
+
+    meta = {
+      description = "A ligature-based symbol font and a mapping function for sketchybar";
+      longDescription = ''
+        A ligature-based symbol font and a mapping function for sketchybar, inspired by simple-bar's usage of community-contributed minimalistic app icons.
+      '';
+      homepage = "https://github.com/kvndrsslr/sketchybar-app-font";
+      license = lib.licenses.cc0;
+      maintainers = with lib.maintainers; [ khaneliman ];
+    };
+  })