Files
chiasson-nix/modules/wisdom/editors/cursor.nix
T
2026-05-25 13:48:47 -03:00

94 lines
3.1 KiB
Nix

{ inputs, ... }: {
flake.homeManagerModules.wisdomEditorsCursor =
{ config, lib, pkgs, ... }:
let
root = config.chiasson.home;
cfg = config.chiasson.home.editors.cursor;
cursorPkgs = inputs.cursor.packages.${pkgs.stdenv.hostPlatform.system} or { };
cursorPkg =
if cursorPkgs ? cursor then
cursorPkgs.cursor
else if cursorPkgs ? default then
cursorPkgs.default
else
null;
# NixOS-New `home-shared.nix`: `cursor-cli` alongside the AppImage. nixpkgs now names this
# `cursor-agent`; keep both for compatibility across pins.
defaultAgentPkg =
if pkgs ? cursor-agent then
pkgs.cursor-agent
else if pkgs ? cursor-cli then
pkgs.cursor-cli
else
null;
nixIdeTools = [ pkgs.nixd pkgs.nixfmt ];
cursorWithNixIde =
if cursorPkg == null then
null
else
pkgs.symlinkJoin {
name = "cursor-with-nix-ide";
paths = [ cursorPkg ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
for prog in $out/bin/*; do
if [ -x "$prog" ]; then
wrapProgram "$prog" --prefix PATH : "${lib.makeBinPath nixIdeTools}"
fi
done
'';
};
in
{
options.chiasson.home.editors.cursor = {
enable = lib.mkEnableOption "Cursor editor from the `cursor` flake input.";
setAsDefaultEditor = lib.mkOption {
type = lib.types.bool;
default = true;
description = "`EDITOR` / `VISUAL` `cursor --wait`.";
};
agent = {
enable = lib.mkEnableOption ''
Cursor Agent CLI (`cursor-agent` in current nixpkgs; older pins used `cursor-cli`).
'' // {
default = true;
};
package = lib.mkOption {
type = with lib.types; nullOr package;
default = defaultAgentPkg;
defaultText = "pkgs.cursor-agent or pkgs.cursor-cli or null";
description = ''
Package providing the `cursor-agent` CLI. Set to `null` to omit the CLI while keeping the GUI app.
'';
};
};
nixIde = {
enable = lib.mkEnableOption ''
Nix IDE extension tooling (`nixd` LSP, `nixfmt` formatter).
Installs `nixd` / `nixfmt` and wraps Cursor so they are on the editor `PATH`
(the GUI does not inherit your shell profile).
'' // {
default = true;
};
};
};
config = lib.mkIf (root.enable && cfg.enable && cursorPkg != null) {
home.packages =
[
(if cfg.nixIde.enable && cursorWithNixIde != null then
cursorWithNixIde
else
cursorPkg)
]
++ lib.optionals (cfg.agent.enable && cfg.agent.package != null) [ cfg.agent.package ]
++ lib.optionals cfg.nixIde.enable nixIdeTools;
home.sessionVariables = lib.mkIf cfg.setAsDefaultEditor {
EDITOR = "cursor --wait";
VISUAL = "cursor --wait";
};
};
};
}