This repository was archived by the owner on Apr 6, 2026. It is now read-only.
forked from Jesssullivan/tinyland-hexstrunk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
271 lines (232 loc) · 9.28 KB
/
flake.nix
File metadata and controls
271 lines (232 loc) · 9.28 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
{
description = "HexStrike-AI — auditable, provable cybersecurity MCP platform";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = { config, pkgs, lib, system, ... }:
let
# ── OCaml package set ────────────────────────────────
# OCaml has a known test failure on aarch64-darwin
# (tests/unwind/driver.ml fails for both 5.2 and 5.3).
# Skip OCaml's test suite on darwin; it compiles fine.
ocamlPkgs = if pkgs.stdenv.hostPlatform.isDarwin then
pkgs.ocamlPackages.overrideScope (self: super: {
ocaml = super.ocaml.overrideAttrs (old: { doCheck = false; });
})
else
pkgs.ocamlPackages;
# ── Futhark compiled kernels ──────────────────────────
# Each kernel is compiled to a separate shared library to avoid
# symbol collisions (all export futhark_context_new etc.)
# Source is in futhark/out/ (gitignored, built by CI futhark-build job).
# For local dev, the OCaml FFI bridge falls back to pure-OCaml stubs.
# Build locally: just futhark-build && just futhark-kernels
sharedLibExt = if pkgs.stdenv.hostPlatform.isDarwin then "dylib" else "so";
# ── OCaml package dependencies ─────────────────────────
ocamlDeps = with ocamlPkgs; [
findlib yojson cmdliner sha uuidm logs fmt ctypes ctypes-foreign
];
ocamlTestDeps = with ocamlPkgs; [ alcotest ];
# ── Security tool runtime ──────────────────────────────
# Every binary declared in dhall/tools/*.dhall requiredBinaries
# plus execute_command.ml whitelist.
#
# Some packages are broken on aarch64-darwin in nixpkgs-unstable:
# - samba 4.22: test_ldb_comparison_fold build failure
# - thc-hydra: depends on samba/libssh which fails
# - checkov/prowler: pycep-parser needs uv_build
# These are available in the container (Linux) or via pip overlay.
securityTools = with pkgs; [
# Network/Recon
nmap
subfinder
dig
# Crypto
openssl
# Web security
curl
nuclei
sqlmap
dalfox
wafw00f
katana
# Cloud/Container
trivy
kube-bench
# CredentialAudit
john
] ++ lib.optionals (!pkgs.stdenv.hostPlatform.isDarwin) [
# These build on Linux but fail on macOS:
thc-hydra # needs libssh/samba
samba # smbclient, rpcclient
binutils # objdump, readelf, strings (GNU ar conflicts with macOS ld)
] ++ (with pkgs; [
# BinaryAnalysis
binwalk
# Forensics
exiftool
foremost
# Intelligence
exploitdb # searchsploit
# API Testing
ffuf
# Credentials/Utils
sops
wget
netcat-gnu
git
openssh
gnugrep
coreutils
bash
]);
in {
treefmt = {
projectRootFile = "flake.nix";
programs.ocamlformat.enable = true;
programs.nixpkgs-fmt.enable = true;
};
# ── Packages ──────────────────────────────────────────
packages = {
# OCaml MCP server binary
hexstrike-mcp = ocamlPkgs.buildDunePackage {
pname = "hexstrike-mcp";
version = "0.2.0";
src = ./ocaml;
duneVersion = "3";
buildInputs = ocamlDeps;
checkInputs = ocamlTestDeps;
doCheck = true;
meta.description = "HexStrike MCP server — verified cybersecurity tool dispatch";
};
# Go gateway binary
hexstrike-gateway = pkgs.buildGoModule {
pname = "hexstrike-gateway";
version = "0.2.0";
src = ./gateway;
vendorHash = "sha256-Vz+WNq66jZkmzFrIpIf1ZqcG4JjTonqDI3bEllUZUm4=";
subPackages = [ "cmd/hexstrike-gateway" ];
meta.description = "HexStrike gateway — tsnet + policy + metering";
};
# Compiled Dhall policies (JSON)
hexstrike-policies = pkgs.runCommand "hexstrike-policies" {
nativeBuildInputs = [ pkgs.dhall-json ];
src = ./dhall;
} ''
mkdir -p $out
dhall-to-json --file $src/render.dhall --output $out/tool-manifest.json
dhall-to-json --file $src/policies/compose.dhall --output $out/policy.json
'';
# Full-fat OCI container image
container = pkgs.dockerTools.buildLayeredImage {
name = "ghcr.io/tinyland-inc/hexstrike-ai";
tag = "edge";
contents = [
config.packages.hexstrike-mcp
config.packages.hexstrike-gateway
config.packages.hexstrike-policies
pkgs.cacert
] ++ securityTools;
config = {
Entrypoint = [ "hexstrike-gateway" ];
Cmd = [
"-mcp-binary" "hexstrike-mcp"
"-policy" "/compiled/policy.json"
"-listen" ":8080"
"-metrics" ":9090"
];
Env = [
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"HEXSTRIKE_RESULTS_DIR=/results"
"HEXSTRIKE_POLICY_PATH=/compiled/policy.json"
];
WorkingDir = "/workspace";
Volumes = {
"/workspace" = {};
"/results" = {};
};
ExposedPorts = {
"8080/tcp" = {};
"9090/tcp" = {};
};
};
# Symlink compiled policies into /compiled for gateway Cmd default
extraCommands = ''
mkdir -p compiled
ln -s ${config.packages.hexstrike-policies}/policy.json compiled/policy.json
ln -s ${config.packages.hexstrike-policies}/tool-manifest.json compiled/tool-manifest.json
mkdir -p workspace results
'';
};
default = config.packages.hexstrike-gateway;
};
# ── Dev Shells ────────────────────────────────────────
# F* has its own OCaml 5.3 dep tree that may not be cached.
# Split into two shells: default (fast, cached) and fstar (includes F*).
devShells.default = pkgs.mkShell {
name = "hexstrike-dev";
inputsFrom = [
config.packages.hexstrike-mcp
];
packages = with pkgs; [
# Dhall
dhall
dhall-json
dhall-lsp-server
# Futhark
futhark
# Go (for gateway)
go
# Build tools
just
gnumake
# Utilities
jq
] ++ securityTools;
shellHook = ''
# Futhark kernels: set path if locally built
if [ -d "futhark/lib" ]; then
export FUTHARK_KERNEL_PATH="$PWD/futhark/lib"
'' + (if pkgs.stdenv.hostPlatform.isDarwin then ''
export DYLD_LIBRARY_PATH="$PWD/futhark/lib''${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}"
'' else ''
export LD_LIBRARY_PATH="$PWD/futhark/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
'') + ''
fi
echo "hexstrike-dev shell ready"
echo " dhall : $(dhall version 2>/dev/null || echo 'not found')"
echo " futhark : $(futhark --version 2>/dev/null || echo 'not found')"
echo " ocaml : $(ocaml --version 2>/dev/null || echo 'not found')"
echo " dune : $(dune --version 2>/dev/null || echo 'not found')"
echo " go : $(go version 2>/dev/null || echo 'not found')"
echo " just : $(just --version 2>/dev/null || echo 'not found')"
'';
};
# Full shell with F* + Z3 (may require building from source)
devShells.fstar = pkgs.mkShell {
name = "hexstrike-fstar";
inputsFrom = [ config.devShells.default ];
packages = with pkgs; [
fstar
z3
];
shellHook = ''
echo "hexstrike-fstar shell ready"
echo " fstar : $(fstar.exe --version 2>/dev/null | head -1 || echo 'not found')"
echo " z3 : $(z3 --version 2>/dev/null || echo 'not found')"
'';
};
};
};
}