From b2d16e877c64f2ab5ab7453e497b9475e8b1730c Mon Sep 17 00:00:00 2001 From: Notarin Steele <424c414e4b@gmail.com> Date: Sun, 23 Nov 2025 16:45:20 -0500 Subject: [PATCH] feat: set up a basic flake --- flake.lock | 27 ++++++++++++++++++++++++ flake.nix | 39 +++++++++++++++++++++++++++++++++++ package.nix | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1150e27 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1763618868, + "narHash": "sha256-v5afmLjn/uyD9EQuPBn7nZuaZVV9r+JerayK/4wvdWA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a8d610af3f1a5fb71e23e08434d8d61a466fc942", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2c75813 --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + outputs = { + self, + nixpkgs, + ... + }: let + systems = ["x86_64-linux" "aarch64-darwin"]; + buildEachSystem = output: builtins.map output systems; + buildAllSystems = output: ( + builtins.foldl' nixpkgs.lib.recursiveUpdate {} (buildEachSystem output) + ); + in + buildAllSystems (system: let + pkgs = import nixpkgs {inherit system;}; + in { + packages.${system} = { + topiary-nushell = pkgs.callPackage ./package.nix { + tree-sitter-nu = builtins.fetchGit { + url = "https://github.com/nushell/tree-sitter-nu"; + rev = "47d4b4f5369c0cae866724758ae88ef07e10e4f1"; + }; + }; + default = self.packages.${system}.topiary-nushell; + }; + apps.${system} = { + topiary-nushell = { + type = "app"; + program = "${pkgs.lib.getExe self.packages.${system}.topiary-nushell}"; + meta = { + description = "Topiary with NuShell support"; + }; + }; + default = self.apps.${system}.topiary-nushell; + }; + }); +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..b1ca258 --- /dev/null +++ b/package.nix @@ -0,0 +1,59 @@ +{ + stdenv, + lib, + writeShellApplication, + tree-sitter-nu ? fetchGit "https://github.com/nushell/tree-sitter-nu", + topiary, + nushell, + writeText, + callPackage, +}: +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)" + ]; + + 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; + }; + })) {}; +in { + name = "topiary-nushell"; + runtimeInputs = [nushell topiary]; + runtimeEnv = let + extension = with stdenv; + if isLinux + then ".so" + else if isDarwin + then ".dylib" + else throw "Unsupported system: ${system}"; + in { + 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} "$@" + ''; +})