-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
123 lines (113 loc) · 4.13 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
122
123
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
fenix.url = "github:nix-community/fenix";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
nixpkgs,
flake-utils,
crane,
...
} @ inputs:
flake-utils.lib.eachSystem (flake-utils.lib.defaultSystems) (
system: let
extensionToml = builtins.fromTOML (builtins.readFile ./extension.toml);
# Template Variables
plugin-id = builtins.replaceStrings ["-"] ["_"] extensionToml.id;
isGrammar = builtins.hasAttr "grammars" extensionToml;
lang = if isGrammar
then builtins.head (builtins.attrNames extensionToml.grammars)
else "";
lsp-name = if isGrammar && builtins.hasAttr "language_servers" extensionToml
then builtins.head (builtins.attrNames extensionToml.language_servers)
else "";
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
fenix = inputs.fenix.packages.${system};
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
grammar = if isGrammar then
pkgs.stdenv.mkDerivation rec {
pname = lang + "_grammar";
version = extensionToml.grammars.${lang}.commit;
src = builtins.fetchGit {
rev = version;
url = extensionToml.grammars.${lang}.repository;
};
buildInputs = with pkgs; [ docker tree-sitter ];
# FIX: not compile
buildPhase = ''
HOME=$(mktemp -d fake-homeXXXX)
tree-sitter build --wasm -o $out
'';
} else null;
# fenix: rustup replacement for reproducible builds
toolchain = fenix.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-VZZnlyP69+Y3crrLHQyJirqlHrTtGTsyiSnZB8jEvVo=";
};
buildInputs = with pkgs; [ pkg-config ];
extension-wasm = craneLib.buildPackage {
doCheck = false;
pname = plugin-id;
src = craneLib.cleanCargoSource (craneLib.path ./.);
cargoExtraArgs = "--target wasm32-wasip1";
installPhaseCommand = ''
mkdir -p $out
cp target/wasm32-wasip1/release/${plugin-id}.wasm $out/extension.wasm
'';
inherit buildInputs;
};
extension-lsp = if lsp-name != "" then craneLib.buildPackage {
doCheck = false;
pname = plugin-id;
src = craneLib.cleanCargoSource (craneLib.path ./.);
buildPhaseCargoCommand = "cargo build --release -p ${lsp-name}";
installPhaseCommand = ''
mkdir -p $out
cp target/release/${lsp-name} $out/
'';
inherit buildInputs;
} else null;
# Lista de paths que siempre incluiremos
basePaths = [ extension-wasm ]
++ lib.optional (extension-lsp != null) extension-lsp
++ lib.optional (grammar != null) grammar;
all = pkgs.symlinkJoin {
name = plugin-id;
paths = basePaths;
postBuild = ''
cp ${./extension.toml} $out/extension.toml
${lib.optionalString (builtins.pathExists ./languages) ''
cp -r ${./languages} $out/languages
''}
'';
};
in {
# `nix build`
packages = rec {
default = extension;
extension = all;
wasm = extension-wasm;
} // lib.optionalAttrs (extension-lsp != null) {
lsp = extension-lsp;
} // lib.optionalAttrs (grammar != null) {
inherit grammar;
};
# `nix develop`
devShells.default = pkgs.mkShell {
packages = with pkgs; [
cargo-dist
cargo-release
docker
tree-sitter
];
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
};
}
);
}