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
+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.