Skip to content

Commit 4abdcc9

Browse files
authored
feat: set up a basic flake (#38)
1 parent e5c4db1 commit 4abdcc9

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
4+
};
5+
outputs = {
6+
self,
7+
nixpkgs,
8+
...
9+
}: let
10+
systems = ["x86_64-linux" "aarch64-darwin"];
11+
buildEachSystem = output: builtins.map output systems;
12+
buildAllSystems = output: (
13+
builtins.foldl' nixpkgs.lib.recursiveUpdate {} (buildEachSystem output)
14+
);
15+
in
16+
buildAllSystems (system: let
17+
pkgs = import nixpkgs {inherit system;};
18+
in {
19+
packages.${system} = {
20+
topiary-nushell = pkgs.callPackage ./package.nix {
21+
tree-sitter-nu = builtins.fetchGit {
22+
url = "https://github.com/nushell/tree-sitter-nu";
23+
rev = "47d4b4f5369c0cae866724758ae88ef07e10e4f1";
24+
};
25+
};
26+
default = self.packages.${system}.topiary-nushell;
27+
};
28+
apps.${system} = {
29+
topiary-nushell = {
30+
type = "app";
31+
program = "${pkgs.lib.getExe self.packages.${system}.topiary-nushell}";
32+
meta = {
33+
description = "Topiary with NuShell support";
34+
};
35+
};
36+
default = self.apps.${system}.topiary-nushell;
37+
};
38+
});
39+
}

package.nix

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
stdenv,
3+
lib,
4+
writeShellApplication,
5+
tree-sitter-nu ? fetchGit "https://github.com/nushell/tree-sitter-nu",
6+
topiary,
7+
nushell,
8+
writeText,
9+
callPackage,
10+
}:
11+
writeShellApplication (let
12+
libtree-sitter-nu = callPackage ({
13+
lib,
14+
stdenv,
15+
}:
16+
stdenv.mkDerivation (finalAttrs: {
17+
pname = "tree-sitter-nu";
18+
version = tree-sitter-nu.rev;
19+
20+
src = tree-sitter-nu;
21+
22+
makeFlags = [
23+
# The PREFIX var isn't picking up from stdenv.
24+
"PREFIX=$(out)"
25+
];
26+
27+
meta = with lib; {
28+
description = "A tree-sitter grammar for nu-lang, the language of nushell";
29+
homepage = "https://github.com/nushell/tree-sitter-nu";
30+
license = licenses.mit;
31+
};
32+
})) {};
33+
in {
34+
name = "topiary-nushell";
35+
runtimeInputs = [nushell topiary];
36+
runtimeEnv = let
37+
extension = with stdenv;
38+
if isLinux
39+
then ".so"
40+
else if isDarwin
41+
then ".dylib"
42+
else throw "Unsupported system: ${system}";
43+
in {
44+
TOPIARY_CONFIG_FILE = writeText "languages.ncl" ''
45+
{
46+
languages = {
47+
nu = {
48+
extensions = ["nu"],
49+
grammar.source.path = "${libtree-sitter-nu}/lib/libtree-sitter-nu${extension}",
50+
},
51+
},
52+
}
53+
'';
54+
TOPIARY_LANGUAGE_DIR = ./languages;
55+
};
56+
text = ''
57+
${lib.getExe topiary} "$@"
58+
'';
59+
})

0 commit comments

Comments
 (0)