NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.38k stars 14.34k forks source link

patch code-cursor to remove double window header #348282

Closed poyhen closed 1 month ago

poyhen commented 1 month ago

Describe the bug

image https://github.com/getcursor/cursor/issues/837

Steps To Reproduce

Steps to reproduce the behavior:

  1. run cursor (possibly on gnome)

Expected behavior

to not have the extra gnome header image

Additional context

i am new to nix and tried to modify the package.nix for code-cursor. i achieved to patch it according to instructions on (https://github.com/getcursor/cursor/issues/837#issuecomment-2326443145) but i failed to update the update script to match url and outputHash

here is my package.nix

{
  lib,
  stdenvNoCC,
  fetchurl,
  appimageTools,
  makeWrapper,
  writeScript,
}:
let
  pname = "cursor";
  version = "0.41.3";
  appKey = "230313mzl4w4u92";
  src = appimageTools.extract {
    inherit pname version;
    src = fetchurl {
      url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.41.3-build-240925fkhcqg263-x86_64.AppImage";
      hash = "sha256-WtfyiNGnUn8g1HR0TQPyn3SMJmjqe+otAYeyokMIO+w=";
    };

    #workaround for https://github.com/getcursor/cursor/issues/837
    postExtract = ''
      substituteInPlace $out/resources/app/out/vs/code/electron-main/main.js \
        --replace ',minHeight' ',frame:false,minHeight'
    '';
  };
in
stdenvNoCC.mkDerivation {
  inherit pname version;

  src = appimageTools.wrapAppImage { inherit version pname src; };

  nativeBuildInputs = [ makeWrapper ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/
    cp -r bin $out/bin

    mkdir -p $out/share/cursor
    cp -a ${src}/locales $out/share/cursor
    cp -a ${src}/resources $out/share/cursor
    cp -a ${src}/usr/share/icons $out/share/
    install -Dm 644 ${src}/cursor.desktop -t $out/share/applications/

    substituteInPlace $out/share/applications/cursor.desktop --replace-fail "AppRun" "cursor"

    wrapProgram $out/bin/cursor \
      --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}} --no-update"

    runHook postInstall
  '';

  passthru.updateScript = writeScript "update.sh" ''
    #!/usr/bin/env nix-shell
    #!nix-shell -i bash -p curl yq coreutils gnused common-updater-scripts
    set -eu -o pipefail
    latestLinux="$(curl -s https://download.todesktop.com/${appKey}/latest-linux.yml)"
    version="$(echo "$latestLinux" | yq -r .version)"
    filename="$(echo "$latestLinux" | yq -r '.files[] | .url | select(. | endswith(".AppImage"))')"
    url="https://download.todesktop.com/${appKey}/$filename"
    currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"')

    if [[ "$version" != "$currentVersion" ]]; then
      hash=$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url "$url")")
      update-source-version code-cursor "$version" "$hash" "$url" --source-key=src.src
    fi
  '';

  meta = {
    description = "AI-powered code editor built on vscode";
    homepage = "https://cursor.com";
    license = lib.licenses.unfree;
    sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
    maintainers = with lib.maintainers; [ sarahec ];
    platforms = [ "x86_64-linux" ];
    mainProgram = "cursor";
  };
}

after wrestling for a few days i hope the maintainer can help

Notify maintainers

@sarahec

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.11.2-cachyos, NixOS, 24.11 (Vicuna), 24.11.20241009.5633bcf`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.8`
 - nixpkgs: `/nix/store/60sn02zhawl3kwn0r515zff3h6hg6ydz-source`

Add a :+1: reaction to issues you find important.

sarahec commented 1 month ago

Thanks for spotting this! I'll update the derivation.

sarahec commented 1 month ago

After digging into the code (and the other 115 packages that use app images), there's no good way to do this. The solution is to push on the cursor team.

I'm sorry I can't fix it from this end.