Skip to content

Commit

Permalink
{update-vencord.sh,vencord.nix}: add update logic for pnpmDeps.hash
Browse files Browse the repository at this point in the history
  • Loading branch information
DontEatOreo committed Jan 9, 2025
1 parent 1a8fb00 commit fd1ad8f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
63 changes: 55 additions & 8 deletions update-vencord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ trap cleanup EXIT
OWNER="Vendicated"
REPO="Vencord"

echo "Updating $ABS_NIX_FILE for $OWNER/$REPO ($UPDATE_TYPE)..."

# Create a wrapper that calls the package with the appropriate unstable flag
cat >temp-wrapper.nix <<EOF
{ pkgs ? import <nixpkgs> {} }:
Expand All @@ -38,28 +36,77 @@ cat >temp-wrapper.nix <<EOF
}
EOF

update_hash() {
local type="$1"
local new_hash="$2"
local prefix="${type}PnpmDeps"

sed -i "/^[[:space:]]*${prefix}[[:space:]]*=[[:space:]]*\"sha256-[A-Za-z0-9+/=]\{1,\}\"/c\ ${prefix} = \"sha256-${new_hash}\";" "$ABS_NIX_FILE"
}

update_pnpm_deps() {
local type="$1"
echo "Checking ${type}pnpmDeps"

local is_unstable
is_unstable=$([[ "$type" == "unstable" ]] && echo "true" || echo "false")

if nix-build --pure \
--expr "with import (builtins.getFlake \"nixpkgs\") {}; (callPackage ${ABS_NIX_FILE} { unstable = ${is_unstable}; }).pnpmDeps" \
--no-link &>/dev/null; then
echo "${type}pnpmDeps hash is already correct"
return 0
fi

echo "Current hash invalid. Calculating new pnpmDeps hash for ${type}..."

local build_output
build_output=$(nix-build --pure \
--expr "with import (builtins.getFlake \"nixpkgs\") {}; (callPackage ${ABS_NIX_FILE} { unstable = ${is_unstable}; }).pnpmDeps" \
--no-link 2>&1 || true)

local new_hash
new_hash=$(echo "$build_output" | grep -oP 'got:\s+sha256-\K[A-Za-z0-9+/]*=' || true)

if [ -n "$new_hash" ]; then
update_hash "$type" "$new_hash"
echo "Updated ${type} pnpmDeps hash"

if nix-build --pure \
--expr "with import (builtins.getFlake \"nixpkgs\") {}; (callPackage ${ABS_NIX_FILE} { unstable = ${is_unstable}; }).pnpmDeps" \
--no-link &>/dev/null; then
echo "Verification successful - new hash works"
return 0
else
echo "Error: New hash verification failed"
return 1
fi
else
echo "Failed to extract new pnpmDeps hash"
return 1
fi
}

if [ "$UPDATE_TYPE" = "stable" ]; then
# For stable versions, we're getting latest tag and update
echo "Fetching latest stable version..."
update_pnpm_deps "stable"
if ! nix-update --version-regex 'v(.*)' \
--url "https://github.com/$OWNER/$REPO" \
--format \
-f ./temp-wrapper.nix \
--override-filename "$ABS_NIX_FILE" \
"${REPO}"; then
echo "Failed to update stable version"
exit 1
echo "Failed to update stable version, updating pnpm deps..."
fi
else
# For unstable versions, we're just using branch update
echo "Fetching latest unstable version..."
update_pnpm_deps "unstable"
if ! nix-update --version=branch \
--url "https://github.com/$OWNER/$REPO" \
--format \
-f ./temp-wrapper.nix \
--override-filename "$ABS_NIX_FILE" \
"${REPO}"; then
echo "Failed to update unstable version"
exit 1
echo "Failed to update unstable version, updating pnpm deps..."
fi
fi
11 changes: 6 additions & 5 deletions vencord.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
let
stableVersion = "1.10.9";
stableHash = "sha256-sU2eJUUw7crvzMGGBQP6rbxISkL+S5nmT3QspyYXlRQ=";
stablePnpmDeps = "sha256-vVzERis1W3QZB/i6SQR9dQR56yDWadKWvFr+nLTQY9Y=";

unstableVersion = "1.10.9-unstable-2025-01-10";
unstableRev = "3243120baaa56f65866b532b731bc3426512c90e";
unstableHash = "sha256-ov1qLtBzLAO8k9pokOstEaeS/me+ElVvGzyFTSfaZM0=";

unstableVersion = "1.10.9-unstable-2025-01-09";
unstableRev = "4ab297c9e3e1898f2d72bd6055a3ee94f2f4f416";
unstableHash = "sha256-mDqHuWDGCCR9wF4g9PFBdQNgDFwmZAPuAnSczEL8mEA=";
unstablePnpmDeps = "sha256-ZUwtNtOmxjhOBpYB7vuytunGBRSuVxdlQsceRmeyhhI=";
in
stdenv.mkDerivation (finalAttrs: {
pname = "vencord" + lib.optionalString unstable "-unstable";
Expand All @@ -36,7 +37,7 @@ stdenv.mkDerivation (finalAttrs: {

pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname src;
hash = "sha256-ZUwtNtOmxjhOBpYB7vuytunGBRSuVxdlQsceRmeyhhI=";
hash = if unstable then unstablePnpmDeps else stablePnpmDeps;
};

nativeBuildInputs = [
Expand Down

0 comments on commit fd1ad8f

Please sign in to comment.