diff --git a/.envrc b/.envrc new file mode 100644 index 00000000000..3550a30f2de --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 90e5d79bb08..b12c598ac05 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ next-env.d.ts # test subset config packages/test-harness/testSubsetGrep.properties + +# nix +.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..a1271a0ba5f --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1709675310, + "narHash": "sha256-w61tqFEmuJ+/1rAwU7nkYZ+dN6sLwyobfLwX2Yn42FE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "43d259f8d726113fac056e8bb17d5ac2dea3e0a8", + "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 00000000000..b373cb308a9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,63 @@ +{ + 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; }; }); + 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 + pkgs.pre-commit + + python + # Dependencies from pre-commit python scripts + # run `pre-commit run --all-files` to find out what you need. + pythonPackages.identify + pythonPackages.cfgv + pythonPackages.yamllint + ]; + # To prevent weird broken non-interactive bash terminal + buildInputs = [ pkgs.bashInteractive ]; + shellHook = '' + if [ ! -f .git/hooks/pre-commit ]; then + pre-commit install + fi + + # Cursorless .prettierrc depends on prettier-plugin-tailwindcss, which + # pre-commit won't auto-install. So we have to manually install it into the + # workspace until there is a nix package. + if ! pnpm ls prettier-plugin-tailwindcss | grep prettier >/dev/null; then + pnpm -w -D install prettier-plugin-tailwindcss + # This updates the pnpm-lock.yaml, which we don't want to keep + git restore pnpm-lock.yaml + fi + ''; + }; + } + ); + }; +}