-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
flake.nix
121 lines (101 loc) · 3.82 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
description = "tree-sitter-nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, nix-github-actions }: (
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
in
{
checks =
let
# shellPackages = (pkgs.callPackage ./shell.nix { }).packages;
# If the generated code differs from the checked in we need
# to check in the newly generated sources.
mkCheck = name: check: pkgs.runCommand name
{
inherit (self.devShells.${system}.default) nativeBuildInputs;
} ''
cp -rv ${self} src
chmod +w -R src
cd src
${check}
touch $out
'';
in
{
build = self.packages.${system}.tree-sitter-nix;
editorconfig = mkCheck "editorconfig" "editorconfig-checker";
# If the generated code differs from the checked in we need
# to check in the newly generated sources.
generated-diff = mkCheck "generated-diff" ''
HOME=. npm run generate
diff -r src/ ${self}/src
'';
treefmt = mkCheck "treefmt" "treefmt --no-cache --fail-on-change";
rust-bindings =
let
cargo' = lib.importTOML ./Cargo.toml;
in
pkgs.rustPlatform.buildRustPackage {
pname = cargo'.package.name;
inherit (cargo'.package) version;
src = self;
cargoLock = {
lockFile = ./Cargo.lock;
};
};
} // lib.optionalAttrs (!pkgs.stdenv.isDarwin) {
# Requires xcode
node-bindings =
let
package' = lib.importJSON ./package.json;
in
pkgs.stdenv.mkDerivation {
pname = package'.name;
inherit (package') version;
src = self;
nativeBuildInputs = with pkgs; [
importNpmLock.hooks.npmConfigHook
nodejs
nodejs.passthru.python # for node-gyp
npmHooks.npmBuildHook
npmHooks.npmInstallHook
tree-sitter
];
npmDeps = pkgs.importNpmLock {
npmRoot = ./.;
};
buildPhase = ''
runHook preBuild
${pkgs.nodePackages.node-gyp}/bin/node-gyp configure
npm run build
runHook postBuild
'';
installPhase = "touch $out";
};
};
packages.tree-sitter-nix = pkgs.callPackage ./default.nix { src = self; };
packages.default = self.packages.${system}.tree-sitter-nix;
devShells.default = pkgs.callPackage ./shell.nix { };
formatter = pkgs.writeShellScriptBin "tree-sitter-nix-fmt" ''
exec ${pkgs.treefmt}/bin/treefmt --config-file ${./treefmt.toml} "$@"
'';
})) // {
githubActions = nix-github-actions.lib.mkGithubMatrix {
# Inherit GHA actions matrix from a subset of platforms supported by hosted runners
checks = {
inherit (self.checks) x86_64-linux;
# Don't run linters on darwin as it's just scheduling overhead
x86_64-darwin = builtins.removeAttrs self.checks.x86_64-darwin [ "editorconfig" "generated-diff" "treefmt" ];
};
};
}
);
}