This commit is contained in:
TudorAndrei
2025-10-08 17:05:57 +03:00
parent 25890c7958
commit 536b9d4b53
9 changed files with 482 additions and 1018 deletions
+154
View File
@@ -0,0 +1,154 @@
name: Update Cursor Version
on:
schedule:
- cron: '0 12 * * *' # Run daily at 12:00 UTC
workflow_dispatch: # Allow manual triggering
jobs:
update-cursor:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Nix
uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixpkgs-unstable
- name: Install dependencies
run: |
nix-env -iA nixpkgs.curl nixpkgs.jq nixpkgs.nix-prefetch-url
- name: Get latest Cursor version
id: get_version
run: |
set -euo pipefail
# Get the latest version from Cursor's API redirect with retries
for i in {1..3}; do
echo "Attempt $i: Fetching latest version from Cursor API..."
if REDIRECT_URL=$(curl -s -I --max-time 30 "https://api2.cursor.sh/updates/download/golden/linux-x64/cursor/latest" | grep -i location | cut -d' ' -f2 | tr -d '\r\n' 2>/dev/null); then
if [[ -n "$REDIRECT_URL" ]]; then
# Extract version from URL like: .../Cursor-1.7.39-x86_64.AppImage
LATEST_VERSION=$(echo "$REDIRECT_URL" | grep -o 'Cursor-[0-9]\+\.[0-9]\+\.[0-9]\+' | sed 's/Cursor-//' 2>/dev/null)
if [[ -n "$LATEST_VERSION" ]]; then
echo "Latest version: $LATEST_VERSION"
echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT
break
fi
fi
fi
if [[ $i -eq 3 ]]; then
echo "Error: Failed to fetch latest version after 3 attempts"
exit 1
fi
echo "Retrying in 10 seconds..."
sleep 10
done
# Get current version from flake.nix
CURRENT_VERSION=$(grep -o 'version = "[^"]*"' flake.nix | head -1 | cut -d'"' -f2)
echo "Current version: $CURRENT_VERSION"
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Check if update is needed
id: check_update
run: |
if [ "${{ steps.get_version.outputs.version }}" != "${{ steps.get_version.outputs.current_version }}" ]; then
echo "update_needed=true" >> $GITHUB_OUTPUT
echo "Update needed: ${{ steps.get_version.outputs.current_version }} -> ${{ steps.get_version.outputs.version }}"
else
echo "update_needed=false" >> $GITHUB_OUTPUT
echo "No update needed. Current version is up to date."
fi
- name: Update flake.nix
if: steps.check_update.outputs.update_needed == 'true'
run: |
set -euo pipefail
VERSION="${{ steps.get_version.outputs.version }}"
# Construct the download URL for the AppImage
APPIMAGE_URL="https://api2.cursor.sh/updates/download/golden/linux-x64/cursor/$VERSION"
echo "Fetching AppImage from: $APPIMAGE_URL"
# Get the actual download URL by following redirects
ACTUAL_URL=$(curl -s -I "$APPIMAGE_URL" | grep -i location | cut -d' ' -f2 | tr -d '\r\n')
if [[ -z "$ACTUAL_URL" ]]; then
echo "Error: Could not get actual download URL"
exit 1
fi
echo "Actual download URL: $ACTUAL_URL"
# Get the SHA256 hash with retries
for i in {1..3}; do
echo "Attempt $i: Calculating SHA256 hash..."
if SHA256=$(nix-prefetch-url --type sha256 "$ACTUAL_URL" 2>/dev/null); then
if [[ "$SHA256" != "" && ${#SHA256} -eq 52 ]]; then
echo "SHA256: $SHA256"
break
fi
fi
if [[ $i -eq 3 ]]; then
echo "Error: Failed to calculate SHA256 after 3 attempts"
exit 1
fi
echo "Retrying in 5 seconds..."
sleep 5
done
# Create backup
cp flake.nix flake.nix.backup
# Update flake.nix with new version and hash - be more specific to avoid replacing nixpkgs URL
sed -i "s/version = \"[^\"]*\" # Will be updated by GitHub Actions/version = \"$VERSION\"/" flake.nix
sed -i "/buildCursor = {/,/};/s|url = \"[^\"]*\"|url = \"$ACTUAL_URL\"|" flake.nix
sed -i "/buildCursor = {/,/};/s/sha256 = \"[^\"]*\"/sha256 = \"$SHA256\"/" flake.nix
echo "Updated flake.nix with version $VERSION"
- name: Test the updated flake
if: steps.check_update.outputs.update_needed == 'true'
run: |
nix flake check
nix build .#cursor --dry-run
- name: Commit and push changes
if: steps.check_update.outputs.update_needed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add flake.nix
git commit -m "Update Cursor to version ${{ steps.get_version.outputs.version }}"
git push
- name: Create release
if: steps.check_update.outputs.update_needed == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "cursor-${{ steps.get_version.outputs.version }}"
release_name: "Cursor ${{ steps.get_version.outputs.version }}"
body: |
Automated update to Cursor version ${{ steps.get_version.outputs.version }}
Changes:
- Updated version to ${{ steps.get_version.outputs.version }}
- Updated download URL and SHA256 hash
- Tested flake build
draft: false
prerelease: false
-214
View File
@@ -1,214 +0,0 @@
# Comprehensive Solution for Cursor AppImage Native Module Issues on NixOS
## Problem Summary
When using Cursor 1.4.2 as an AppImage in a NixOS flake, users encounter errors related to native modules not being found:
```
Error: Cannot find module './build/Debug/keymapping'
```
This issue occurs because the AppImage contains pre-compiled native modules that expect to find certain libraries in specific locations, but NixOS has a different filesystem structure that doesn't match these expectations.
## Root Cause Analysis
The problem is multifaceted:
1. **Library Path Issues**: Native modules in the AppImage can't find required system libraries
2. **Environment Variable Mismatch**: Electron applications expect certain environment variables to be set
3. **Sandboxing Conflicts**: NixOS sandboxing interferes with AppImage's assumptions about the filesystem
4. **Keyboard Mapping Dependencies**: The `native-keymap` module specifically requires X11 keyboard libraries
## Solution Overview
The solution involves modifying the Cursor wrapper in `home.nix` to:
1. Add missing system libraries to the library path
2. Set appropriate environment variables for Electron applications
3. Use AppImage extraction mode to avoid sandbox issues
4. Add proper flags to handle GPU and sandboxing issues
## Implementation
### Updated Cursor Wrapper Configuration
Here's the complete updated `cursorAppImage` section for your `home.nix`:
```nix
let
# Cursor 1.4.2 AppImage wrapper with enhanced compatibility and update handling
cursorAppImage = pkgs.writeShellScriptBin "cursor" ''
# Set up environment for better AppImage compatibility
export APPDIR=""
export ARGV0=""
export OWD=""
# Disable Cursor's auto-update mechanism to prevent crashes
export CURSOR_DISABLE_UPDATE="1"
export CURSOR_SKIP_UPDATE_CHECK="1"
# Ensure proper library paths
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath [
pkgs.glib
pkgs.gtk3
pkgs.cairo
pkgs.pango
pkgs.atk
pkgs.gdk-pixbuf
pkgs.xorg.libX11
pkgs.xorg.libXcomposite
pkgs.xorg.libXcursor
pkgs.xorg.libXext
pkgs.xorg.libXfixes
pkgs.xorg.libXi
pkgs.xorg.libXrandr
pkgs.xorg.libXrender
pkgs.xorg.libXtst
pkgs.nss
pkgs.nspr
pkgs.dbus
pkgs.at-spi2-atk
pkgs.at-spi2-core
pkgs.mesa
pkgs.alsa-lib
pkgs.fuse
pkgs.libxkbcommon # Added for keyboard mapping support
pkgs.libxkbfile # Added for keyboard mapping support
]}:$LD_LIBRARY_PATH"
# Set additional environment variables to handle keymapping and native module issues
export ELECTRON_DISABLE_SECURITY_WARNINGS="1"
export ELECTRON_NO_ATTACH_CONSOLE="1"
export ELECTRON_RUN_AS_NODE="0"
# Additional environment variables for native module compatibility
export NODE_OPTIONS="--no-warnings"
export NODE_ENV="production"
export ELECTRON_ENABLE_LOGGING="false"
export ELECTRON_DISABLE_SECURITY_WARNINGS="true"
# Fix for native keymap module issues
export XDG_CACHE_HOME="/tmp/cursor-xdg-cache-$$"
mkdir -p "$XDG_CACHE_HOME"
# Create a temporary directory for Cursor's cache to avoid permission issues
export CURSOR_CACHE_DIR="/tmp/cursor-cache-$$"
mkdir -p "$CURSOR_CACHE_DIR"
# Additional fixes for AppImage native modules
export APPIMAGE_EXTRACT_AND_RUN="1"
# Run the AppImage with appimage-run and additional flags
exec ${pkgs.appimage-run}/bin/appimage-run \
--no-sandbox \
--appimage-extract-and-run \
${pkgs.fetchurl {
url = "https://downloads.cursor.com/production/07aa3b4519da4feab4761c58da3eeedd253a1671/linux/x64/Cursor-1.4.2-x86_64.AppImage";
sha256 = "0gb89li1aklzgc9h8y5rlrnk0n6sb4ikahaml4r9kr6ixadc4b1a";
}} \
--disable-updates \
--no-update-check \
--disable-gpu-sandbox \
--disable-dev-shm-usage \
"$@"
'';
```
## Key Changes Explained
### 1. Additional Libraries
- **libxkbcommon** and **libxkbfile**: Essential for keyboard mapping functionality
- These libraries were missing from the original configuration and are required by the `native-keymap` module
### 2. Environment Variables
- **ELECTRON_RUN_AS_NODE="0"**: Ensures Electron runs in application mode rather than Node.js mode
- **NODE_OPTIONS="--no-warnings"**: Reduces noise in the console output
- **NODE_ENV="production"**: Optimizes Node.js behavior for production use
- **XDG_CACHE_HOME**: Provides a writable cache directory for the application
### 3. AppImage Execution Mode
- **APPIMAGE_EXTRACT_AND_RUN="1"**: Forces extraction mode which avoids many sandboxing issues
- **--appimage-extract-and-run**: Command line flag that does the same thing
### 4. Additional Electron Flags
- **--disable-gpu-sandbox**: Reduces GPU-related sandboxing issues
- **--disable-dev-shm-usage**: Avoids issues with shared memory in containers/sandboxed environments
## Testing Plan
### Prerequisites
1. Updated `home.nix` file with the new Cursor wrapper configuration
2. Working NixOS system with flakes enabled
3. Sudo access to rebuild the system
### Testing Steps
1. **Apply Configuration Changes**
- Replace the existing `cursorAppImage` section in `home.nix`
- Save the file
2. **Rebuild the System**
```bash
sudo nixos-rebuild switch --flake .#cursor-system
```
3. **Test Basic Functionality**
```bash
cursor --version
```
4. **Test GUI Launch**
```bash
cursor
```
5. **Test Keyboard Functionality**
- Type in the editor
- Test keyboard shortcuts
- Try different keyboard layouts if applicable
### Success Criteria
The fix is successful if:
- [ ] `cursor --version` runs without errors
- [ ] Cursor GUI launches without keymapping errors
- [ ] Keyboard input works normally in the editor
- [ ] No native module loading errors in the console
- [ ] All basic functionality works as expected
## Troubleshooting
### If Issues Persist
1. **Clear AppImage Cache**
```bash
rm -rf ~/.cache/appimage-run/*
```
2. **Check System Logs**
```bash
journalctl -xe
```
3. **Run with Debugging**
```bash
cursor --enable-logging --v=1
```
### Rollback Plan
If the updated configuration causes issues:
1. Restore the previous `home.nix` file
2. Rebuild the system:
```bash
sudo nixos-rebuild switch --flake .#cursor-system
```
3. Clear the AppImage cache:
```bash
rm -rf ~/.cache/appimage-run/*
```
## Conclusion
This solution addresses the native module loading issues by providing the missing libraries and environment variables that the AppImage expects. The key insight is that Electron applications packaged as AppImages have specific requirements that don't align with NixOS's unique filesystem structure, and we need to bridge that gap through careful environment configuration.
The changes are backward-compatible and should not introduce any new issues while resolving the existing keymapping errors.
-93
View File
@@ -1,93 +0,0 @@
# Migration to Clean Package-Only Structure
## ✅ Migration Complete
The cursor-flake repository has been successfully migrated from a complex system configuration flake to a clean, focused package-only flake.
## 📁 New Structure
```
cursor-flake/
├── flake.nix # 🎯 Clean package-only flake
├── flake.lock # Flake lock file
├── update-cursor.sh # 🔄 Simple update script
├── README.md # Updated documentation
├── LICENSE # MIT License
└── archive-old-system-configs/ # 📦 Archived old files
├── configuration.nix # (old system config)
├── home.nix # (old home-manager config)
├── flake-old-complex.nix # (old complex flake)
├── update-cursor-hash.sh # (old complex update script)
└── ... # (other archived files)
```
## 🚀 How to Use
### Build Cursor Package
```bash
nix build .#cursor
./result/bin/cursor --version # Should show: 1.5.5
```
### Update to New Version
```bash
./update-cursor.sh "https://downloads.cursor.com/production/[hash]/linux/x64/Cursor-1.6.0-x86_64.AppImage"
```
### Use in Your NixOS System
Add to your main system flake:
```nix
cursor-flake = {
url = "github:yourusername/cursor-flake"; # or "path:/path/to/cursor-flake" for local
inputs.nixpkgs.follows = "nixpkgs";
};
```
Then use:
```nix
environment.systemPackages = [
cursor-flake.packages.x86_64-linux.cursor
];
```
## 🆚 What Changed
### Before (Complex Structure)
- ❌ Mixed package + system configuration
- ❌ Required `nixos-rebuild switch` for testing
- ❌ Risk of breaking system during updates
- ❌ Inconsistent with other flakes
- ❌ Complex update process
### After (Clean Structure)
- ✅ Pure package management
- ✅ Simple `nix build .#cursor` testing
- ✅ No system breaking risk
- ✅ Consistent with ollama-nixos-flake pattern
- ✅ Simple update workflow
## 🔧 Benefits
1. **Safety**: No more system crashes during updates
2. **Simplicity**: Focused on just packaging Cursor
3. **Reusability**: Easy to integrate into any NixOS system
4. **Consistency**: Matches your other package flakes
5. **Maintainability**: Much less code to maintain
## 📦 Archive
All old system configuration files have been preserved in `archive-old-system-configs/` for reference, including:
- The old complex `flake.nix`
- System configuration files
- Home manager configuration
- Old update scripts
## ✨ Current Status
- **Cursor Version**: 1.5.5
- **Structure**: Clean package-only flake
- **Update Script**: `./update-cursor.sh`
- **Build Test**: ✅ Working
- **Version Test**: ✅ Working (reports 1.5.5)
The migration is complete and the flake is ready for production use! 🎉
+86 -160
View File
@@ -1,192 +1,118 @@
# Cursor NixOS Flake
# Self-Updating Cursor Flake
A clean, simple NixOS flake for packaging the [Cursor](https://cursor.sh/) AI-powered code editor.
A Nix flake that provides the Cursor code editor with automatic daily updates via GitHub Actions.
## 📦 What This Flake Provides
## Features
This flake packages Cursor as a Nix package that can be easily integrated into any NixOS system or used standalone.
- 🚀 **Self-updating**: Automatically checks for new Cursor versions daily
- 🔧 **Manual updates**: Local script for immediate updates
- 🛡️ **Robust**: Proper error handling and fallbacks
- 📦 **AppImage-based**: Uses Cursor's official AppImage for maximum compatibility
- 🎯 **Linux x86_64**: Optimized for Linux AMD64 architecture
**Packages:**
- `packages.x86_64-linux.cursor` - The Cursor editor with full desktop integration
- `packages.x86_64-linux.default` - Same as cursor (default package)
**Features:**
-**Complete Desktop Integration** - Includes icon extraction and desktop entry
-**Icon Support** - Automatically extracts and installs Cursor icon from AppImage
-**MIME Type Associations** - Supports opening various file types with Cursor
-**Version Management** - Built-in version checking (`cursor --version`)
-**Update Disabled** - Prevents Cursor's built-in updater (managed by Nix instead)
## 🚀 Quick Start
### Using in Your NixOS Configuration
Add this flake as an input to your main system flake:
```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
cursor-flake = {
url = "path:/path/to/cursor-flake"; # Update this path
inputs.nixpkgs.follows = "nixpkgs";
};
# ... other inputs
};
outputs = { nixpkgs, cursor-flake, ... }: {
nixosConfigurations.your-hostname = nixpkgs.lib.nixosSystem {
# ...
modules = [
./configuration.nix
{
# Add Cursor to your system packages
environment.systemPackages = with pkgs; [
cursor-flake.packages.x86_64-linux.cursor
# ... other packages
];
}
# Or in home-manager:
{
home-manager.users.your-username = { pkgs, ... }: {
home.packages = [
cursor-flake.packages.x86_64-linux.cursor
# ... other packages
];
};
}
];
};
};
}
```
### Standalone Usage
You can also build and run Cursor directly from this flake:
## Quick Start
### Method 1: Direct Installation
```bash
# Build the package
nix build .#cursor
# Install Cursor directly
nix profile install github:your-username/cursor-nixos-flake
# Run Cursor
./result/bin/cursor
# Or run directly without building
nix run .#cursor
cursor --version
```
## 🔄 Updating Cursor
### Method 2: Add to Your Flake
Add to your `flake.nix` inputs:
```nix
inputs.cursor.url = "github:your-username/cursor-nixos-flake";
```
When a new version of Cursor is released, use the included update script:
Then use in your configuration:
```nix
# For NixOS system configuration
environment.systemPackages = with pkgs; [
cursor.packages.x86_64-linux.cursor
];
### Method 1: Automatic with URL
# For home-manager
home.packages = with pkgs; [
cursor.packages.x86_64-linux.cursor
];
# For devShell
devShells.default = pkgs.mkShell {
packages = with pkgs; [
cursor.packages.x86_64-linux.cursor
];
};
```
### Method 3: Temporary Run
```bash
./update-cursor.sh "https://downloads.cursor.com/production/[hash]/linux/x64/Cursor-1.6.0-x86_64.AppImage"
# Run without installing
nix run github:your-username/cursor-nixos-flake
# Build and run
nix build github:your-username/cursor-nixos-flake
./result/bin/cursor
```
### Method 2: Interactive
## Manual Update
To manually update Cursor to the latest version:
```bash
./update-cursor.sh
# Follow the prompts to enter version or URL
```
### Method 3: Version number
```bash
./update-cursor.sh "1.6.0"
# Script will prompt for the full download URL
```
The script will automatically:
- ✅ Update the version in `flake.nix`
- ✅ Update the download URL
- ✅ Fetch and update the SHA256 hash
- ✅ Test that the package builds correctly
- ✅ Verify the version is correct
- ✅ Confirm icon extraction and desktop entry creation
## 📁 Repository Structure
```
cursor-flake/
├── flake.nix # Main flake configuration (package-only)
├── flake.lock # Flake lock file
├── update-cursor.sh # Update script for new versions
├── README.md # This file
├── LICENSE # MIT License
└── archive-old-system-configs/ # Archived old system configs
├── configuration.nix # (archived - was for full system setup)
├── home.nix # (archived - was for home-manager)
└── ... # (other archived files)
```
## 🔧 Development
### Testing Changes
To update to a specific version:
```bash
# Test that the package builds
nix build .#cursor
# Test that it runs
./result/bin/cursor --version
# Clean build (removes cached results)
nix build .#cursor --rebuild
./update-cursor.sh 1.8.0
```
## How It Works
### Automatic Updates
The GitHub Actions workflow runs daily and:
1. Checks Cursor's API for the latest version
2. Only updates if a new version is available
3. Downloads the AppImage and calculates SHA256 hash
4. Updates `flake.nix` with new version and hash
5. Tests the build and commits changes
6. Creates a GitHub release for tracking
### Manual Updates
The `update-cursor.sh` script provides:
- Version checking and comparison
- Safe updates with backups
- Build validation
- Interactive confirmation prompts
If you prefer to update manually:
## API Endpoints
1. Get the new AppImage URL from [cursor.sh](https://cursor.sh)
2. Update version and URL in `flake.nix`
3. Get the new hash:
```bash
nix-prefetch-url "https://downloads.cursor.com/production/[hash]/linux/x64/Cursor-X.Y.Z-x86_64.AppImage"
```
4. Update the hash in `flake.nix`
5. Test: `nix build .#cursor`
- **AppImage Download**: `https://api2.cursor.sh/updates/download/golden/linux-x64/cursor/{version}`
## 🏗️ Architecture
This flake uses `appimageTools.extract` and `appimageTools.wrapType2` to properly package the Cursor AppImage with all necessary dependencies and desktop integration. The packaging process:
- **Extracts AppImage contents** to access embedded icons and metadata
- **Bundles required system libraries** using appimageTools
- **Installs icons** to standard XDG locations (`/share/pixmaps`, `/share/icons/hicolor/`)
- **Creates desktop entry** with proper MIME type associations
- **Sets up environment variables** for optimal compatibility
- **Disables built-in updater** (managed by Nix instead)
- **Creates temporary directories** to avoid permission issues
- **Provides clean `cursor` command** with version support
## 🆚 Migration from Complex Structure
This flake was simplified from a previous version that included full NixOS system configurations. The old structure has been archived in `archive-old-system-configs/` for reference.
**Benefits of the new structure:**
- ✅ **Focused**: Just packages Cursor, nothing else
- ✅ **Reusable**: Easy to integrate into any NixOS system
- ✅ **Maintainable**: No complex system configurations to maintain
- ✅ **Safe**: No risk of breaking your system during updates
- ✅ **Consistent**: Matches the pattern of other package flakes
## 📜 License
MIT License - see [LICENSE](LICENSE) file.
## 🤝 Contributing
Issues and pull requests are welcome! Please test any changes by running:
## Testing
```bash
nix build .#cursor
./result/bin/cursor --version
# Test the complete setup
./test-setup.sh
# Test flake syntax
nix flake check
# Test building
nix build '.#cursor' --dry-run
```
## 🔗 Related
## Development
- [Cursor Official Website](https://cursor.sh/)
- [NixOS Documentation](https://nixos.org/manual/nixos/stable/)
- [Nix Flakes Documentation](https://nixos.wiki/wiki/Flakes)
### Customization
- **Update frequency**: Modify cron schedule in `.github/workflows/update-cursor.yml`
- **API endpoints**: Update URLs in workflow and update script
- **Build options**: Modify the `buildCursor` function in `flake.nix`
## License
MIT License - see [LICENSE](LICENSE) file for details.
-267
View File
@@ -1,267 +0,0 @@
# Cursor AppImage Native Module Fix
## Problem Analysis
The issue with Cursor when using the custom developed flake is related to native modules not being found when the AppImage runs. The error shows:
```
Error: Cannot find module './build/Debug/keymapping'
Require stack:
- /home/user/.cache/appimage-run/d249132fa6429cbc46050495a19ed410e04db53655428955024ff631c095d11c/usr/share/cursor/resources/app/node_modules/native-keymap/index.js
```
This is a common issue with Electron applications packaged as AppImages on NixOS systems. The native modules are compiled for a specific environment and don't work properly in the NixOS sandbox.
## Solution
We need to modify the Cursor wrapper in `home.nix` to add additional environment variables that help with native module loading. Here are the changes to make:
### Updated Cursor Wrapper Configuration
```nix
{ config, pkgs, lib, ... }:
let
# Cursor 1.4.2 AppImage wrapper with enhanced compatibility and update handling
cursorAppImage = pkgs.writeShellScriptBin "cursor" ''
# Set up environment for better AppImage compatibility
export APPDIR=""
export ARGV0=""
export OWD=""
# Disable Cursor's auto-update mechanism to prevent crashes
export CURSOR_DISABLE_UPDATE="1"
export CURSOR_SKIP_UPDATE_CHECK="1"
# Ensure proper library paths
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath [
pkgs.glib
pkgs.gtk3
pkgs.cairo
pkgs.pango
pkgs.atk
pkgs.gdk-pixbuf
pkgs.xorg.libX11
pkgs.xorg.libXcomposite
pkgs.xorg.libXcursor
pkgs.xorg.libXext
pkgs.xorg.libXfixes
pkgs.xorg.libXi
pkgs.xorg.libXrandr
pkgs.xorg.libXrender
pkgs.xorg.libXtst
pkgs.nss
pkgs.nspr
pkgs.dbus
pkgs.at-spi2-atk
pkgs.at-spi2-core
pkgs.mesa
pkgs.alsa-lib
pkgs.fuse
pkgs.libxkbcommon
pkgs.libxkbfile
]}:$LD_LIBRARY_PATH"
# Set additional environment variables to handle keymapping and native module issues
export ELECTRON_DISABLE_SECURITY_WARNINGS="1"
export ELECTRON_NO_ATTACH_CONSOLE="1"
export ELECTRON_RUN_AS_NODE="0"
# Additional environment variables for native module compatibility
export NODE_OPTIONS="--no-warnings"
export NODE_ENV="production"
export ELECTRON_ENABLE_LOGGING="false"
export ELECTRON_DISABLE_SECURITY_WARNINGS="true"
# Fix for native keymap module issues
export XDG_CACHE_HOME="/tmp/cursor-xdg-cache-$$"
mkdir -p "$XDG_CACHE_HOME"
# Create a temporary directory for Cursor's cache to avoid permission issues
export CURSOR_CACHE_DIR="/tmp/cursor-cache-$$"
mkdir -p "$CURSOR_CACHE_DIR"
# Additional fixes for AppImage native modules
export APPIMAGE_EXTRACT_AND_RUN="1"
# Run the AppImage with appimage-run and additional flags
exec ${pkgs.appimage-run}/bin/appimage-run \
--no-sandbox \
--appimage-extract-and-run \
${pkgs.fetchurl {
url = "https://downloads.cursor.com/production/07aa3b4519da4feab4761c58da3eeedd253a1671/linux/x64/Cursor-1.4.2-x86_64.AppImage";
sha256 = "0gb89li1aklzgc9h8y5rlrnk0n6sb4ikahaml4r9kr6ixadc4b1a";
}} \
--disable-updates \
--no-update-check \
--disable-gpu-sandbox \
--no-sandbox \
--disable-dev-shm-usage \
"$@"
'';
in
{
home.username = "user";
home.homeDirectory = "/home/user";
home.stateVersion = "23.11";
# Let Home Manager install and manage itself
programs.home-manager.enable = true;
# Add Cursor to home packages
home.packages = with pkgs; [
cursorAppImage
# Additional development tools
nodejs_20
python3
rustc
cargo
# Terminal improvements
starship
zsh
# Git tools
git-crypt
git-lfs
# Additional utilities
ripgrep
fd
bat
eza
fzf
tmux
];
# Shell configuration
programs.zsh = {
enable = true;
autosuggestion.enable = true;
enableCompletion = true;
syntaxHighlighting.enable = true;
shellAliases = {
ll = "eza -la";
la = "eza -a";
cat = "bat";
find = "fd";
grep = "rg";
};
};
# Starship prompt
programs.starship = {
enable = true;
enableZshIntegration = true;
settings = {
add_newline = false;
prompt_order = [ "directory" "git_branch" "git_status" "nodejs" "rust" "python" "cmd_duration" "line_break" "$all" ];
};
};
# Git configuration
programs.git = {
enable = true;
userName = "Your Name";
userEmail = "your.email@example.com";
extraConfig = {
init.defaultBranch = "main";
pull.rebase = true;
};
};
# VS Code settings (for Cursor compatibility)
home.file.".config/Code/User/settings.json".text = builtins.toJSON {
"editor.fontSize" = 14;
"editor.fontFamily" = "'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace";
"editor.fontLigatures" = true;
"editor.tabSize" = 2;
"editor.insertSpaces" = true;
"editor.rulers" = [ 80 120 ];
"editor.minimap.enabled" = false;
"workbench.colorTheme" = "Default Dark+";
"workbench.iconTheme" = "material-icon-theme";
"terminal.integrated.fontSize" = 14;
"terminal.integrated.fontFamily" = "'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace";
};
# Cursor-specific settings
home.file.".config/Cursor/User/settings.json".text = builtins.toJSON {
"editor.fontSize" = 14;
"editor.fontFamily" = "'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace";
"editor.fontLigatures" = true;
"editor.tabSize" = 2;
"editor.insertSpaces" = true;
"editor.rulers" = [ 80 120 ];
"editor.minimap.enabled" = false;
"workbench.colorTheme" = "Default Dark+";
"workbench.iconTheme" = "material-icon-theme";
"terminal.integrated.fontSize" = 14;
"terminal.integrated.fontFamily" = "'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace";
"cursor.chat.enabled" = true;
"cursor.chat.autoComplete" = true;
};
# Environment variables
home.sessionVariables = {
EDITOR = "cursor";
VISUAL = "cursor";
BROWSER = "firefox";
};
# XDG directories
xdg = {
enable = true;
userDirs = {
enable = true;
createDirectories = true;
desktop = "$HOME/Desktop";
documents = "$HOME/Documents";
download = "$HOME/Downloads";
music = "$HOME/Music";
pictures = "$HOME/Pictures";
publicShare = "$HOME/Public";
templates = "$HOME/Templates";
videos = "$HOME/Videos";
};
};
}
```
## Key Changes Made
1. **Added libxkbcommon and libxkbfile** to the library path to help with keyboard mapping
2. **Added ELECTRON_RUN_AS_NODE="0"** to ensure Electron runs properly
3. **Added NODE_OPTIONS="--no-warnings"** and **NODE_ENV="production"** for better Node.js compatibility
4. **Added XDG_CACHE_HOME** environment variable with a temporary directory to avoid permission issues
5. **Added APPIMAGE_EXTRACT_AND_RUN="1"** to help with AppImage native modules
6. **Added --appimage-extract-and-run** flag to the appimage-run command
7. **Added --disable-gpu-sandbox** and **--disable-dev-shm-usage** flags to help with sandbox issues
## How to Apply These Changes
1. Open your `home.nix` file
2. Replace the existing `cursorAppImage` section with the updated version above
3. Rebuild your system with:
```bash
sudo nixos-rebuild switch --flake .#cursor-system
```
4. Test Cursor:
```bash
cursor --version
```
## Additional Troubleshooting
If you still encounter issues:
1. Clear the AppImage cache:
```bash
rm -rf ~/.cache/appimage-run/*
```
2. Try running Cursor with additional debugging:
```bash
cursor --enable-logging --v=1
```
3. Check if the issue persists in a fresh terminal session
These changes should resolve the native module loading issues you're experiencing with Cursor in your NixOS flake.
+3 -3
View File
@@ -106,9 +106,9 @@
packages.${system} = {
default = self.packages.${system}.cursor;
cursor = buildCursor {
version = "1.6.35";
url = "https://downloads.cursor.com/production/b753cece5c67c47cb5637199a5a5de2b7100c18f/linux/x64/Cursor-1.6.35-x86_64.AppImage";
sha256 = "1qpkvs6zga979hhki49blyckffjp9pk49vhfn9nv57bxgjrbqszb";
version = "1.7.38";
url = "https://downloads.cursor.com/production/fe5d1728063e86edeeda5bebd2c8e14bf4d0f96a/linux/x64/Cursor-1.7.38-x86_64.AppImage";
sha256 = "1wgsq5xrnfi452qk650q1bnd59n57mp6gmcb5wg2dp6fnmahjr77"; # Will be updated by GitHub Actions
};
};
Executable
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
set -euo pipefail
# Test script to verify the Cursor flake setup
echo "Testing Cursor Flake Setup"
echo "========================="
# Check if we're in the right directory
if [[ ! -f "flake.nix" ]]; then
echo "Error: flake.nix not found. Please run this script from the flake directory."
exit 1
fi
# Test 1: Check flake syntax
echo "1. Testing flake syntax..."
if command -v nix >/dev/null 2>&1; then
if nix flake check --no-build; then
echo " ✓ Flake syntax is valid"
else
echo " ✗ Flake syntax error"
exit 1
fi
else
echo " ⚠ Skipping flake check (nix not available)"
fi
# Test 2: Check update script
echo "2. Testing update script..."
if [[ -f "update-cursor.sh" && -x "update-cursor.sh" ]]; then
echo " ✓ Update script exists and is executable"
# Test script help
if ./update-cursor.sh --help 2>/dev/null || ./update-cursor.sh -h 2>/dev/null; then
echo " ✓ Update script help works"
else
echo " ⚠ Update script help not available (this is normal)"
fi
else
echo " ✗ Update script missing or not executable"
exit 1
fi
# Test 3: Check GitHub Actions workflow
echo "3. Testing GitHub Actions workflow..."
if [[ -f ".github/workflows/update-cursor.yml" ]]; then
echo " ✓ GitHub Actions workflow exists"
# Basic YAML syntax check
if command -v yamllint >/dev/null 2>&1; then
if yamllint .github/workflows/update-cursor.yml >/dev/null 2>&1; then
echo " ✓ Workflow YAML syntax is valid"
else
echo " ⚠ Workflow YAML syntax issues (yamllint not available or found issues)"
fi
else
echo " ⚠ Skipping YAML validation (yamllint not available)"
fi
else
echo " ✗ GitHub Actions workflow missing"
exit 1
fi
# Test 4: Check API connectivity
echo "4. Testing API connectivity..."
if command -v curl >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
if curl -s --max-time 10 "https://api2.cursor.sh/updates/check/golden/linux-x64-deb/cursor" | jq -r '.version' >/dev/null 2>&1; then
echo " ✓ Cursor API is accessible"
else
echo " ⚠ Cursor API not accessible (this might be temporary)"
fi
else
echo " ⚠ Skipping API test (curl or jq not available)"
fi
# Test 5: Check current version
echo "5. Checking current version..."
CURRENT_VERSION=$(grep -o 'version = "[^"]*"' flake.nix | head -1 | cut -d'"' -f2)
echo " Current version: $CURRENT_VERSION"
# Test 6: Check if SHA256 is placeholder
echo "6. Checking SHA256 hash..."
CURRENT_SHA256=$(grep -o 'sha256 = "[^"]*"' flake.nix | head -1 | cut -d'"' -f2)
if [[ "$CURRENT_SHA256" == "0000000000000000000000000000000000000000000000000000" ]]; then
echo " ⚠ SHA256 is placeholder - needs to be updated"
else
echo " ✓ SHA256 appears to be set"
fi
echo ""
echo "Test Summary"
echo "============"
echo "Setup appears to be mostly correct!"
echo ""
echo "Next steps:"
echo "1. Run './update-cursor.sh' to get the correct SHA256 hash"
echo "2. Commit and push your changes to enable GitHub Actions"
echo "3. Check the Actions tab in GitHub to see if the workflow runs"
echo ""
echo "For manual testing:"
echo "- nix build .#cursor --dry-run"
echo "- nix run .#cursor --version"
-162
View File
@@ -1,162 +0,0 @@
# Testing Plan for Cursor AppImage Fix
## Overview
This document outlines the steps to test the updated Cursor AppImage wrapper configuration to ensure the native module loading issues are resolved.
## Prerequisites
1. The updated `home.nix` file with the new Cursor wrapper configuration
2. A working NixOS system with flakes enabled
3. Sudo access to rebuild the system
## Testing Steps
### 1. Apply the Configuration Changes
1. Open your `home.nix` file
2. Replace the existing `cursorAppImage` section with the updated version from `cursor-fix-solution.md`
3. Save the file
### 2. Rebuild the System
```bash
# Navigate to your flake directory
cd /path/to/cursor-flake
# Rebuild the system with the updated configuration
sudo nixos-rebuild switch --flake .#cursor-system
```
Expected output:
- The build should complete without errors
- You should see the new Cursor package being built
### 3. Test Basic Functionality
```bash
# Test that Cursor can be invoked
cursor --version
```
Expected output:
- Should display the Cursor version (1.4.2)
- No error messages about missing modules
### 4. Test GUI Launch
```bash
# Launch Cursor GUI
cursor
```
Expected behavior:
- Cursor should launch without the keymapping errors
- The application should be responsive
- No console errors about native modules
### 5. Test Keyboard Functionality
Within the Cursor application:
1. Try typing in the editor
2. Test different keyboard layouts if applicable
3. Use keyboard shortcuts (Ctrl+C, Ctrl+V, etc.)
Expected behavior:
- Keyboard input should work normally
- No lag or errors when typing
- Keyboard shortcuts should function correctly
### 6. Test Project Operations
1. Open an existing project or create a new one
2. Try basic file operations (create, edit, save)
3. Test the AI features if available
Expected behavior:
- All operations should work without errors
- No crashes or unexpected behavior
### 7. Verify Environment Variables
```bash
# Check that environment variables are set correctly
printenv | grep -E "(CURSOR|ELECTRON|NODE)"
```
Expected output:
- Should show the environment variables we added
- Values should match what we specified in the configuration
### 8. Clean Cache Test
```bash
# Clear AppImage cache to test fresh start
rm -rf ~/.cache/appimage-run/*
# Restart Cursor
cursor --version
```
Expected behavior:
- Should work correctly even with cleared cache
- No errors about missing modules
## Success Criteria
The fix is considered successful if:
1. [ ] `cursor --version` runs without errors
2. [ ] Cursor GUI launches without keymapping errors
3. [ ] Keyboard input works normally in the editor
4. [ ] No native module loading errors in the console
5. [ ] All basic functionality works as expected
6. [ ] Application remains stable during extended use
## Troubleshooting
If issues persist after applying the fix:
1. Check the system logs:
```bash
journalctl -xe
```
2. Try running with additional debugging:
```bash
cursor --enable-logging --v=1
```
3. Verify the AppImage is being extracted correctly:
```bash
ls -la ~/.cache/appimage-run/
```
4. Check library dependencies:
```bash
ldd ~/.cache/appimage-run/*/usr/lib/libkeymapping.so
```
## Rollback Plan
If the updated configuration causes issues:
1. Restore the previous `home.nix` file
2. Rebuild the system:
```bash
sudo nixos-rebuild switch --flake .#cursor-system
```
3. Clear the AppImage cache:
```bash
rm -rf ~/.cache/appimage-run/*
```
## Additional Validation
Once the basic tests pass, perform these additional checks:
1. [ ] Test in a fresh terminal session
2. [ ] Test after system reboot
3. [ ] Test with different projects and file types
4. [ ] Verify no performance degradation
+137 -119
View File
@@ -1,129 +1,147 @@
#!/usr/bin/env bash
# Simple script to update Cursor version in a package-only flake
set -euo pipefail
set -e
# Script to manually update Cursor version in the flake
# Usage: ./update-cursor.sh [version]
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FLAKE_FILE="$SCRIPT_DIR/flake.nix"
print_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Check if we're in the right directory
if [[ ! -f "flake.nix" ]]; then
print_error "This script must be run from the cursor-flake directory"
exit 1
fi
print_info "Cursor Package Flake Updater"
echo ""
# Get current version and URL
CURRENT_VERSION=$(grep -o 'version = "[^"]*"' flake.nix | head -1 | sed 's/version = "//;s/"//')
CURRENT_URL=$(grep -o 'https://downloads\.cursor\.com/[^"]*' flake.nix | head -1)
CURRENT_HASH=$(grep -o 'sha256 = "[^"]*"' flake.nix | head -1 | sed 's/sha256 = "//;s/"//')
print_info "Current version: ${CURRENT_VERSION:-unknown}"
print_info "Current URL: $CURRENT_URL"
echo ""
# Handle input
if [[ $# -ge 1 ]]; then
if [[ "$1" =~ ^https:// ]]; then
NEW_URL="$1"
NEW_VERSION=$(echo "$NEW_URL" | grep -o 'Cursor-[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | sed 's/Cursor-//')
else
NEW_VERSION="$1"
read -p "Enter the full download URL for version $NEW_VERSION: " NEW_URL
fi
else
read -p "Enter new version (e.g., 1.5.6) or full URL: " INPUT
if [[ "$INPUT" =~ ^https:// ]]; then
NEW_URL="$INPUT"
NEW_VERSION=$(echo "$NEW_URL" | grep -o 'Cursor-[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | sed 's/Cursor-//')
else
NEW_VERSION="$INPUT"
read -p "Enter the full download URL: " NEW_URL
fi
fi
if [[ -z "$NEW_URL" || -z "$NEW_VERSION" ]]; then
print_error "Invalid input"
exit 1
fi
print_info "New version: $NEW_VERSION"
print_info "New URL: $NEW_URL"
echo ""
# Get hash
print_info "Fetching SHA256 hash..."
HASH=$(nix-prefetch-url "$NEW_URL")
if [[ -z "$HASH" ]]; then
print_error "Failed to get hash"
exit 1
fi
print_success "SHA256 hash: $HASH"
echo ""
# Update flake.nix
print_info "Updating flake.nix..."
# Update version
sed -i "s|version = \"[^\"]*\";|version = \"$NEW_VERSION\";|" flake.nix
print_success "Updated version"
# Update URL
sed -i "s|$CURRENT_URL|$NEW_URL|g" flake.nix
print_success "Updated URL"
# Update hash
sed -i "s|sha256 = \"$CURRENT_HASH\";|sha256 = \"$HASH\";|" flake.nix
print_success "Updated hash"
# Test build
print_info "Testing build..."
if nix build .#cursor; then
print_success "Build successful!"
# Function to get latest version from API redirect
get_latest_version() {
# Get the redirect URL and extract version from the AppImage filename
local redirect_url
redirect_url=$(curl -s -I "https://api2.cursor.sh/updates/download/golden/linux-x64/cursor/latest" | grep -i location | cut -d' ' -f2 | tr -d '\r\n')
if [[ -x "./result/bin/cursor" ]]; then
BUILT_VERSION=$(./result/bin/cursor --version 2>/dev/null || echo "unknown")
print_info "Built version: $BUILT_VERSION"
if [[ "$BUILT_VERSION" == "$NEW_VERSION" ]]; then
print_success "Version verification passed!"
else
print_warning "Version mismatch: expected $NEW_VERSION, got $BUILT_VERSION"
fi
# Check that icon and desktop entry were installed
if [[ -f "./result/share/pixmaps/cursor.png" ]]; then
print_success "Icon successfully extracted and installed!"
else
print_warning "Icon not found - might not display properly in desktop"
fi
if [[ -f "./result/share/applications/cursor.desktop" ]]; then
print_success "Desktop entry created!"
else
print_warning "Desktop entry not found"
fi
if [[ -n "$redirect_url" ]]; then
# Extract version from URL like: .../Cursor-1.7.39-x86_64.AppImage
echo "$redirect_url" | grep -o 'Cursor-[0-9]\+\.[0-9]\+\.[0-9]\+' | sed 's/Cursor-//'
else
echo "Error: Could not get redirect URL"
return 1
fi
else
print_error "Build failed!"
}
# Function to get current version from flake.nix
get_current_version() {
grep -o 'version = "[^"]*"' "$FLAKE_FILE" | head -1 | cut -d'"' -f2
}
# Function to update flake.nix
update_flake() {
local version="$1"
local appimage_url="https://api2.cursor.sh/updates/download/golden/linux-x64/cursor/$version"
echo "Fetching AppImage from: $appimage_url"
# Get the actual download URL by following redirects
local actual_url
actual_url=$(curl -s -I "$appimage_url" | grep -i location | cut -d' ' -f2 | tr -d '\r\n')
if [[ -z "$actual_url" ]]; then
echo "Error: Could not get actual download URL"
return 1
fi
echo "Actual download URL: $actual_url"
# Get SHA256 hash
local sha256
if command -v nix-prefetch-url >/dev/null 2>&1; then
sha256=$(nix-prefetch-url --type sha256 "$actual_url")
else
echo "Warning: nix-prefetch-url not found. You'll need to update the SHA256 manually."
sha256="0000000000000000000000000000000000000000000000000000"
fi
echo "SHA256: $sha256"
# Create backup
cp "$FLAKE_FILE" "$FLAKE_FILE.backup"
# Update flake.nix - be more specific to avoid replacing nixpkgs URL
sed -i "s/version = \"[^\"]*\" # Will be updated by GitHub Actions/version = \"$version\"/" "$FLAKE_FILE"
sed -i "/buildCursor = {/,/};/s|url = \"[^\"]*\"|url = \"$actual_url\"|" "$FLAKE_FILE"
sed -i "/buildCursor = {/,/};/s/sha256 = \"[^\"]*\"/sha256 = \"$sha256\"/" "$FLAKE_FILE"
echo "Updated flake.nix with version $version"
}
# Function to test the flake
test_flake() {
echo "Testing flake..."
if command -v nix >/dev/null 2>&1; then
nix flake check
echo "Flake check passed!"
else
echo "Warning: nix command not found. Skipping flake check."
fi
}
# Main logic
main() {
local target_version="${1:-}"
echo "Cursor Flake Updater"
echo "==================="
# Get current version
local current_version
current_version=$(get_current_version)
echo "Current version: $current_version"
# Determine target version
if [[ -n "$target_version" ]]; then
echo "Target version: $target_version"
else
echo "Fetching latest version..."
target_version=$(get_latest_version)
echo "Latest version: $target_version"
fi
# Check if update is needed
if [[ "$target_version" == "$current_version" ]]; then
echo "No update needed. Current version is up to date."
exit 0
fi
echo "Update needed: $current_version -> $target_version"
read -p "Do you want to proceed with the update? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
update_flake "$target_version"
test_flake
echo "Update completed successfully!"
echo "You can now commit the changes:"
echo " git add flake.nix"
echo " git commit -m \"Update Cursor to version $target_version\""
else
echo "Update cancelled."
exit 1
fi
}
echo ""
print_info "Package updated successfully!"
print_info "To use in your system: rebuild your main NixOS configuration"
print_success "Update complete!"
# Check dependencies
check_dependencies() {
local missing_deps=()
if ! command -v curl >/dev/null 2>&1; then
missing_deps+=("curl")
fi
if ! command -v jq >/dev/null 2>&1; then
missing_deps+=("jq")
fi
if [[ ${#missing_deps[@]} -gt 0 ]]; then
echo "Error: Missing required dependencies: ${missing_deps[*]}"
echo "Please install them and try again."
exit 1
fi
}
# Run main function
check_dependencies
main "$@"