-
Notifications
You must be signed in to change notification settings - Fork 147
/
flake.nix
116 lines (105 loc) · 3.58 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
{
description = "Set of simple, performant neovim plugins";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ flake-parts, nixpkgs, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems =
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
perSystem = { self, config, self', inputs', pkgs, system, lib, ... }: {
# use fenix overlay
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [ inputs.fenix.overlays.default ];
};
# define the packages provided by this flake
packages = let
fs = lib.fileset;
# nix source files (*.nix)
nixFs = fs.fileFilter (file: file.hasExt == "nix") ./.;
# rust source files
rustFs = fs.unions [
# Cargo.*
(fs.fileFilter (file: lib.hasPrefix "Cargo" file.name) ./.)
# *.rs
(fs.fileFilter (file: file.hasExt "rs") ./.)
# additional files
./.cargo
./rust-toolchain.toml
];
# nvim source files
# all that are not nix, nor rust
nvimFs = fs.difference ./. (fs.union nixFs rustFs);
version = "0.9.3";
in {
blink-fuzzy-lib = let
inherit (inputs'.fenix.packages.minimal) toolchain;
rustPlatform = pkgs.makeRustPlatform {
cargo = toolchain;
rustc = toolchain;
};
in rustPlatform.buildRustPackage {
pname = "blink-fuzzy-lib";
inherit version;
src = fs.toSource {
root = ./.;
fileset = rustFs;
};
cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};
nativeBuildInputs = with pkgs; [ git ];
};
blink-cmp = pkgs.vimUtils.buildVimPlugin {
pname = "blink-cmp";
inherit version;
src = fs.toSource {
root = ./.;
fileset = nvimFs;
};
preInstall = ''
mkdir -p target/release
ln -s ${self'.packages.blink-fuzzy-lib}/lib/libblink_cmp_fuzzy.* target/release/
'';
};
default = self'.packages.blink-cmp;
};
# builds the native module of the plugin
apps.build-plugin = {
type = "app";
program = let
buildScript = pkgs.writeShellApplication {
name = "build-plugin";
runtimeInputs = with pkgs; [ fenix.minimal.toolchain gcc ];
text = ''
export LIBRARY_PATH="${lib.makeLibraryPath [ pkgs.libiconv ]}";
cargo build --release
'';
};
in (lib.getExe buildScript);
};
# define the default dev environment
devShells.default = pkgs.mkShell {
name = "blink";
inputsFrom = [
self'.packages.blink-fuzzy-lib
self'.packages.blink-cmp
self'.apps.build-plugin
];
packages = with pkgs; [ rust-analyzer-nightly ];
};
formatter = pkgs.nixfmt-classic;
};
};
nixConfig = {
extra-substituters = [ "https://nix-community.cachix.org" ];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs"
];
};
}