From 93d4e18b46dc3fcdbce8b4bfdbaebcb385ba9098 Mon Sep 17 00:00:00 2001 From: nandi <78769380+codegod100@users.noreply.github.com> Date: Wed, 22 Jul 2026 20:03:39 +0000 Subject: [PATCH] Add zed-preview package (official x86_64 Linux binaries) Package the Zed preview channel from GitHub release tarballs, expose it on x86_64-linux only, and teach the weekly updater about github-release-binary. --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 51 ++++++++++++++++++++++++++++++++------------------- scripts/update-packages.sh | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ packages/zed-preview/default.nix | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ packages/zed-preview/upstream.json | 8 ++++++++ 5 file(s) changed, 285 insertion(s)(+), 19 deletion(s)(-) diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ | `vit` | [solpbc/vit](https://github.com/solpbc/vit) | `npm install -g vit` | | `rook` | [solpbc/rook](https://github.com/solpbc/rook) | `npm install -g @solpbc/rook` | | `spinel` | [matz/spinel](https://github.com/matz/spinel) | build from source (`make deps && make && make install`) | +| `zed-preview` | [zed-industries/zed](https://github.com/zed-industries/zed) (preview channel) | [official Linux installer](https://zed.dev/docs/linux) / `zed-linux-x86_64.tar.gz` | ## Usage @@ -37,17 +38,20 @@ nix build .#vit nix build .#rook nix build .#spinel +nix build .#zed-preview # x86_64-linux only # run without installing nix run .#vit -- --help nix run .#rook -- --help nix run .#spinel -- --help nix run .#spin -- new myapp # spin project tool (from the spinel package) +nix run .#zed-preview -- --version # install into your profile nix profile install .#vit nix profile install .#rook nix profile install .#spinel +nix profile install .#zed-preview ``` ## Updating packages @@ -102,6 +106,22 @@ For spinel, the updater also re-reads `PRISM_VERSION` / `RBS_VERSION` from the upstream Makefile and refreshes the vendored gem hashes when they change. +**github-release-binary** — prebuilt release assets (no source build): + +```json +{ + "type": "github-release-binary", + "github": "owner/repo", + "tag_prefix": "v", + "tag_suffix": "-pre", + "asset": "zed-linux-x86_64.tar.gz" +} +``` + +Tracks the newest non-draft GitHub release whose tag matches +`{tag_prefix}{semver}{tag_suffix}` and refreshes the `fetchurl` hash for +`asset`. Used by `zed-preview` (x86_64-linux only). + ### Manual steps (vit / rook) If you prefer to bump by hand (same flow for either npm-github package): @@ -147,3 +167,23 @@ nix hash convert --hash-algo sha256 --to sri ``` 3. `nix build .#spinel` and smoke-test `./result/bin/spinel -e 'puts 1'`. + +### Manual steps (zed-preview) + +`zed-preview` ships official Linux x86_64 preview binaries (tags `vX.Y.Z-pre`). +Prefer the updater: + +```bash +./scripts/update-packages.sh zed-preview +``` + +By hand: + +1. Bump `version` in `packages/zed-preview/default.nix` (e.g. `1.12.0-pre`). +2. Prefetch the tarball hash: + ```bash + nix-prefetch-url "https://github.com/zed-industries/zed/releases/download/vX.Y.Z-pre/zed-linux-x86_64.tar.gz" + nix hash convert --hash-algo sha256 --to sri + ``` +3. Paste the SRI hash into `fetchurl.hash`, then `nix build .#zed-preview` and + smoke-test `./result/bin/zed-preview --version`. diff --git a/flake.nix b/flake.nix --- a/flake.nix +++ b/flake.nix @@ -28,27 +28,40 @@ rook = pkgs.callPackage ./packages/rook { }; default = self.packages.${system}.vit; } + // pkgs.lib.optionalAttrs (system == "x86_64-linux") { + # Official preview tarball is only fetched for x86_64-linux. + zed-preview = pkgs.callPackage ./packages/zed-preview { }; + } ); # Convenience: `nix run .#vit -- --help`, `nix run .#spinel -- --help` - apps = forAllSystems (system: { - vit = { - type = "app"; - program = "${self.packages.${system}.vit}/bin/vit"; - }; - spinel = { - type = "app"; - program = "${self.packages.${system}.spinel}/bin/spinel"; - }; - spin = { - type = "app"; - program = "${self.packages.${system}.spinel}/bin/spin"; - }; - rook = { - type = "app"; - program = "${self.packages.${system}.rook}/bin/rook"; - }; - default = self.apps.${system}.vit; - }); + apps = forAllSystems ( + system: + { + vit = { + type = "app"; + program = "${self.packages.${system}.vit}/bin/vit"; + }; + spinel = { + type = "app"; + program = "${self.packages.${system}.spinel}/bin/spinel"; + }; + spin = { + type = "app"; + program = "${self.packages.${system}.spinel}/bin/spin"; + }; + rook = { + type = "app"; + program = "${self.packages.${system}.rook}/bin/rook"; + }; + default = self.apps.${system}.vit; + } + // nixpkgs.lib.optionalAttrs (system == "x86_64-linux") { + zed-preview = { + type = "app"; + program = "${self.packages.${system}.zed-preview}/bin/zed-preview"; + }; + } + ); }; } diff --git a/scripts/update-packages.sh b/scripts/update-packages.sh --- a/scripts/update-packages.sh +++ b/scripts/update-packages.sh @@ -411,6 +411,120 @@ log "${name}: updated successfully to ${latest}" } +latest_github_tag_with_suffix() { + # latest_github_tag_with_suffix + # e.g. prefix=v suffix=-pre => matches v1.12.0-pre, prints 1.12.0-pre + local repo="$1" prefix="$2" suffix="$3" + local url="https://api.github.com/repos/${repo}/releases?per_page=30" + local args=(-fsSL) + if [[ -n "${GITHUB_TOKEN:-}" ]]; then + args+=(-H "Authorization: Bearer ${GITHUB_TOKEN}") + fi + curl "${args[@]}" "$url" | python3 -c ' +import json, re, sys +prefix, suffix = sys.argv[1], sys.argv[2] +releases = json.load(sys.stdin) +pat = re.compile( + r"^" + re.escape(prefix) + r"(\d+\.\d+\.\d+)" + re.escape(suffix) + r"$" +) +versions = [] +for r in releases: + if r.get("draft"): + continue + name = r.get("tag_name") or "" + m = pat.match(name) + if m: + versions.append(m.group(1) + suffix) +if not versions: + sys.exit("no matching release tags for prefix=%r suffix=%r" % (prefix, suffix)) +def key(v): + core = re.split(r"[+-]", v, maxsplit=1)[0] + return [int(x) for x in core.split(".")] +versions.sort(key=key) +print(versions[-1]) +' "$prefix" "$suffix" +} + +set_fetchurl_hash() { + # set_fetchurl_hash + # Replaces hash = "..." inside the first fetchurl { ... } block. + local file="$1" value="$2" + python3 -c ' +import re, sys +path, value = sys.argv[1], sys.argv[2] +text = open(path).read() +pat = re.compile( + r"(fetchurl\s*\{[^}]*?hash\s*=\s*\")([^\"]+)(\")", + re.S, +) +new, n = pat.subn(rf"\g<1>{value}\g<3>", text, count=1) +if n != 1: + sys.exit(f"failed to set fetchurl.hash in {path} (matches={n})") +open(path, "w").write(new) +' "$file" "$value" +} + +update_github_release_binary() { + # Official prebuilt release assets (e.g. zed-preview Linux tarball). + # version in default.nix is the tag without the leading "v" (e.g. 1.12.0-pre). + local name="$1" + local pkg_dir="$ROOT/packages/${name}" + local default_nix="$pkg_dir/default.nix" + local upstream="$pkg_dir/upstream.json" + local repo tag_prefix tag_suffix asset + repo="$(read_field "$upstream" github)" + tag_prefix="$(read_field "$upstream" tag_prefix)" + tag_suffix="$(read_field "$upstream" tag_suffix)" + asset="$(read_field "$upstream" asset)" + [[ -n "$repo" ]] || die "${name}: upstream.json missing github" + [[ -n "$asset" ]] || die "${name}: upstream.json missing asset" + tag_prefix="${tag_prefix:-v}" + tag_suffix="${tag_suffix:-}" + + local cur latest + cur="$(current_version "$default_nix")" + log "${name}: current=${cur}" + latest="$(latest_github_tag_with_suffix "$repo" "$tag_prefix" "$tag_suffix")" + log "${name}: latest upstream=${latest}" + + if [[ "$latest" == "$cur" ]]; then + log "${name}: already up to date" + return 0 + fi + + # Semver compare on the numeric core (ignore -pre etc.) + local cur_core latest_core + cur_core="${cur%%-*}"; cur_core="${cur_core%%+*}" + latest_core="${latest%%-*}"; latest_core="${latest_core%%+*}" + if ! version_gt "$latest_core" "$cur_core" && [[ "$latest" != "$cur" ]]; then + # Same core version but different suffix, or non-monotonic tag: still update + # when the full tag string differs (handled above). If latest core is older, + # skip to avoid downgrades. + if ! version_gt "$latest_core" "$cur_core" && [[ "$latest_core" != "$cur_core" ]]; then + log "${name}: latest core ${latest_core} is not newer than ${cur_core}; skipping" + return 0 + fi + fi + + if [[ "$CHECK_ONLY" -eq 1 ]]; then + log "${name}: OUTDATED (${cur} -> ${latest})" + return 10 + fi + + log "${name}: updating ${cur} -> ${latest}" + set_field_string "$default_nix" version "$latest" + + local src_url src_hash + src_url="https://github.com/${repo}/releases/download/${tag_prefix}${latest}/${asset}" + log "${name}: prefetching ${src_url}" + src_hash="$(sri_from_url_file "$src_url")" + set_fetchurl_hash "$default_nix" "$src_hash" + log "${name}: src hash ${src_hash}" + + verify_build "$name" + log "${name}: updated successfully to ${latest}" +} + update_github_unstable() { # Track tip of a branch for projects without release tags. # version format: 0-unstable-YYYY-MM-DD @@ -477,6 +591,9 @@ ;; github-unstable) update_github_unstable "$name" || status=$? + ;; + github-release-binary) + update_github_release_binary "$name" || status=$? ;; *) die "${name}: unsupported upstream type '${type}'" diff --git a/packages/zed-preview/default.nix b/packages/zed-preview/default.nix new file mode 100644 --- /dev/null +++ b/packages/zed-preview/default.nix @@ -0,0 +1,88 @@ +{ + lib, + stdenv, + fetchurl, + autoPatchelfHook, + makeWrapper, + alsa-lib, + libGL, + libgcc, + vulkan-loader, + wayland, + versionCheckHook, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "zed-preview"; + # Official preview channel tags are vX.Y.Z-pre (prerelease on GitHub). + version = "1.12.0-pre"; + + src = fetchurl { + url = "https://github.com/zed-industries/zed/releases/download/v${finalAttrs.version}/zed-linux-x86_64.tar.gz"; + hash = "sha256-KqqXibrYxLzt+HInAJla86wbqgVlDE4PKLha6BOflgc="; + }; + + sourceRoot = "zed-preview.app"; + + nativeBuildInputs = [ + autoPatchelfHook + makeWrapper + ]; + + buildInputs = [ + alsa-lib + libgcc + ]; + + # Bundled $ORIGIN/../lib covers most deps; these are either NEEDED (alsa) or + # commonly dlopened at runtime (GPU / Wayland). + runtimeDependencies = [ + alsa-lib + libGL + vulkan-loader + wayland + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out + cp -a bin lib libexec share $out/ + # Coexist with nixpkgs zed-editor (zeditor) and a stable zed binary. + mv $out/bin/zed $out/bin/zed-preview + + # Point the desktop entry at our binary name (line-anchored; plain + # substitute would also rewrite TryExec when matching Exec=zed). + sed -i \ + -e 's/^TryExec=zed$/TryExec=zed-preview/' \ + -e 's/^Exec=zed/Exec=zed-preview/' \ + $out/share/applications/dev.zed.Zed-Preview.desktop + + runHook postInstall + ''; + + postFixup = '' + wrapProgram $out/bin/zed-preview \ + --set ZED_UPDATE_EXPLANATION "Zed Preview has been installed using Nix. Auto-updates have thus been disabled." + ''; + + nativeInstallCheckInputs = [ versionCheckHook ]; + versionCheckProgram = "${placeholder "out"}/bin/zed-preview"; + versionCheckProgramArg = "--version"; + # Upstream prints "Zed preview 1.12.0 …" (no -pre suffix). + preInstallCheck = '' + export version="${lib.removeSuffix "-pre" finalAttrs.version}" + ''; + doInstallCheck = true; + + meta = { + description = "High-performance, multiplayer code editor (official Linux preview binaries)"; + homepage = "https://zed.dev"; + changelog = "https://github.com/zed-industries/zed/releases/tag/v${finalAttrs.version}"; + # AGPL for the editor; some bundled components differ — see licenses.md in the tarball. + license = lib.licenses.gpl3Only; + mainProgram = "zed-preview"; + platforms = [ "x86_64-linux" ]; + sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + }; +}) diff --git a/packages/zed-preview/upstream.json b/packages/zed-preview/upstream.json new file mode 100644 --- /dev/null +++ b/packages/zed-preview/upstream.json @@ -0,0 +1,8 @@ +{ + "type": "github-release-binary", + "github": "zed-industries/zed", + "tag_prefix": "v", + "tag_suffix": "-pre", + "asset": "zed-linux-x86_64.tar.gz", + "description": "Official Linux x86_64 preview tarball. Tracks latest vX.Y.Z-pre GitHub release." +} -- tangled.sh