Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cursor -> add platforms #373494

Closed

Conversation

aspauldingcode
Copy link
Contributor

@aspauldingcode aspauldingcode commented Jan 13, 2025

Supercedes #371208
Supercedes #371260

Things done

Added Darwin x86/aarch64 to sources
Added corresponding build and install functions
Added Darwin downloads to update script
Added self to maintainers

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@aspauldingcode aspauldingcode marked this pull request as draft January 13, 2025 15:59
@aspauldingcode
Copy link
Contributor Author

@sarahec I've made changes here.

@aspauldingcode
Copy link
Contributor Author

Screenshot 2025-01-13 at 8 10 26 AM

So, I just tried to git commit --amend a previous commit so I could nixfmt the cursor package.nix and pass a formatting test there. But, I ran into it telling me that there were changed upstream that I needed to pull, so I pulled with rebase true. I don't even know if that's what I was supposed to do, but I did it anyway and it seems to be okay with git log master..cursor-add-platforms

  ~/nixpkgs  ⎇ cursor-add-platforms ≡  zsh  git log master..cursor-add-platforms

commit 59dabeb63027072a4fe3badaace58089a3c83c9b (HEAD -> cursor-add-platforms, origin/cursor-add-platforms)
Author: aspauldingcode <[email protected]>
Date:   Mon Jan 13 07:58:07 2025 -0800

    cursor -> add platforms

@sarahec sarahec added the 12. first-time contribution This PR is the author's first one; please be gentle! label Jan 13, 2025
@sarahec
Copy link
Contributor

sarahec commented Jan 13, 2025

I just tried to git commit --amend a previous commit so I could nixfmt the cursor package.nix and pass a formatting test there.

Once you push a commit, you can't append to it. So what you do is use git rebase -i ~2 to see the pushed commit and your "fix it" commit, mark the top (latest) commit as fixup (squash, keep old description), and git push --force-with-lease.

If you look at the top of the PR, you'll see a tab labeled "Commits: 2". If you click on that tab, you'll see both of them listed. So follow the instructions in the previous paragraph to rebase, fixup, and force push so you only have one commit.

P.S. I'm planning to submit a PR today that includes your sources list and automatically updates all of the entries. Once it merges, you can rebase on top of it.

@sarahec
Copy link
Contributor

sarahec commented Jan 13, 2025

Let's wait for #373536 to be merged then we can update master and rebase your branch atop it.

In the meantime, take a look at what I've done. Instead of needing if/then/else in function bodies, you'll define your own functions for unpacking the dmg and installing it, then we'll assign with: installPhase = ${if stdenvNoCC.isDarwin then dmgInstall else appimageInstall}; and likewise for src.

P.S. Since these are all function bodies, they're lazily evaluated.

@aspauldingcode
Copy link
Contributor Author

Looks like my aarch64-linux hashes and appImage link were correct. Hooray!
I still haven't tested x86_64-darwin, but I'm pretty sure it's correct too.

@bet4it
Copy link

bet4it commented Jan 14, 2025

$ nix-build -E 'with import <nixpkgs> {}; callPackage ./package.nix {}'                                                                                       
this derivation will be built:
  /nix/store/zymm6w6y1f9h0f546ckzxvr1fzba2y9c-cursor-0.44.11.drv
building '/nix/store/zymm6w6y1f9h0f546ckzxvr1fzba2y9c-cursor-0.44.11.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/lg8xj14zdkgpydkkz9vbizb3gkvldqzi-cursor-0.44.11-build-250103fqxdt5u9z-arm64.AppImage
do not know how to unpack source archive /nix/store/lg8xj14zdkgpydkkz9vbizb3gkvldqzi-cursor-0.44.11-build-250103fqxdt5u9z-arm64.AppImage
error: builder for '/nix/store/zymm6w6y1f9h0f546ckzxvr1fzba2y9c-cursor-0.44.11.drv' failed with exit code 1

Why I get this?

