Add flake build

This commit is contained in:
xenia 2023-11-11 23:27:34 +01:00
parent 7c0c72b8b7
commit 387beff54d
4 changed files with 110 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.direnv

59
flake.lock Normal file
View File

@ -0,0 +1,59 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1697009197,
"narHash": "sha256-viVRhBTFT8fPJTb1N3brQIpFZnttmwo3JVKNuWRVc3s=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01441e14af5e29c9d27ace398e6dd0b293e25a54",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

49
flake.nix Normal file
View File

@ -0,0 +1,49 @@
{
description = "Tree sitter collection";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (sys:
let pkgs = nixpkgs.legacyPackages.${sys};
deps = [ pkgs.tree-sitter pkgs.nodejs pkgs.gcc ];
compile-tree-sitter = { src, name }: pkgs.stdenv.mkDerivation {
# inherit src name;
src = src;
name = name;
nativeBuildInputs = deps;
buildPhase = ''
tree-sitter generate
'';
installPhase = ''
mkdir -p "$out"
cp -r src "$out/src"
touch src/scanner.c
gcc -c src/parser.c -o parser.o
gcc -c src/scanner.c -o scanner.o
ar rcs "$out/parser.a" parser.o scanner.o
gcc -shared src/scanner.c src/parser.c -o "$out/lib-tree-sitter-$name.so"
'';
# TODO: Get tests working
# For some reason, just doing tree-sitter test fails with "read-only file system"
};
in rec {
packages.agda = compile-tree-sitter { src = ./agda; name = "agda"; };
packages.bash = compile-tree-sitter { src = ./bash; name = "bash"; };
packages.c = compile-tree-sitter { src = ./c; name = "c"; };
packages.nix = compile-tree-sitter { src = ./nix; name = "nix"; };
packages.python = compile-tree-sitter { src = ./python; name = "python"; };
packages.rust = compile-tree-sitter { src = ./rust; name = "rust"; };
}
);
}