Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 66 additions & 67 deletions package.nix
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
{
stdenv,
lib,
runCommand,
writeShellApplication,
tree-sitter-nu ? fetchGit "https://github.com/nushell/tree-sitter-nu",
topiary,
nushell,
writeText,
callPackage,
symlinkJoin,
}:
symlinkJoin {
name = "topiary-nushell";
paths = [
(writeShellApplication (
let
libtree-sitter-nu = callPackage (
{
lib,
stdenv,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "tree-sitter-nu";
version = tree-sitter-nu.rev;
writeShellApplication (
let
libtree-sitter-nu = callPackage (
{
lib,
stdenv,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "tree-sitter-nu";
version = tree-sitter-nu.rev;

src = tree-sitter-nu;

makeFlags = [
# The PREFIX var isn't picking up from stdenv.
"PREFIX=$(out)"
];

src = tree-sitter-nu;
meta = with lib; {
description = "A tree-sitter grammar for nu-lang, the language of nushell";
homepage = "https://github.com/nushell/tree-sitter-nu";
license = licenses.mit;
};
})
) { };

extension =
with stdenv;
if isLinux then
".so"
else if isDarwin then
".dylib"
else
throw "Unsupported system: ${system}";

makeFlags = [
# The PREFIX var isn't picking up from stdenv.
"PREFIX=$(out)"
];
# Create a directory holding ALL runtime config files
# This makes a single path for GC root.
topiaryConfigDir = runCommand "topiary-nushell-config" { } ''
local_config_dir="$out"

meta = with lib; {
description = "A tree-sitter grammar for nu-lang, the language of nushell";
homepage = "https://github.com/nushell/tree-sitter-nu";
license = licenses.mit;
};
})
) { };
# 1. Copy the nu.scm language directory
mkdir -p $local_config_dir/languages
cp ${./languages/nu.scm} $local_config_dir/languages/nu.scm

extension =
with stdenv;
if isLinux then
".so"
else if isDarwin then
".dylib"
else
throw "Unsupported system: ${system}";
in
cat > $local_config_dir/languages.ncl <<EOF
{
name = "topiary-nushell";
runtimeInputs = [
nushell
topiary
];
runtimeEnv = {
TOPIARY_CONFIG_FILE = writeText "languages.ncl" ''
{
languages = {
nu = {
extensions = ["nu"],
grammar.source.path = "${libtree-sitter-nu}/lib/libtree-sitter-nu${extension}",
},
},
}
'';
TOPIARY_LANGUAGE_DIR = ./languages;
};
text = ''
${lib.getExe topiary} "$@"
'';
languages = {
nu = {
extensions = ["nu"],
grammar.source.path = "${libtree-sitter-nu}/lib/libtree-sitter-nu${extension}",
},
},
}
))
./.
];
meta = with lib; {
description = "topiary formatter for nushell";
homepage = "https://github.com/blindFS/topiary-nushell";
license = licenses.mit;
mainProgram = "topiary-nushell";
};
}
EOF
'';
in
{
name = "topiary-nushell";
runtimeInputs = [
nushell
topiary
];
runtimeEnv = {
TOPIARY_CONFIG_FILE = "${topiaryConfigDir}/languages.ncl";
TOPIARY_LANGUAGE_DIR = "${topiaryConfigDir}/languages";
};
text = ''
${lib.getExe topiary} "$@"
'';
}
)