@sarahec
Copy link
Contributor

sarahec commented Jan 15, 2025

Let's wait for #373536 to be merged then we can update master and rebase your branch atop it.

My PR was merged (#373536) and your maintainers entry was merged (#373489), so we can build on them!

Bring your branch up to date

git checkout master
git fetch upstream master
git checkout cursor-add-platforms
git rebase master

You will get some merge conflicts in this file. You'll fix them as we reorganize the file.

Integrate your changes

  1. Copy the Darwin URLs into sources. Notice that I've called fetchurl for the two linux ones -- you need fetchurl for the automatic update mechanism to work.
  2. Copy your Darwin install script into the let block as something like:
darwinInstallPhase = ''
      runHook preInstall
      mkdir -p $out/Applications
      cp -r *.app $out/Applications/
      runHook postInstall
'';
  1. Likewise, add darwinUnpackPhase with the code to unpack the .dmg file.
  2. Inside the mkDerivation block, edit installPhase: installPhase = ${if stdenvNoCC.isDarwin then dmgInstall else appimageInstall}; and likewise for src.
  3. Add the two Darwin types to the list of supported systems
  4. Inside the update script:
    a. Add lines to get the Darwin filename and version
    b. If the versions don't match, exit
    c. Add a line to extract the Darwin partial URL (You should be able to copy the linux one)
    d. Fill in the if/elseif chain for your two darwin platforms
  5. Add yourself as a maintainer
  6. Clean up any remaining conflicts.

@sarahec
Copy link
Contributor

sarahec commented Jan 15, 2025

Why I get this?

@bet4it This PR isn't ready yet.

If you have a current copy of nixpkgs checked out, you can cd into it and run nix-build -A code-cursor to get your arm64 build.

Otherwise, watch https://nixpk.gs/pr-tracker.html?pr=373536 and you can use the package once it reaches the nixpkgs-unstable branch.

P.S. Did you file a bug on the startup issue you saw? I need the information to figure out if the bug is in the packaging (nixpkgs) or whether it has to be fixed by cursor themselves.

@aspauldingcode
Copy link
Contributor Author

Screenshot 2025-01-15 at 6 06 33 PM I don't think I've ever been more confused in my life

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 16, 2025
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 16, 2025
@aspauldingcode
Copy link
Contributor Author

Okay, looks like I've done it or done something. @sarahec can you check and see if any of what I did looks ok?

@sarahec
Copy link
Contributor

sarahec commented Jan 16, 2025

I need you to merge the two commits:

  1. Make your change I suggested and commit it. Now you have three commits.
  2. git rebase -i HEAD~3 to rebase the last three commits
  3. Change the first two commits from pick to squash, then save and exit the text editor
  4. You'll be asked to edit the commit message. I recommend `code-cursor: add darwin support {x86,aarch64}

Then git push --force-with-lease

After that, it's time to update the long commit message at the top of this page:

  1. Uncheck all platforms, then only check the ones you have built and run the app on from this PR. (Build: NIXPKGS_ALLOW_UNFREE=1 nix-build -A code-cursor. The last line will look like this: /nix/store/zrgx0yk46gyg13mfvybizkx5z002gli1-cursor-0.44.11 and you will add /bin/cursor to it like so: /nix/store/zrgx0yk46gyg13mfvybizkx5z002gli1-cursor-0.44.11/bin/cursor. That should launch the app.
  2. Check "Tested, if applicable" at the top of this screen
  3. Run nix-shell -p nixpkgs-review --run "NIXPKGS_ALLOW_UNFREE=1 nixpkgs-review pr 373494 --post-result" to build this package, anything that depends on it (nothing), and post the results of that compilation to this thread.
  4. Now check "Tested compilation of all packages..." at the top of this page.
  5. If you built and ran the app in step 1, check "Tested basic functionality of all binary files" at the top of this page.
  6. Skip the release notes entry.
  7. Check "Fits CONTRIBUTING.md" at the top of the page. (I've walked you through all the appropriate steps).
  8. Now edit the message at the top of the page to begin with:
Added Darwin x86/aarch664 to sources
Added corresponding build and install functions
Added Darwin downloads to update script
Added self to maintainers

and remember to save it. (There will be a save button below the long text box).

Finally, click the circular arrows next to my username under Reviewers. That re-requests a review.

While you're doing that, I'll test the update script.

@sarahec
Copy link
Contributor

sarahec commented Jan 16, 2025

I'm still testing and making changes to the update script. The spaces/%20 in the mac URLs are causing problems. I'll get it sorted out.

P.S. I keep running into one problem with the Darwin URLs. I'm going to take a fresh look at it in the morning. (I think sed is doing the wrong thing when extracting the stem.)

@aspauldingcode
Copy link
Contributor Author

I need you to merge the two commits:

1. Make your change I suggested and commit it. Now you have three commits.

2. `git rebase -i HEAD~3` to rebase the last three commits

I don't seem to have this quite right. I had too many, I tried to squash several of mine into the latest and accidentally committed changes to the other ones I didn't partake.

pick 59155b95914e devede: 4.17.0 → 4.19.0
pick effda74e948c bundletool: 1.17.2 → 1.18.0
pick 6eae496f0445 cirrus-cli: 0.133.2 → 0.134.0
pick 241e340e28e6 cursor → add darwin, modify update script, add maintainer
s 8b035ca8afff formatted nixfmt
s df6d5105d03c cursor → add darwin, modify update script, add maintainer
s 2c0859ae7e71 formatted nixfmt
s b17fb21b484d Update pkgs/by-name/co/code-cursor/package.nix
s 322dcc4a4228 Update pkgs/by-name/co/code-cursor/package.nix
s 1d61bfb24673 Update pkgs/by-name/co/code-cursor/package.nix
s ab6658e342b6 Update pkgs/by-name/co/code-cursor/package.nix
Screenshot 2025-01-15 at 10 58 06 PM

@aspauldingcode
Copy link
Contributor Author

I don't seem to have this quite right. I had too many

Wait I think I fixed it. Sorry. This is a wild ride for me. First time trying to git with any other project. Literally a noob right now but its ok

Copy link
Contributor

@sarahec sarahec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out we should be using buildPlatform

@sarahec sarahec added the 6.topic: darwin Running or building packages on Darwin label Jan 17, 2025
@sarahec
Copy link
Contributor

sarahec commented Jan 17, 2025

I discovered it wouldn't build on any platform and traced it down to the incorrect stdenvNoCC.isDarwin/stdenvNoCC.isDarwin. We need to get either the hostPlatform or the buildPlatform from stdenv before asking what it is. (My bad -- I suggested the short form to you.)

Importing buildPlatform from stdenvNoCC makes the rest of the code tidier.

Also fixed a couple of stylistic nits.

@aspauldingcode
Copy link
Contributor Author

I can't merge the commits atm but it's committed (from phone). Hope it works :) can you check again? @sarahec

@github-actions github-actions bot added 10.rebuild-linux: 1-10 and removed 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jan 18, 2025
@aspauldingcode
Copy link
Contributor Author

Whoops looks like we broke it again

Copy link
Contributor

@sarahec sarahec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$badword. I gave you a bad suggestion. Here's a replacement.

@aspauldingcode
Copy link
Contributor Author

Looks like I gotta format it again.

@sarahec
Copy link
Contributor

sarahec commented Jan 18, 2025

Ugh. Looks like we may need to rearrange files a fair bit to make this work. Would you be willing to add me as an editor to your nixpkgs fork so I can just drop the changes in?

What needs to change:

  1. Update.sh becomes its own file
  2. At the end of the let, we'll add if hostPlatform.isLinux then linux-specific mkDerivation else darwin-specific mkDerivation
  3. meta remains the same.

I wish I had thought of this earlier! A search through nixpkgs shows this is how others do it.

@sarahec
Copy link
Contributor

sarahec commented Jan 18, 2025

I have good news and bad news. The good news: it works, it's clean, and it's easy to read and modify. The bad news: it's now four files (package.nix, update.sh, linux.nix, darwin.nix) and since I made some big changes I'll want to pull in another reviewer or two.

P.S. Would it be easier if I submitted this as a new PR and credited you?

package.nix

{
  lib,
  stdenvNoCC,
  fetchurl,
  callPackage,
}:

let
  pname = "cursor";
  version = "0.44.11";

  inherit (stdenvNoCC) hostPlatform;

  sources = {
    x86_64-linux = fetchurl {
      url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.44.11-build-250103fqxdt5u9z-x86_64.AppImage";
      hash = "sha256-eOZuofnpED9F6wic0S9m933Tb7Gq7cb/v0kRDltvFVg=";
    };
    aarch64-linux = fetchurl {
      url = "https://download.todesktop.com/230313mzl4w4u92/cursor-0.44.11-build-250103fqxdt5u9z-arm64.AppImage";
      hash = "sha256-mxq7tQJfDccE0QsZDZbaFUKO0Xc141N00ntX3oEYRcc=";
    };
    x86_64-darwin = fetchurl {
      url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.44.11%20-%20Build%20250103fqxdt5u9z-x64.dmg";
      hash = "sha256-JKPClcUD2W3KWRlRTomDF4FOOA1DDw3iAQ+IH7yan+E=";
    };
    aarch64-darwin = fetchurl {
      url = "https://download.todesktop.com/230313mzl4w4u92/Cursor%200.44.11%20-%20Build%20250103fqxdt5u9z-arm64.dmg";
      hash = "sha256-0HDnRYfy+jKJy5dvaulQczAoFqYmGGWcdhIkaFZqEPA=";
    };
  };

  source = sources.${hostPlatform.system};

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

in
if hostPlatform.isLinux then
  callPackage ./linux.nix {
    inherit
      sources
      source
      pname
      version
      meta
      ;
  }
else
  callPackage ./darwin.nix {
    inherit
      sources
      source
      pname
      version
      meta
      ;
  }

update.sh

Needs the executable bit set: chmod +x update.sh

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl yq coreutils gnused trurl common-updater-scripts
set -eu -o pipefail
baseUrl="https://download.todesktop.com/230313mzl4w4u92"
latestLinux="$(curl -s $baseUrl/latest-linux.yml)"
latestDarwin="$(curl -s $baseUrl/latest-mac.yml)"
linuxVersion="$(echo "$latestLinux" | yq -r .version)"

currentVersion=$(nix-instantiate --eval -E "with import ./. {}; code-cursor.version or (lib.getVersion code-cursor)" | tr -d '"')

if [[ "$linuxVersion" != "$currentVersion" ]]; then
    darwinVersion="$(echo "$latestDarwin" | yq -r .version)"
    if [ "$linuxVersion" != "$darwinVersion" ]; then
        echo "Linux version ($linuxVersion) and Darwin version ($darwinVersion) do not match"
        exit 1
    fi
    version="$linuxVersion"

    linuxFilename="$(echo "$latestLinux" | yq -r '.files[] | .url | select(. | endswith(".AppImage"))' | head -n 1)"
    linuxStem="$(echo "$linuxFilename" | sed -E s/^\(.+build.+\)-[^-]+AppImage$/\\1/)"

    darwinFilename="$(echo "$latestDarwin" | yq -r '.files[] | .url | select(. | endswith(".dmg"))' | head -n 1)"
    darwinStem="$(echo "$darwinFilename" | sed -E s/^\(.+Build[^-]+\)-.+dmg$/\\1/)"

    for platform in  "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"; do
        if [ $platform = "x86_64-linux" ]; then
            url="$baseUrl/$linuxStem-x86_64.AppImage"
        elif [ $platform = "aarch64-linux" ]; then
            url="$baseUrl/$linuxStem-arm64.AppImage"
        elif [ $platform = "x86_64-darwin" ]; then
            url="$baseUrl/$darwinStem-x64.dmg"
        elif [ $platform = "aarch64-darwin" ]; then
            url="$baseUrl/$darwinStem-arm64.dmg"
        else
            echo "Unsupported platform: $platform"
            exit 1
        fi

        url=$(trurl --accept-space "$url")
        hash=$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url "$url")")
        update-source-version code-cursor $version $hash $url --system=$platform --ignore-same-version --source-key="sources.$platform"
    done
fi

linux.nix

{
  stdenvNoCC,
  appimageTools,
  makeWrapper,
  sources,
  source,
  pname,
  version,
  meta,
}:
let
  appimageContents = appimageTools.extractType2 {
    inherit version pname;
    src = source;
  };
in
stdenvNoCC.mkDerivation rec {
  inherit pname version meta;

  src = appimageTools.wrapType2 {
    inherit version pname;
    src = source;
  };

  nativeBuildInputs = [ makeWrapper ];

  installPhase = ''
    runHook preInstall

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

    mkdir -p $out/share/cursor
    cp -a ${appimageContents}/locales $out/share/cursor
    cp -a ${appimageContents}/resources $out/share/cursor
    cp -a ${appimageContents}/usr/share/icons $out/share/
    install -Dm 644 ${appimageContents}/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 --enable-wayland-ime=true}} --no-update"

    runHook postInstall
  '';

  passthru = {
    inherit sources;
    updateScript = ./update.sh;
  };
}

darwin.nix

{
  stdenvNoCC,
  undmg,
  sources,
  source,
  pname,
  version,
  meta,
}:

stdenvNoCC.mkDerivation {
  inherit pname version meta;

  src = source;

  sourceRoot = ".";

  nativeBuildInputs = [ undmg ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/Applications
    cp -r *.app $out/Applications/

    mkdir -p "$out/bin"
    cat << EOF > "$out/bin/cursor"
    open -na '$APP_DIR' --args "\$@"
    EOF
    chmod +x "$out/bin/cursor"
    runHook postInstall
  '';

  passthru = {
    inherit sources;
    updateScript = ./update.sh;
  };
}

formatted nixfmt

cursor -> add darwin, modify update script, add maintainer

formatted nixfmt

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

I missed that, thanks

Co-authored-by: Sarah Clark <[email protected]>

add myself as a maintainer

modify update script.

fix src = source;

cursor -> add darwin, modify update script, add maintainer

formatted nixfmt

cursor -> add darwin, modify update script, add maintainer

formatted nixfmt

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

I missed that, thanks

Co-authored-by: Sarah Clark <[email protected]>

add myself as a maintainer

modify update script.

fix src = source;

tidying up the code

Co-authored-by: Sarah Clark <[email protected]>

set back to src instead of source

Co-authored-by: Sarah Clark <[email protected]>

tell it we don't need a build phase

Co-authored-by: Sarah Clark <[email protected]>

use singular form lib.optional and fix spelling

Co-authored-by: Sarah Clark <[email protected]>

inherit src

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update pkgs/by-name/co/code-cursor/package.nix

Co-authored-by: Sarah Clark <[email protected]>

Update package.nix

Co-authored-by: Sarah Clark <[email protected]>

again, format
@aspauldingcode
Copy link
Contributor Author

@sarahec I've set you as collaborator on my fork.

@aspauldingcode
Copy link
Contributor Author

P.S. Would it be easier if I submitted this as a new PR and credited you?

if that works for you that's fine too?

@sarahec
Copy link
Contributor

sarahec commented Jan 19, 2025

I've opened a new PR as I still couldn't push into your fork. (Sorry. I'm making sure you get credit for your work.)

Superseded by #374944

@sarahec sarahec closed this Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: darwin Running or building packages on Darwin 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 12. first-time contribution This PR is the author's first one; please be gentle!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants