-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
74 lines (67 loc) · 2.27 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
llama-cpp.url = "github:ggerganov/llama.cpp";
};
outputs = { self, nixpkgs, flake-utils, llama-cpp }:
flake-utils.lib.eachSystem ["x86_64-linux"] (system:
with nixpkgs.legacyPackages.${system};
let
t = lib.trivial;
hl = haskell.lib;
haskellPackages = haskell.packages.ghc945;
name = "llama.cpp-bindings";
llama-cpp-with-includes =
llama-cpp.packages.${system}.default.overrideAttrs (oldAttrs: {
postInstall = (oldAttrs.postInstall or "") + ''
mkdir -p $out/lib
mkdir -p $out/include
cp *.a $out/lib/
cp $src/*.h $out/include/
# I don't think ghc/c2hs can process common.h because
# it is C++, but it contains default params that I want to
# auto-import somehow
cp $src/examples/*.h $out/include/
'';
});
project = devTools:
let
addBuildTools = (t.flip hl.addBuildTools) (devTools ++ [
zlib
haskellPackages.c2hs
llama-cpp-with-includes
]);
in
haskellPackages.developPackage {
root = ./.;
name = name;
returnShellEnv = !(devTools == []);
modifier = (t.flip t.pipe) [
addBuildTools
hl.dontHaddock
hl.enableExecutableProfiling
(drv: hl.overrideCabal drv (attrs: {
configureFlags = [
"--ghc-options=-fprof-auto"
"--extra-include-dirs=${llama-cpp-with-includes}/include"
"--extra-lib-dirs=${llama-cpp-with-includes}/lib"
];
}))
];
};
in {
packages = {
pkg = project [ ];
default = self.packages.${system}.pkg;
llama-cpp = llama-cpp-with-includes;
};
devShell = project (with haskellPackages; [
cabal-fmt
cabal-install
haskell-language-server
hlint
watchexec
]);
});
}