Skip to content

Commit c134c6d

Browse files
committed
refactor: use symlinkJoin instead of runCommand
1 parent 3e18c8e commit c134c6d

1 file changed

Lines changed: 67 additions & 66 deletions

File tree

package.nix

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,82 @@
11
{
22
stdenv,
33
lib,
4-
runCommand,
54
writeShellApplication,
65
tree-sitter-nu ? fetchGit "https://github.com/nushell/tree-sitter-nu",
76
topiary,
87
nushell,
8+
writeText,
99
callPackage,
10+
symlinkJoin,
1011
}:
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-
];
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;
2825

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}";
26+
src = tree-sitter-nu;
4527

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"
28+
makeFlags = [
29+
# The PREFIX var isn't picking up from stdenv.
30+
"PREFIX=$(out)"
31+
];
5032

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
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+
) { };
5440

55-
cat > $local_config_dir/languages.ncl <<EOF
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
5650
{
57-
languages = {
58-
nu = {
59-
extensions = ["nu"],
60-
grammar.source.path = "${libtree-sitter-nu}/lib/libtree-sitter-nu${extension}",
61-
},
62-
},
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+
'';
6372
}
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-
)
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+
}

0 commit comments

Comments
 (0)