|
1 | 1 | { |
2 | 2 | stdenv, |
3 | 3 | lib, |
| 4 | + runCommand, |
4 | 5 | writeShellApplication, |
5 | 6 | tree-sitter-nu ? fetchGit "https://github.com/nushell/tree-sitter-nu", |
6 | 7 | topiary, |
7 | 8 | nushell, |
8 | | - writeText, |
9 | 9 | callPackage, |
10 | | - symlinkJoin, |
11 | 10 | }: |
12 | | -symlinkJoin { |
13 | | - name = "topiary-nushell"; |
14 | | - paths = [ |
15 | | - (writeShellApplication ( |
16 | | - let |
17 | | - libtree-sitter-nu = callPackage ( |
18 | | - { |
19 | | - lib, |
20 | | - stdenv, |
21 | | - }: |
22 | | - stdenv.mkDerivation (finalAttrs: { |
23 | | - pname = "tree-sitter-nu"; |
24 | | - version = tree-sitter-nu.rev; |
| 11 | +writeShellApplication ( |
| 12 | + let |
| 13 | + libtree-sitter-nu = callPackage ( |
| 14 | + { |
| 15 | + lib, |
| 16 | + stdenv, |
| 17 | + }: |
| 18 | + stdenv.mkDerivation (finalAttrs: { |
| 19 | + pname = "tree-sitter-nu"; |
| 20 | + version = tree-sitter-nu.rev; |
| 21 | + |
| 22 | + src = tree-sitter-nu; |
| 23 | + |
| 24 | + makeFlags = [ |
| 25 | + # The PREFIX var isn't picking up from stdenv. |
| 26 | + "PREFIX=$(out)" |
| 27 | + ]; |
25 | 28 |
|
26 | | - src = tree-sitter-nu; |
| 29 | + meta = with lib; { |
| 30 | + description = "A tree-sitter grammar for nu-lang, the language of nushell"; |
| 31 | + homepage = "https://github.com/nushell/tree-sitter-nu"; |
| 32 | + license = licenses.mit; |
| 33 | + }; |
| 34 | + }) |
| 35 | + ) { }; |
| 36 | + |
| 37 | + extension = |
| 38 | + with stdenv; |
| 39 | + if isLinux then |
| 40 | + ".so" |
| 41 | + else if isDarwin then |
| 42 | + ".dylib" |
| 43 | + else |
| 44 | + throw "Unsupported system: ${system}"; |
27 | 45 |
|
28 | | - makeFlags = [ |
29 | | - # The PREFIX var isn't picking up from stdenv. |
30 | | - "PREFIX=$(out)" |
31 | | - ]; |
| 46 | + # Create a directory holding ALL runtime config files |
| 47 | + # This makes a single path for GC root. |
| 48 | + topiaryConfigDir = runCommand "topiary-nushell-config" { } '' |
| 49 | + local_config_dir="$out" |
32 | 50 |
|
33 | | - meta = with lib; { |
34 | | - description = "A tree-sitter grammar for nu-lang, the language of nushell"; |
35 | | - homepage = "https://github.com/nushell/tree-sitter-nu"; |
36 | | - license = licenses.mit; |
37 | | - }; |
38 | | - }) |
39 | | - ) { }; |
| 51 | + # 1. Copy the nu.scm language directory |
| 52 | + mkdir -p $local_config_dir/languages |
| 53 | + cp ${./languages/nu.scm} $local_config_dir/languages/nu.scm |
40 | 54 |
|
41 | | - extension = |
42 | | - with stdenv; |
43 | | - if isLinux then |
44 | | - ".so" |
45 | | - else if isDarwin then |
46 | | - ".dylib" |
47 | | - else |
48 | | - throw "Unsupported system: ${system}"; |
49 | | - in |
| 55 | + cat > $local_config_dir/languages.ncl <<EOF |
50 | 56 | { |
51 | | - name = "topiary-nushell"; |
52 | | - runtimeInputs = [ |
53 | | - nushell |
54 | | - topiary |
55 | | - ]; |
56 | | - runtimeEnv = { |
57 | | - TOPIARY_CONFIG_FILE = writeText "languages.ncl" '' |
58 | | - { |
59 | | - languages = { |
60 | | - nu = { |
61 | | - extensions = ["nu"], |
62 | | - grammar.source.path = "${libtree-sitter-nu}/lib/libtree-sitter-nu${extension}", |
63 | | - }, |
64 | | - }, |
65 | | - } |
66 | | - ''; |
67 | | - TOPIARY_LANGUAGE_DIR = ./languages; |
68 | | - }; |
69 | | - text = '' |
70 | | - ${lib.getExe topiary} "$@" |
71 | | - ''; |
| 57 | + languages = { |
| 58 | + nu = { |
| 59 | + extensions = ["nu"], |
| 60 | + grammar.source.path = "${libtree-sitter-nu}/lib/libtree-sitter-nu${extension}", |
| 61 | + }, |
| 62 | + }, |
72 | 63 | } |
73 | | - )) |
74 | | - ./. |
75 | | - ]; |
76 | | - meta = with lib; { |
77 | | - description = "topiary formatter for nushell"; |
78 | | - homepage = "https://github.com/blindFS/topiary-nushell"; |
79 | | - license = licenses.mit; |
80 | | - mainProgram = "topiary-nushell"; |
81 | | - }; |
82 | | -} |
| 64 | + EOF |
| 65 | + ''; |
| 66 | + in |
| 67 | + { |
| 68 | + name = "topiary-nushell"; |
| 69 | + runtimeInputs = [ |
| 70 | + nushell |
| 71 | + topiary |
| 72 | + ]; |
| 73 | + runtimeEnv = { |
| 74 | + TOPIARY_CONFIG_FILE = "${topiaryConfigDir}/languages.ncl"; |
| 75 | + TOPIARY_LANGUAGE_DIR = "${topiaryConfigDir}/languages"; |
| 76 | + }; |
| 77 | + text = '' |
| 78 | + ${lib.getExe topiary} "$@" |
| 79 | + ''; |
| 80 | + } |
| 81 | +) |
0 commit comments