Repository navigation
Expand file tree
/
Copy pathdefault.nix
More file actions
139 lines (120 loc) · 4.25 KB
/
Copy pathdefault.nix
File metadata and controls
139 lines (120 loc) · 4.25 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
{
pkgs,
root-src,
compile-rust,
get-root-subtree,
build-config,
patch-yaml-schema,
genvm-tool,
patch-llm-config,
patch-web-config,
patch-rpath,
host-system,
host-system-as-genvm,
compiled-libs,
...
}@args:
let
lib = pkgs.lib;
monorepo = builtins.fromJSON (builtins.readFile (root-src + "/.genvm-monorepo-root"));
release-src = get-root-subtree (
[
".genvm-monorepo-root"
"install"
"libs/unhardcoded-engine/llm_policy"
"libs/unhardcoded-engine/llm_policy.lua"
]
++ builtins.map (line: "executors/${line}.x/manifest.json") (
builtins.attrNames monorepo.executor-lines
)
);
runner-forks = builtins.toFile "runner-forks.json" (
builtins.toJSON (import (root-src + "/runners/forks.nix") { inherit root-src; })
);
# The shipped LLM dispatch script requires the `llm_policy` package, which
# lives in the unhardcoded-engine submodule instead of under install/.
llm-policy-src = release-src + "/libs/unhardcoded-engine";
make-for-target =
target:
let
exe = compile-rust rec {
inherit target;
pname = "genvm-modules-bin";
version = "0.1.0";
profile = "release-with-debug";
cargoLock.lockFile = ./Cargo.lock;
src = get-root-subtree [
"implementation"
"crates/modules-interfaces"
"crates/calldata"
"crates/calldata-derive"
# a dev-dependency of the executor crates below, but cargo still needs its manifest
"crates/fuzzing"
# executor crates come from the v0.4.x submodule mount
"executors/v0.4.x/executor/crates"
];
sourceRoot = "./source/implementation";
extraLibs = compiled-libs.${target};
LUA_LIB_NAME = "lua";
LSQLITE3_PREBUILT = "1";
GENVM_PROFILE = build-config.executor-version;
};
in
pkgs.stdenvNoCC.mkDerivation rec {
name = "genvm-manager-${target}";
srcs = [
exe
(release-src + "/install")
]
++ compiled-libs.${target};
dontUnpack = true;
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [
pkgs.makeWrapper
patch-yaml-schema
genvm-tool
patch-llm-config
patch-web-config
patch-rpath
];
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/lib
cp ${exe} "$out/bin/genvm-modules"
for src in $srcs; do
if [[ "$src" != "${exe}" ]]
then
cp --no-preserve=ownership -r "$src/." "$out/."
chmod -R u+w "$out"
fi
done
# compiled-libs doubles as the link input and as a copy source, so its
# static archives land here too; they are already inside the binary.
rm -f "$out"/lib/*.a
if [ ! -f "${llm-policy-src}/llm_policy.lua" ]; then
echo "${llm-policy-src} is missing or incomplete; run \`git submodule update --init libs/unhardcoded-engine\`" >&2
exit 1
fi
cp --no-preserve=ownership "${llm-policy-src}/llm_policy.lua" "$out/lib/genvm-lua/llm_policy.lua"
cp --no-preserve=ownership -r "${llm-policy-src}/llm_policy" "$out/lib/genvm-lua/llm_policy"
chmod -R u+w "$out/lib/genvm-lua"
patch-yaml-schema --tag ${build-config.executor-version} "$out"
patch-llm-config --tag ${build-config.executor-version} "$out/config/genvm-module-llm.yaml"
patch-web-config --tag ${build-config.executor-version} "$out/config/genvm-module-web.yaml"
# Assemble data/manifest.yaml from the active executor submodules
# (executor-version + fork), the runner forks and the static base fields.
genvm-tool -C ${release-src} build-manifest --runner-forks ${runner-forks} --output "$out/data/manifest.yaml"
patch-rpath --codesign --search-dir "$out/lib" --rpath '$ORIGIN/../lib' "$out/bin/genvm-modules"
find "$out/lib" -type f -name '*.so' -not -name 'libc.so' | while read lib; do
patch-rpath --search-dir "$out/lib" --rpath '$ORIGIN' "$lib"
done
'';
};
in
{
manager = make-for-target host-system-as-genvm;
manager-amd64-linux = make-for-target "amd64-linux";
manager-arm64-linux = make-for-target "arm64-linux";
manager-arm64-macos = make-for-target "arm64-macos";
}