pgrok: move to node-packages.nix

This commit is contained in:
Marie Ramlow 2023-09-24 20:23:54 +02:00
parent c1a53897ad
commit d8b16f7418
No known key found for this signature in database
8 changed files with 3466 additions and 8575 deletions

View file

@ -191,6 +191,7 @@
, "patch-package" , "patch-package"
, "peerflix" , "peerflix"
, "peerflix-server" , "peerflix-server"
, {"pgrok-build-deps": "../../tools/networking/pgrok/build-deps"}
, "pkg" , "pkg"
, "pm2" , "pm2"
, "pnpm" , "pnpm"

File diff suppressed because it is too large Load diff

View file

@ -1,11 +0,0 @@
diff --git a/package.json b/package.json
index 35d34c5..82eda74 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,6 @@
{
"name": "pgrokd",
+ "version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build --outDir=../cli/dist --emptyOutDir",

View file

@ -0,0 +1,38 @@
{
"name": "pgrokd",
"scripts": {
"dev": "vite",
"build": "tsc && vite build --outDir=dist --emptyOutDir",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
},
"version": "1.4.0",
"dependencies": {
"axios": "~1.4.0",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"react-router-dom": "~6.15.0",
"@headlessui/react": "~1.7.17",
"@heroicons/react": "~2.0.18",
"@tailwindcss/forms": "~0.5.4",
"@trivago/prettier-plugin-sort-imports": "~4.2.0",
"@types/node": "~20.5.1",
"@types/react": "~18.2.15",
"@types/react-dom": "~18.2.7",
"@typescript-eslint/eslint-plugin": "~6.0.0",
"@typescript-eslint/parser": "~6.0.0",
"@vitejs/plugin-react": "~4.0.3",
"autoprefixer": "~10.4.15",
"code-inspector-plugin": "v0.1.9",
"eslint": "~8.45.0",
"eslint-plugin-import": "~2.28.0",
"eslint-plugin-react": "~7.33.2",
"eslint-plugin-react-hooks": "~4.6.0",
"eslint-plugin-react-refresh": "~0.4.3",
"eslint-plugin-unicorn": "~48.0.1",
"postcss": "~8.4.28",
"prettier": "~3.0.2",
"tailwindcss": "~3.3.3",
"typescript": "~5.0.2",
"vite": "~4.4.5"
}
}

View file

@ -3,23 +3,22 @@
, callPackage , callPackage
, fetchFromGitHub , fetchFromGitHub
}: }:
let buildGoModule rec {
pname = "pgrok";
version = "1.4.0"; version = "1.4.0";
src = fetchFromGitHub { src = fetchFromGitHub {
owner = "pgrok"; owner = "pgrok";
repo = "pgrok"; repo = "pgrok";
rev = "v${version}"; rev = "v${version}";
hash = "sha256-2k3XLXmf1Xnx4HvS7sD/aq+78Z4I7uY4djV958n5TX4="; hash = "sha256-2k3XLXmf1Xnx4HvS7sD/aq+78Z4I7uY4djV958n5TX4=";
}; };
web = callPackage ./web.nix { inherit src version; };
in
buildGoModule {
pname = "pgrok";
inherit version src;
vendorHash = "sha256-M0xVHRh9NKPxmUEmx1dDQUZc8aXcdAfHisQAnt72RdY="; vendorHash = "sha256-M0xVHRh9NKPxmUEmx1dDQUZc8aXcdAfHisQAnt72RdY=";
outputs = [ "out" "server" "web" ]; outputs = [ "out" "server" ];
web = callPackage ./web.nix { inherit src version; };
ldflags = [ ldflags = [
"-s" "-s"
@ -43,7 +42,6 @@ buildGoModule {
postInstall = '' postInstall = ''
moveToOutput bin/pgrokd $server moveToOutput bin/pgrokd $server
cp -r ${web} $web
''; '';
passthru.updateScript = ./update.sh; passthru.updateScript = ./update.sh;

File diff suppressed because it is too large Load diff

View file

@ -1,58 +1,40 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix wget nix-prefetch-github moreutils jq prefetch-npm-deps nodejs #!nix-shell -i bash -p nix curl nix-update jq
# adapted from https://github.com/NixOS/nixpkgs/blob/f4ffbe5ecb8039816f2dae60526e0a47f65a2b4e/pkgs/servers/memos/update.sh
set -euo pipefail set -euo pipefail
nix-update
cd "$(dirname "$0")"
nixpkgs=../../../..
node_packages="$nixpkgs/pkgs/development/node-packages"
pgrok="$nixpkgs/pkgs/tools/networking/pgrok"
TARGET_VERSION_REMOTE=$(curl -s https://api.github.com/repos/pgrok/pgrok/releases/latest | jq -r ".tag_name") TARGET_VERSION_REMOTE=$(curl -s https://api.github.com/repos/pgrok/pgrok/releases/latest | jq -r ".tag_name")
TARGET_VERSION=${TARGET_VERSION_REMOTE#v} TARGET_VERSION=${TARGET_VERSION_REMOTE#v}
if [[ "$UPDATE_NIX_OLD_VERSION" == "$TARGET_VERSION" ]]; then
echo "pgrok is up-to-date: ${UPDATE_NIX_OLD_VERSION}"
exit 0
fi
extractVendorHash() {
original="${1?original hash missing}"
result="$(nix-build -A pgrok.goModules 2>&1 | tail -n3 | grep 'got:' | cut -d: -f2- | xargs echo || true)"
[ -z "$result" ] && { echo "$original"; } || { echo "$result"; }
}
replaceHash() {
old="${1?old hash missing}"
new="${2?new hash missing}"
awk -v OLD="$old" -v NEW="$new" '{
if (i=index($0, OLD)) {
$0 = substr($0, 1, i-1) NEW substr($0, i+length(OLD));
}
print $0;
}' ./pkgs/tools/networking/pgrok/default.nix | sponge ./pkgs/tools/networking/pgrok/default.nix
}
# change version number
sed -e "s/version =.*;/version = \"$TARGET_VERSION\";/g" \
-i ./pkgs/tools/networking/pgrok/default.nix
# update hash
SRC_HASH="$(nix-instantiate --eval -A pgrok.src.outputHash | tr -d '"')"
NEW_HASH="$(nix-prefetch-github pgrok pgrok --rev v$TARGET_VERSION | jq -r .hash)"
replaceHash "$SRC_HASH" "$NEW_HASH"
GO_HASH="$(nix-instantiate --eval -A pgrok.vendorHash | tr -d '"')"
EMPTY_HASH="$(nix-instantiate --eval -A lib.fakeHash | tr -d '"')"
replaceHash "$GO_HASH" "$EMPTY_HASH"
replaceHash "$EMPTY_HASH" "$(extractVendorHash "$GO_HASH")"
# update src yarn lock
SRC_FILE_BASE="https://raw.githubusercontent.com/pgrok/pgrok/v$TARGET_VERSION" SRC_FILE_BASE="https://raw.githubusercontent.com/pgrok/pgrok/v$TARGET_VERSION"
pushd ./pkgs/tools/networking/pgrok # replace ^ versions with ~, replace outdir to dist
wget -q "$SRC_FILE_BASE/pgrokd/web/package.json" curl https://raw.githubusercontent.com/pgrok/pgrok/main/pgrokd/web/package.json \
npm install --package-lock-only | jq "{name,scripts,version: \"${TARGET_VERSION}\",dependencies: (.dependencies + .devDependencies) }" \
rm package.json* | sed -e 's/"\^/"~/g' -e 's/\.\.\/cli\/dist/dist/g' \
NPM_HASH=$(prefetch-npm-deps ./package-lock.json) > "$pgrok/build-deps/package.json.new"
popd
old_deps="$(jq '.dependencies' "$pgrok/build-deps/package.json")"
new_deps="$(jq '.dependencies' "$pgrok/build-deps/package.json.new")"
if [[ "$old_deps" == "$new_deps" ]]; then
echo "package.json dependencies not changed, do simple version change"
sed -e '/^ "pgrok-build-deps/,+3 s/version = ".*"/version = "'"$TARGET_VERSION"'"/' \
--in-place "$node_packages"/node-packages.nix
mv build-deps/package.json{.new,}
else
echo "package.json dependencies changed, updating nodePackages"
mv build-deps/package.json{.new,}
./"$node_packages"/generate.sh
fi
sed -i -E -e "s#npmDepsHash = \".*\"#npmDepsHash = \"$NPM_HASH\"#" ./pkgs/tools/networking/pgrok/web.nix

View file

@ -1,29 +1,30 @@
{ buildNpmPackage { src
, src
, version , version
, nodejs
, nodePackages
, stdenvNoCC
}: }:
buildNpmPackage { let
name = "pgrok-web"; build-deps = nodePackages."pgrok-build-deps-../../tools/networking/pgrok/build-deps";
inherit src version; in
sourceRoot = "${src.name}/pgrokd/web"; stdenvNoCC.mkDerivation {
pname = "pgrok-web";
inherit version;
src = "${src}/pgrokd/web";
npmDepsHash = "sha256-f4pDBoG6sTJE3aUknqUvHHpBR9KWo/B4YMrWHkGbvA8="; nativeBuildInputs = [ nodejs ];
# Upstream doesn't have a lockfile buildPhase = ''
postPatch = '' runHook preBuild
cp ${./package-lock.json} ./package-lock.json cp ${./build-deps/package.json} package.json
substituteInPlace ./package.json \ ln -s ${build-deps}/lib/node_modules/pgrokd/node_modules node_modules
--replace "../cli/dist" "$out" npm run build
''; runHook postBuild
'';
patches = [ installPhase = ''
./add_version_to_package.json.patch runHook preInstall
]; cp -r dist $out
runHook postInstall
dontInstall = true; '';
dontFixup = true; }
NODE_OPTIONS = "--openssl-legacy-provider";
npmPackFlags = [ "--ignore-scripts" ];
}