Skip to content

Instantly share code, notes, and snippets.

@lukalot
Created June 2, 2024 18:58
Show Gist options
  • Save lukalot/fcbf3216ad13b8303ab0947af0d5abd5 to your computer and use it in GitHub Desktop.
Save lukalot/fcbf3216ad13b8303ab0947af0d5abd5 to your computer and use it in GitHub Desktop.
{pkgs, ...}: let
pname = "cursor";
version = "0.32.2";
src = pkgs.fetchurl {
# this will break if the version is updated.
# unfortunately, i couldn't seem to find a url that
# points to a specific version.
# alternatively, download the appimage manually and
# include it via src = ./cursor.AppImage, instead of fetchurl
url = "https://download.cursor.sh/linux/appImage/x64";
hash = "sha256-q2aQWMUp6Ay5kThrH/QSAFozz8IRqzySOcsM9Cy/vKo=";
};
appimageContents = pkgs.appimageTools.extract {inherit pname version src;};
in
with pkgs;
appimageTools.wrapType2 {
inherit pname version src;
extraInstallCommands = ''
install -m 444 -D ${appimageContents}/${pname}.desktop -t $out/share/applications
substituteInPlace $out/share/applications/${pname}.desktop \
--replace 'Exec=AppRun' 'Exec=${pname}'
cp -r ${appimageContents}/usr/share/icons $out/share
# unless linked, the binary is placed in $out/bin/cursor-someVersion
ln -s $out/bin/${pname}-${version} $out/bin/${pname}
'';
extraBwrapArgs = [
"--bind-try /etc/nixos/ /etc/nixos/"
];
# vscode likes to kill the parent so that the
# gui application isn't attached to the terminal session
dieWithParent = false;
extraPkgs = pkgs: [
unzip
autoPatchelfHook
asar
# override doesn't preserve splicing https://github.com/NixOS/nixpkgs/issues/132651
(buildPackages.wrapGAppsHook.override {inherit (buildPackages) makeWrapper;})
];
}
@lukalot
Copy link
Author

lukalot commented Jun 2, 2024

This Nix pkg will enable the installation and use of Cursor on NixOS as a package when adding systemPackages = [ (callPackage ./cursorsh.nix {}) ]; to your configuration.nix packages list.

@snorreks
Copy link

Thank you! I have updated the code to work with 0.35.0. The url is now downloader and not download. I also change the behaviour of handling symlink:

# Code from https://gist.github.com/lukalot/fcbf3216ad13b8303ab0947af0d5abd5
{pkgs, ...}: let
  pname = "cursor";
  version = "0.35.0";

  src = pkgs.fetchurl {
    # this will break if the version is updated.
    # unfortunately, i couldn't seem to find a url that
    # points to a specific version.
    # alternatively, download the appimage manually and
    # include it via src = ./cursor.AppImage, instead of fetchurl
    url = "https://downloader.cursor.sh/linux/appImage/x64";
    hash = "sha256-Fsy9OVP4vryLHNtcPJf0vQvCuu4NEPDTN2rgXO3Znwo=";
  };
  appimageContents = pkgs.appimageTools.extract {inherit pname version src;};
in
  with pkgs;
    appimageTools.wrapType2 {
      inherit pname version src;

      extraInstallCommands = ''
        install -m 444 -D ${appimageContents}/${pname}.desktop -t $out/share/applications
        substituteInPlace $out/share/applications/${pname}.desktop \
          --replace-quiet 'Exec=AppRun' 'Exec=${pname}'
        cp -r ${appimageContents}/usr/share/icons $out/share

        # Ensure the binary exists and create a symlink if it doesn't already exist
        if [ -e ${appimageContents}/AppRun ]; then
          install -m 755 -D ${appimageContents}/AppRun $out/bin/${pname}-${version}
          if [ ! -L $out/bin/${pname} ]; then
            ln -s $out/bin/${pname}-${version} $out/bin/${pname}
          fi
        else
          echo "Error: Binary not found in extracted AppImage contents."
          exit 1
        fi
      '';

      extraBwrapArgs = [
        "--bind-try /etc/nixos/ /etc/nixos/"
      ];

      # vscode likes to kill the parent so that the
      # gui application isn't attached to the terminal session
      dieWithParent = false;

      extraPkgs = pkgs: [
        unzip
        autoPatchelfHook
        asar
        # override doesn't preserve splicing https://github.com/NixOS/nixpkgs/issues/132651
        (buildPackages.wrapGAppsHook.override {inherit (buildPackages) makeWrapper;})
      ];
    }

@lukalot
Copy link
Author

lukalot commented Aug 20, 2024

tysm @snorreks!

@pmarreck
Copy link

pmarreck commented Aug 28, 2024

one of Cursor's dependencies seems to be failing to build locally:

