forked from dmtrKovalenko/fff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
154 lines (131 loc) · 4.59 KB
/
Copy pathflake.nix
File metadata and controls
154 lines (131 loc) · 4.59 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
description = "fff.nvim";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
zig-overlay = {
url = "github:mitchellh/zig-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
crane,
flake-utils,
rust-overlay,
zig-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
# zlob requires Zig >= 0.16, but nixpkgs tops out at 0.15. Pull from
# mitchellh/zig-overlay which ships every released version.
zig = zig-overlay.packages.${system}."0.16.0";
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
cargoToml = builtins.fromTOML (builtins.readFile ./crates/fff-nvim/Cargo.toml);
fffMcpCargoToml = builtins.fromTOML (builtins.readFile ./crates/fff-mcp/Cargo.toml);
# Common arguments can be set here to avoid repeating them later
# Note: changes here will rebuild all dependency crates
commonArgs = {
pname = cargoToml.package.name;
version = cargoToml.package.version;
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
nativeBuildInputs = [ pkgs.pkg-config pkgs.perl zig pkgs.llvmPackages.libclang.lib ];
buildInputs = with pkgs; [
# Add additional build inputs here
openssl
];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
# Zig 0.16 insists on writing to its global cache even when the
# zlob build.rs passes --global-cache-dir. In the nix sandbox $HOME
# is /homeless-shelter (unwritable), so redirect to $TMPDIR before
# the build phase runs.
preBuild = ''
export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-global-cache"
export ZIG_LOCAL_CACHE_DIR="$TMPDIR/zig-local-cache"
export XDG_CACHE_HOME="$TMPDIR/cache"
mkdir -p "$ZIG_GLOBAL_CACHE_DIR" "$ZIG_LOCAL_CACHE_DIR" "$XDG_CACHE_HOME"
'';
};
my-crate = craneLib.buildPackage (
commonArgs
// {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
doCheck = false;
}
);
fff-mcp-args = commonArgs // {
pname = fffMcpCargoToml.package.name;
version = fffMcpCargoToml.package.version;
cargoExtraArgs = "-p fff-mcp --bin fff-mcp";
};
fff-mcp = craneLib.buildPackage (
fff-mcp-args
// {
cargoArtifacts = craneLib.buildDepsOnly fff-mcp-args;
doCheck = false;
}
);
# Copies the dynamic library into the target/release folder
copy-dynamic-library = /* bash */ ''
set -eo pipefail
mkdir -p target/release
if [ "$(uname)" = "Darwin" ]; then
cp -vf ${my-crate}/lib/libfff_nvim.dylib target/release/libfff_nvim.dylib
else
cp -vf ${my-crate}/lib/libfff_nvim.so target/release/libfff_nvim.so
fi
echo "Library copied to target/release/"
'';
in
{
checks = {
inherit my-crate fff-mcp;
};
packages = {
default = my-crate;
inherit fff-mcp;
# Neovim plugin
fff-nvim = pkgs.vimUtils.buildVimPlugin {
pname = "fff.nvim";
version = "main";
src = pkgs.lib.cleanSource ./.;
postPatch = copy-dynamic-library;
doCheck = false; # Skip require check since we have a Rust FFI component
};
};
apps.default = flake-utils.lib.mkApp {
drv = my-crate;
};
apps.fff-mcp = flake-utils.lib.mkApp {
drv = fff-mcp;
};
# Add the release command
apps.release = flake-utils.lib.mkApp {
drv = pkgs.writeShellScriptBin "release" copy-dynamic-library;
};
devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = [
# pkgs.ripgrep
];
};
}
);
}