-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathflake.nix
More file actions
112 lines (96 loc) · 3.1 KB
/
flake.nix
File metadata and controls
112 lines (96 loc) · 3.1 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
{
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";
};
};
outputs =
{
self,
nixpkgs,
crane,
flake-utils,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
cargoToml = builtins.fromTOML (builtins.readFile ./crates/fff-nvim/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 pkgs.zig pkgs.llvmPackages.libclang.lib ];
buildInputs = with pkgs; [
# Add additional build inputs here
openssl
];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
my-crate = craneLib.buildPackage (
commonArgs
// {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
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;
};
packages = {
default = my-crate;
# 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;
};
# 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
];
};
}
);
}