error: hash mismatch in fixed-output derivation '/nix/store/vw3j9ni4vhphgssa9m0aic1nwkrsj9kb-x64.drv':
         specified: sha256-Fsy9OVP4vryLHNtcPJf0vQvCuu4NEPDTN2rgXO3Znwo=
            got:    sha256-TPCJxrXFfatKDv5XrE8nqGFIE/KKi1aUZ/uUtIeIgxc=
error: 1 dependencies of derivation '/nix/store/k2li5zbw7dmfmbadvp0ym8rjf44k3qpm-cursor-0.35.0-extracted.drv' failed to build
error: 1 dependencies of derivation '/nix/store/rfwdgyz1b0m2kr85dyhlvvdg5lxwlszk-cursor-0.35.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/96lzlmcmqlfbkbarj8ny0g8i1pddl0hs-system-path.drv' failed to build

EDIT: Nevermind, this hash config currently works:

  src = pkgs.fetchurl {
    # this will break if the version is updated.
    # unfortunately, i couldn't seem to find a url that
    # points to a specific version.
    # alternatively, download the appimage manually and
    # include it via src = ./cursor.AppImage, instead of fetchurl
    url = "https://downloader.cursor.sh/linux/appImage/x64";
    sha256 = "05w3i23v957vcya5d2way89lhqd84x7sqmzy1r5anzf5np38kw2c";
  };

@deej81
Copy link

deej81 commented Sep 2, 2024

now working with:

src = pkgs.fetchurl {
    # this will break if the version is updated.
    # unfortunately, i couldn't seem to find a url that
    # points to a specific version.
    # alternatively, download the appimage manually and
    # include it via src = ./cursor.AppImage, instead of fetchurl
    url = "https://downloader.cursor.sh/linux/appImage/x64";
    hash = "sha256-qF9vqfvGRGDJ4dZxYzvRFdIKxt6ieiQXupPiOzkF4us=";
  };

@mwmdev
Copy link

mwmdev commented Oct 8, 2024

The code-cursor package is now available in the unstable channel.

@just-a-stream
Copy link

Hey @mwmdev, any idea why I get a build failure when attempting to use it?

image

Thanks!

@mwmdev
Copy link

mwmdev commented Oct 10, 2024

Hi @just-a-stream, it's probably because you need to specify to run it from the unstable channel.

Try this:

nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
nix-channel --update
export NIXPKGS_ALLOW_UNFREE=1 # add this to avoid non-free package error
nix-shell -I nixpkgs=channel:nixos-unstable -p code-cursor

@just-a-stream
Copy link

Thanks for the quick response @mwmdev, it's much appreciated!

I'm currently using unstable via flakes:
image

πŸ€”

@aspauldingcode
Copy link

by the way this is probably depricated now.
In addition, I've added support for cursor for aarch64-linux, and both darwin architectures to mainline nixpkgs, pending merge PR: NixOS/nixpkgs#374944

@chicken-suop
Copy link

chicken-suop commented Feb 12, 2025

Future readers might find this useful. I was using the code-cursor package, but I wanted to use the latest unstable version only for code-cursor.

I created a /etc/nixos/flake.nix file:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs, nixpkgs-unstable, ... }@inputs: {
    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [ ./configuration.nix ];
      specialArgs = { inherit inputs; };
    };
  };
}

Then I updated my /etc/nixos/configuration.nix:

{ config, pkgs, inputs, ... }:

let
  unstable = import inputs.nixpkgs-unstable {
    system = "x86_64-linux";
    config.allowUnfree = true;
  };
in {

  environment.systemPackages = with pkgs; [
    git # Normal packages use 24.11
    unstable.code-cursor # Only code-cursor uses unstable version
  ];

  # ...other settings

  system.stateVersion = "24.11";
}

Then I run this ~/update.sh script to update:

#!/usr/bin/env bash
set -euo pipefail

echo "πŸš€ Starting system update..."

# Clean up old generations
sudo nix-collect-garbage --delete-older-than 14d

# Update flake inputs with explicit directory context
echo "πŸ”„ Updating flake inputs..."
sudo bash -c "cd /etc/nixos && nix flake update"

# Rebuild system
echo "πŸ”¨ Rebuilding system..."
sudo nixos-rebuild boot --flake "/etc/nixos#nixos" # Change 'nixos' to your hostname

# Update Flatpak
echo "πŸ“¦ Updating Flatpak..."
flatpak update -y

echo "βœ… Update complete!"
notify-send "System Updated" "All updates applied successfully"

@aspauldingcode
Copy link

by the way this is probably depricated now.
In addition, I've added support for cursor for aarch64-linux, and both darwin architectures to mainline nixpkgs, pending merge PR: NixOS/nixpkgs#374944

This pr has merged and code-cursor package now supports macOS and arch64 linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment