|
| 1 | +{ |
| 2 | + description = "A Nix-flake-based development environment for Cursorless"; |
| 3 | + |
| 4 | + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
| 5 | + |
| 6 | + outputs = |
| 7 | + { self, nixpkgs }: |
| 8 | + let |
| 9 | + supportedSystems = [ |
| 10 | + "x86_64-linux" |
| 11 | + "aarch64-linux" |
| 12 | + "x86_64-darwin" |
| 13 | + "aarch64-darwin" |
| 14 | + ]; |
| 15 | + forEachSupportedSystem = |
| 16 | + f: nixpkgs.lib.genAttrs supportedSystems (system: f { pkgs = import nixpkgs { inherit system; }; }); |
| 17 | + pythonVersion = builtins.replaceStrings [ "py" ] [ |
| 18 | + "python" |
| 19 | + ] (nixpkgs.lib.importTOML ./pyproject.toml).tool.ruff.target-version; |
| 20 | + in |
| 21 | + { |
| 22 | + devShells = forEachSupportedSystem ( |
| 23 | + { pkgs }: |
| 24 | + { |
| 25 | + default = pkgs.mkShell { |
| 26 | + packages = |
| 27 | + let |
| 28 | + python = pkgs.${pythonVersion}; |
| 29 | + pythonPackages = pkgs."${pythonVersion}Packages"; |
| 30 | + in |
| 31 | + [ |
| 32 | + pkgs.corepack |
| 33 | + pkgs.vsce |
| 34 | + pkgs.pre-commit |
| 35 | + |
| 36 | + python |
| 37 | + # Dependencies from pre-commit python scripts |
| 38 | + # run `pre-commit run --all-files` to find out what you need. |
| 39 | + pythonPackages.identify |
| 40 | + pythonPackages.cfgv |
| 41 | + pythonPackages.yamllint |
| 42 | + ]; |
| 43 | + # To prevent weird broken non-interactive bash terminal |
| 44 | + buildInputs = [ pkgs.bashInteractive ]; |
| 45 | + shellHook = '' |
| 46 | + if [ ! -f .git/hooks/pre-commit ]; then |
| 47 | + pre-commit install |
| 48 | + fi |
| 49 | +
|
| 50 | + # Cursorless .prettierrc depends on prettier-plugin-tailwindcss, which |
| 51 | + # pre-commit won't auto-install. So we have to manually install it into the |
| 52 | + # workspace until there is a nix package. |
| 53 | + if ! pnpm ls prettier-plugin-tailwindcss | grep prettier >/dev/null; then |
| 54 | + pnpm -w -D install prettier-plugin-tailwindcss |
| 55 | + # This updates the pnpm-lock.yaml, which we don't want to keep |
| 56 | + git restore pnpm-lock.yaml |
| 57 | + fi |
| 58 | + ''; |
| 59 | + }; |
| 60 | + } |
| 61 | + ); |
| 62 | + }; |
| 63 | +} |
0 commit comments