Skip to content

Commit 64bd743

Browse files
author
fidgetingbits
committed
Add flake for dev environment on nix
1 parent 226baf3 commit 64bd743

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.direnv/
12
/.make-work/
23
/.metals/
34
/.vscode-test/

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,39 @@ When working with WSL, the host vscode instance connects to a vscode server on t
5959
- If you're adding language support to `vscode-parse-tree`, you need to clone that as well, build it, and link it into the `vscode-server` extension folder: `ln -s ~/your/code/vscode-parse-tree ~/.vscode-server/extensions/parse-tree` for instance.
6060
- If you get errors about needing to install the `Remote-WSL` extension, you might need to manually delete the extension from the host side and try again.
6161

62+
### Developing on Nix
63+
64+
There is a `.envrc` file included to trigger the flake usage.
65+
66+
As of 2023-09 emscripten seems to have some issues related to caching folder on
67+
Nix. After running the `yarn` command you will see something like this:
68+
69+
```
70+
$ yarn add -D tree-sitter-nix
71+
[SNIPPED]
72+
OSError: [Errno 30] Read-only file system: '/nix/store/ykh9rm7z5mr248hsc408zr1csh6ss0vz-emscripten-3.1.42/share/emscripten/cache/symbol_lists.lock'
73+
make: *** [Makefile:63: vendor/web-tree-sitter/0.20.4/README.md] Error 1
74+
error Command failed with exit code 2.
75+
```
76+
77+
In order to work around that error you will have to run the commands included below. Note the `/nix/store/` path comes from the error above.
78+
79+
```bash
80+
$ cp -R /nix/store/ykh9rm7z5mr248hsc408zr1csh6ss0vz-emscripten-3.1.42/share/emscripten/cache/ ~/.emscripten_cache
81+
$ chmod u+rwX -R ~/.emscripten_cache
82+
$ export EM_CACHE=~/.emscripten_cache
83+
$ yarn add -D ...
84+
```
85+
86+
See https://github.com/NixOS/nixpkgs/issues/139943 for background on this
87+
issue.
88+
89+
In order to run `yarn compile` it will attempt to run `npx tree-sitter` which
90+
will fail. You can use `steam-run` instead:
91+
92+
`steam-run yarn compile`
93+
94+
6295
### Updating `web-tree-sitter`
6396

6497
We build a custom version of `web-tree-sitter` to ensure that we can always use the latest version and fix any problems as they come up.

flake.lock

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
description = "A Nix-flake-based Node.js development environment";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
6+
outputs = { self, nixpkgs }:
7+
let
8+
overlays = [
9+
(final: prev: rec {
10+
nodejs = prev.nodejs-18_x;
11+
pnpm = prev.nodePackages.pnpm;
12+
yarn = (prev.yarn.override { inherit nodejs; });
13+
})
14+
];
15+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
16+
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
17+
pkgs = import nixpkgs { inherit overlays system; config.allowUnfree = true; };
18+
});
19+
in
20+
{
21+
devShells = forEachSupportedSystem ({ pkgs }: {
22+
default = pkgs.mkShell {
23+
packages = with pkgs; [ node2nix nodejs pnpm yarn emscripten python310 steam-run];
24+
};
25+
});
26+
};
27+
}

0 commit comments

Comments
 (0)