Repository navigation
Expand file tree
/
Copy pathpackage.nix
More file actions
191 lines (184 loc) · 5.92 KB
/
Copy pathpackage.nix
File metadata and controls
191 lines (184 loc) · 5.92 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
{
lib,
stdenvNoCC,
bun,
git,
makeBinaryWrapper,
}:
# okf runs from source under bun — `okf viz` bundles the Svelte viewer with
# Bun.build + an in-repo Svelte plugin at CLI runtime, so `bun build --compile` is out;
# the package ships the TypeScript tree plus vendored node_modules and a bun
# wrapper. Deps are a fixed-output `bun install` (no bun packaging helper exists
# in nixpkgs; this mirrors its opencode/helix-gpt packages). The repo okf
# operates on is resolved from the caller's working directory (lib.ts), never
# from the store path.
let
# Explicit include-list: nix plumbing stays out (nix-only edits don't rebuild
# the package) and node_modules can never leak in however the source reaches us.
sources = lib.fileset.unions [
# okf viz embeds the LICENSE (copyright + full text) into generated pages.
./LICENSE
./okf.ts
./init.ts
./setup.ts
./bootstrap.ts
./templates
./lib.ts
./config-cli.ts
./vcs
./scaffold.ts
./scaffold-api.ts
./migrate.ts
./migrate-doc.ts
./index-gen.ts
./validate.ts
./viz.ts
./viz-perf.ts
./layout3d.ts
./licenses.ts
./tsconfig.json
./package.json
./bun.lock
./bunfig.toml
./viz-app
./test
];
# Tests stay out of the shipped package: bun's test scanner follows the
# `result` symlink `nix build` leaves in the flake root, so any *.test.ts
# under $out would run as a stale second copy of the suite.
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.difference sources (
lib.fileset.unions [
./test
(lib.fileset.fileFilter (file: lib.hasSuffix ".test.ts" file.name) ./viz-app)
]
);
};
# Full tree including the tests — only checks.test builds from this.
testSrc = lib.fileset.toSource {
root = ./.;
fileset = sources;
};
# The lock is pure JS — no os/cpu-conditional packages, no install scripts —
# so one hash serves every platform; --cpu/--os="*" keeps that true if a
# future dep adds conditionals. --omit=optional: the only optional deps are
# the `bun` npm package (the npx/bunx fallback runtime — see bin/okf.mjs)
# and @typescript/native-preview's per-platform tsgo binaries (~26M each);
# the nix wrapper provides the real bun, and vendoring every platform's
# binaries into the store would be pure bloat. Consequence: the vendored
# tree cannot run the tsgo typecheck — `okf viz --check` needs a dev-tree
# `bun install` (which does fetch optionals). NOT --production:
# `okf viz` needs svelte (compiler + runtime) at CLI runtime, the tests
# happy-dom.
# Refresh the hash (bun.lock or nixpkgs bun changes): set lib.fakeHash, then
# `nix build ./flakes/okf#okf.node_modules` and copy the "got:" value.
node_modules = stdenvNoCC.mkDerivation {
pname = "okf-node_modules";
version = "0";
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./package.json
./bun.lock
];
};
nativeBuildInputs = [ bun ];
dontConfigure = true;
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
"GIT_PROXY_COMMAND"
"SOCKS_SERVER"
];
buildPhase = ''
runHook preBuild
export HOME=$TMPDIR
export BUN_INSTALL_CACHE_DIR=$TMPDIR/bun-cache
bun install \
--frozen-lockfile \
--ignore-scripts \
--no-progress \
--omit=optional \
--cpu="*" \
--os="*"
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir $out
cp -R node_modules $out/node_modules
runHook postInstall
'';
# Fixup would patch shebangs into store paths — forbidden in a fixed-output
# derivation.
dontFixup = true;
outputHash = "sha256-nGI76KBdqrL8/wvbEstArDoGVm3DVHcZP9Xd7t7GLN8=";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
};
in
stdenvNoCC.mkDerivation {
pname = "okf";
# Single version source: package.json (bumped by the release flow).
version = (lib.importJSON ./package.json).version;
inherit src;
nativeBuildInputs = [ makeBinaryWrapper ];
dontConfigure = true;
dontBuild = true;
# bun resolves imports by walking the entry file's parent directories, so the
# node_modules symlink beside the sources is found and followed; --no-install
# forbids any runtime fetch. git backs lib.ts's spawns (repo root, log, ls-files).
installPhase = ''
runHook preInstall
mkdir -p $out/lib/okf $out/bin
cp -R . $out/lib/okf
ln -s ${node_modules}/node_modules $out/lib/okf/node_modules
makeBinaryWrapper ${lib.getExe bun} $out/bin/okf \
--add-flags "run --prefer-offline --no-install" \
--add-flags "$out/lib/okf/okf.ts" \
--set-default OKF_PROG okf \
--prefix PATH : ${
lib.makeBinPath [
bun
git
]
}
runHook postInstall
'';
passthru = {
inherit node_modules;
# `bun test` offline against the vendored deps; surfaced as checks.test.
# git matches the runtime wrapper's PATH and lets the gitProvider tests
# run instead of skipIf-skipping.
tests.unit = stdenvNoCC.mkDerivation {
name = "okf-tests";
src = testSrc;
nativeBuildInputs = [
bun
git
];
dontConfigure = true;
buildPhase = ''
runHook preBuild
export HOME=$TMPDIR
export BUN_INSTALL_CACHE_DIR=$TMPDIR/bun-cache
ln -s ${node_modules}/node_modules node_modules
bun test
runHook postBuild
'';
installPhase = "touch $out";
};
};
meta = {
description = "CLI for maintaining OKF knowledge bundles (scaffold/index/validate/viz)";
# TODO(extraction): flips to the standalone repo URL when okf moves out.
homepage = "https://github.com/kriswill/okflight";
license = lib.licenses.mit;
mainProgram = "okf";
platforms = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
];
maintainers = [ { github = "kriswill"; } ];
};
}