This repository was archived by the owner on Sep 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpackage-cli.nix
More file actions
116 lines (101 loc) · 2.99 KB
/
Copy pathpackage-cli.nix
File metadata and controls
116 lines (101 loc) · 2.99 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
{ lib
, buildNpmPackage
, fetchurl
, importNpmLock
, makeWrapper
, nodejs_22
, codexSupport ? true
, codex
}:
let
packageJson = lib.importJSON ./npm/package.json;
packageJsonForNpm = builtins.removeAttrs packageJson [ "overrides" ];
packageLockJson = lib.importJSON ./npm/package-lock.json;
binPath =
let
rawBinPath =
if lib.isAttrs packageJson.bin then
packageJson.bin.t3
else
packageJson.bin;
in
lib.removePrefix "./" rawBinPath;
binCjsPath =
if lib.hasSuffix ".mjs" binPath then
"${lib.removeSuffix ".mjs" binPath}.cjs"
else
null;
in
buildNpmPackage rec {
pname = "t3-cli";
version = "0.0.25";
nodejs = nodejs_22;
src = fetchurl {
url = "https://registry.npmjs.org/t3/-/t3-${version}.tgz";
hash = "sha512-gCipUyG97jaul/V8QFSkF1zHj1a+oPHg/ihonPDfOiq+27mvQ1zjpxVA5uhStcf3Ef2iUbE/x6aLDpdONU0Q5w==";
};
sourceRoot = "package";
npmDeps = importNpmLock {
package = packageJsonForNpm;
packageLock = packageLockJson;
fetcherOpts = {
"node_modules/@effect/platform-node" = {
name = "platform-node.tgz";
};
"node_modules/@effect/platform-node-shared" = {
name = "platform-node-shared.tgz";
};
"node_modules/@effect/sql-sqlite-bun" = {
name = "sql-sqlite-bun.tgz";
};
"node_modules/effect" = {
name = "effect.tgz";
};
};
};
npmConfigHook = importNpmLock.npmConfigHook;
nativeBuildInputs = [ makeWrapper ];
dontNpmBuild = true;
postPatch = ''
cp ${./npm/package.json} package.json
cp ${./npm/package-lock.json} package-lock.json
${lib.optionalString (packageJson ? overrides) ''
node -e '
const fs = require("fs");
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
delete pkg.overrides;
fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n");
'
''}
bin_path=${lib.escapeShellArg binPath}
if [ ! -f "$bin_path" ]; then
echo "missing CLI entrypoint: $bin_path" >&2
exit 1
fi
sed -i "s/var version = \\\".*\\\";/var version = \\\"${version}\\\";/" "$bin_path"
${lib.optionalString (binCjsPath != null) ''
bin_cjs_path=${lib.escapeShellArg binCjsPath}
if [ -f "$bin_cjs_path" ]; then
sed -i "s/var version = \\\".*\\\";/var version = \\\"${version}\\\";/" "$bin_cjs_path"
fi
''}
'';
installPhase = ''
runHook preInstall
mkdir -p $out/lib/node_modules/t3 $out/bin
cp -r . $out/lib/node_modules/t3
makeWrapper ${nodejs_22}/bin/node $out/bin/t3 \
--add-flags "$out/lib/node_modules/t3/${binPath}" \
${lib.optionalString codexSupport ''
--prefix PATH : "${lib.makeBinPath [ codex ]}"
''}
runHook postInstall
'';
meta = with lib; {
description = "T3 Code CLI packaged from the upstream npm artifact";
homepage = "https://github.com/pingdotgg/t3code";
license = licenses.mit;
mainProgram = "t3";
platforms = platforms.unix;
};
}