From 1cdf49ee6480e54b2acdb9e34275e458fa63631a Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Mon, 24 Jun 2024 11:26:46 +0800 Subject: [PATCH] feat: working debug on nix --- .envrc | 1 + .gitignore | 3 + flake.lock | 27 ++++++ flake.nix | 96 +++++++++++++++++++ .../cursorless-neovim/scripts/debug-neovim.sh | 2 +- .../scripts/populate-dist.sh | 3 + 6 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..3550a30f2d --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 00cb2b0c00..e4490c1d92 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,6 @@ packages/test-harness/testSubsetGrep.properties cursorless.nvim/node/cursorless-neovim cursorless.nvim/node/test-harness + +# nix +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..4e43b25df4 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1718870667, + "narHash": "sha256-jab3Kpc8O1z3qxwVsCMHL4+18n5Wy/HHKyu1fcsF7gs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b10b8f00cb5494795e5f51b39210fed4d2b0748", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..ea62fa502b --- /dev/null +++ b/flake.nix @@ -0,0 +1,96 @@ +{ + description = "A Nix-flake-based development environment for Cursorless"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forEachSupportedSystem = + f: + nixpkgs.lib.genAttrs supportedSystems ( + system: + f { + pkgs = import nixpkgs { + inherit system; + overlays = [ + # https://github.com/NixOS/nixpkgs/pull/317333 + (final: prev: { + nodePackages = prev.nodePackages // { + neovim = prev.buildNpmPackage rec { + pname = "neovim-node-client"; + version = "5.1.1-dev.0"; + src = prev.fetchFromGitHub { + owner = "neovim"; + repo = "node-client"; + rev = "d99ececf115ddc8ade98467417c1bf0120b676b5"; + hash = "sha256-eiKyhJNz7kH2iX55lkn7NZYTj6yaSZLMZxqiqPxDIPs="; + }; + npmDeps = prev.fetchNpmDeps { + inherit src; + hash = "sha256-UoMq+7evskxtZygycxLBgeUtwrET8jYKeZwMiXdBMAw="; + }; + postInstall = '' + mkdir -p $out/bin + ln -s $out/lib/node_modules/neovim/node_modules/.bin/neovim-node-host $out/bin + ''; + }; + }; + neovim = prev.neovim.override { withNodeJs = true; }; + + }) + + ]; + }; + } + ); + pythonVersion = builtins.replaceStrings [ "py" ] [ + "python" + ] (nixpkgs.lib.importTOML ./pyproject.toml).tool.ruff.target-version; + in + { + + devShells = forEachSupportedSystem ( + { pkgs }: + { + default = pkgs.mkShell { + packages = + let + python = pkgs.${pythonVersion}; + pythonPackages = pkgs."${pythonVersion}Packages"; + in + [ + pkgs.corepack + pkgs.vsce + # https://github.com/NixOS/nixpkgs/pull/251418 + (pkgs.pre-commit.overrideAttrs (previousAttrs: { + makeWrapperArgs = '' + --set PYTHONPATH $PYTHONPATH + ''; + })) + + python + pkgs.neovim + ]; + # To prevent weird broken non-interactive bash terminal + buildInputs = [ pkgs.bashInteractive ]; + shellHook = '' + if [ ! -f .git/hooks/pre-commit ]; then + pre-commit install + fi + pnpm install + PATH=${pkgs.lib.getBin pkgs.neovim}/bin:$PATH} + ''; + }; + } + ); + }; +} diff --git a/packages/cursorless-neovim/scripts/debug-neovim.sh b/packages/cursorless-neovim/scripts/debug-neovim.sh index fbedb2d523..58aae44dd6 100755 --- a/packages/cursorless-neovim/scripts/debug-neovim.sh +++ b/packages/cursorless-neovim/scripts/debug-neovim.sh @@ -10,4 +10,4 @@ export NVIM_NODE_LOG_FILE="${workspaceFolder}/packages/cursorless-neovim/out/nvi export NVIM_NODE_LOG_LEVEL="info" export CURSORLESS_MODE="${cursorless_mode}" -nvim -u "${workspaceFolder}/init.lua" +command nvim -u "${workspaceFolder}/init.lua" diff --git a/packages/cursorless-neovim/scripts/populate-dist.sh b/packages/cursorless-neovim/scripts/populate-dist.sh index 8d57668cbd..1d7c2a0405 100755 --- a/packages/cursorless-neovim/scripts/populate-dist.sh +++ b/packages/cursorless-neovim/scripts/populate-dist.sh @@ -2,6 +2,9 @@ set -euo pipefail echo "Populating dist directory..." +if [ ! -e "${CURSORLESS_REPO_ROOT-nonexistent}" ]; then + CURSORLESS_REPO_ROOT=$(git rev-parse --show-toplevel) +fi echo "CURSORLESS_REPO_ROOT: $CURSORLESS_REPO_ROOT" cursorless_nvim_dir="$CURSORLESS_REPO_ROOT/cursorless.nvim" cursorless_neovim_node_in_dir="$CURSORLESS_REPO_ROOT/packages/cursorless-neovim"