Skip to content

Commit 7021ec0

Browse files
authored
parca: add update script (NixOS#397377)
2 parents 0577ecb + 8002e29 commit 7021ec0

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

pkgs/by-name/pa/parca/package.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ buildGoModule rec {
6868
cp -r ${ui}/share/parca/ui/* ui/packages/app/web/build
6969
'';
7070

71+
passthru = {
72+
inherit ui;
73+
updateScript = ./update.sh;
74+
};
75+
7176
meta = {
7277
mainProgram = "parca";
7378
description = "Continuous profiling for analysis of CPU and memory usage";

pkgs/by-name/pa/parca/update.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env nix-shell
2+
#!nix-shell -I nixpkgs=./. -i bash -p curl jq git pnpm_9
3+
# shellcheck shell=bash
4+
set -euo pipefail
5+
nixpkgs="$(pwd)"
6+
cd $(readlink -e $(dirname "${BASH_SOURCE[0]}"))
7+
8+
# Update the hash of the parca source code in the Nix expression.
9+
update_parca_source() {
10+
local version; version="$1"
11+
echo "Updating parca source"
12+
13+
old_version="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).parca.version" | jq -r)"
14+
sed -i "s|${old_version}|${version}|g" package.nix
15+
16+
old_hash="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).parca.src.outputHash" | jq -r)"
17+
new_hash="$(nix-build --impure --expr "let src = (import $nixpkgs/default.nix {}).parca.src; in (src.overrideAttrs or (f: src // f src)) (_: { outputHash = \"\"; outputHashAlgo = \"sha256\"; })" 2>&1 | tr -s ' ' | grep -Po "got: \K.+$")" || true
18+
19+
sed -i "s|${old_hash}|${new_hash}|g" package.nix
20+
}
21+
22+
# Update the hash of the parca ui pnpm dependencies in the Nix expression.
23+
update_pnpm_deps_hash() {
24+
echo "Updating parca ui pnpm deps hash"
25+
26+
old_hash="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).parca.ui.pnpmDeps.outputHash" | jq -r)"
27+
new_hash="$(nix-build --impure --expr "let src = (import $nixpkgs/default.nix {}).parca.ui.pnpmDeps; in (src.overrideAttrs or (f: src // f src)) (_: { outputHash = \"\"; outputHashAlgo = \"sha256\"; })" 2>&1 | tr -s ' ' | grep -Po "got: \K.+$")" || true
28+
29+
sed -i "s|${old_hash}|${new_hash}|g" package.nix
30+
}
31+
32+
# Update the hash of the parca go dependencies in the Nix expression.
33+
update_go_deps_hash() {
34+
echo "Updating parca go deps hash"
35+
36+
old_hash="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).parca.vendorHash" | jq -r)"
37+
new_hash="$(nix-build --impure --expr "let src = (import $nixpkgs/default.nix {}).parca; in (src.overrideAttrs { vendorHash = \"\"; })" 2>&1 | tr -s ' ' | grep -Po "got: \K.+$")" || true
38+
39+
sed -i "s|${old_hash}|${new_hash}|g" package.nix
40+
}
41+
42+
LATEST_TAG="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/parca-dev/parca/releases/latest | jq -r '.tag_name')"
43+
LATEST_VERSION="$(expr "$LATEST_TAG" : 'v\(.*\)')"
44+
CURRENT_VERSION="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).parca.version" | jq -r)"
45+
46+
if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then
47+
echo "parca is up to date: ${CURRENT_VERSION}"
48+
exit 0
49+
fi
50+
51+
update_parca_source "$LATEST_VERSION"
52+
update_pnpm_deps_hash
53+
update_go_deps_hash

0 commit comments

Comments
 (0)