From 7b136032a56ca0bf1eac8d32bbf298a8dafdf976 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Fri, 14 Jun 2024 22:12:50 +0530 Subject: [PATCH] hyprland: add update script Co-authored-by: fufexan --- pkgs/by-name/hy/hyprland/info.json | 7 ++++++ pkgs/by-name/hy/hyprland/package.nix | 16 ++++++++++--- pkgs/by-name/hy/hyprland/update.sh | 35 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 pkgs/by-name/hy/hyprland/info.json create mode 100644 pkgs/by-name/hy/hyprland/update.sh diff --git a/pkgs/by-name/hy/hyprland/info.json b/pkgs/by-name/hy/hyprland/info.json new file mode 100644 index 000000000000..4f9a2cf5b829 --- /dev/null +++ b/pkgs/by-name/hy/hyprland/info.json @@ -0,0 +1,7 @@ +{ + "branch": "", + "commit_hash": "", + "commit_message": "", + "date": "", + "tag": "" +} diff --git a/pkgs/by-name/hy/hyprland/package.nix b/pkgs/by-name/hy/hyprland/package.nix index 958e84ac78f0..467d12e83a69 100644 --- a/pkgs/by-name/hy/hyprland/package.nix +++ b/pkgs/by-name/hy/hyprland/package.nix @@ -47,6 +47,9 @@ , hidpiXWayland ? false , enableNvidiaPatches ? false }: +let + info = builtins.fromJSON (builtins.readFile ./info.json); +in assert lib.assertMsg (!nvidiaPatches) "The option `nvidiaPatches` has been removed."; assert lib.assertMsg (!enableNvidiaPatches) "The option `enableNvidiaPatches` has been removed."; assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been removed. Please refer https://wiki.hyprland.org/Configuring/XWayland"; @@ -68,9 +71,14 @@ stdenv.mkDerivation (finalAttrs: { sed -i "s#/usr#$out#" src/render/OpenGL.cpp ''; - # used by version.sh - DATE = "2024-05-05"; - HASH = finalAttrs.src.rev; + # variables used by generateVersion.sh script, and shown in `hyprctl version` + BRANCH = info.branch; + COMMITS = info.commit_hash; + DATE = info.date; + DIRTY = ""; + HASH = info.commit_hash; + MESSAGE = info.commit_message; + TAG = info.tag; depsBuildBuild = [ # to find wayland-scanner when cross-compiling @@ -152,6 +160,8 @@ stdenv.mkDerivation (finalAttrs: { passthru.providedSessions = [ "hyprland" ]; + passthru.updateScript = ./update.sh; + meta = with lib; { homepage = "https://github.com/hyprwm/Hyprland"; description = "Dynamic tiling Wayland compositor that doesn't sacrifice on its looks"; diff --git a/pkgs/by-name/hy/hyprland/update.sh b/pkgs/by-name/hy/hyprland/update.sh new file mode 100644 index 000000000000..c729705f6b1d --- /dev/null +++ b/pkgs/by-name/hy/hyprland/update.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p common-updater-scripts fd jq + +set -eou pipefail + +latest_release="$(curl --silent 'https://api.github.com/repos/hyprwm/Hyprland/releases/latest')" +latest_tag="$(curl --silent 'https://api.github.com/repos/hyprwm/Hyprland/tags?per_page=1')" +commit_hash="$(jq -r '.[0].commit.sha' <<<"$latest_tag")" +latest_commit="$(curl --silent 'https://api.github.com/repos/hyprwm/Hyprland/commits/'"$commit_hash"'')" +commit_message="$(jq -r '.commit.message' <<<"$latest_commit")" + +tag=$(jq -r '.tag_name' <<<"$latest_release") +# drop 'v' prefix +version="${tag#v}" + +branch=$(jq -r '.target_commitish' <<<"$latest_release") + +date=$(jq -r '.created_at' <<<"$latest_release") +# truncate time +date=${date%T*} + +# update version; otherwise fail +update-source-version hyprland "$version" --ignore-same-hash + +# find hyprland dir +files="$(fd --full-path /hyprland/ | head -1)" +dir="${files%/*}" + +echo -e '{ + "branch": "'"$branch"'", + "commit_hash": "'"$commit_hash"'", + "commit_message": "'"$commit_message"'", + "date": "'"$date"'", + "tag": "'"$tag"'" +}' >"$dir/info.json"