-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathdefault.nix
More file actions
153 lines (130 loc) · 4.17 KB
/
Copy pathdefault.nix
File metadata and controls
153 lines (130 loc) · 4.17 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
{
flake-utils,
nixpkgs,
self,
...
}:
let
systems = [
"aarch64-darwin"
"x86_64-darwin"
"aarch64-linux"
"x86_64-linux"
];
in
flake-utils.lib.eachSystem systems (
system:
let
pkgs = import nixpkgs { inherit system; };
appVersion = "26.901.41123";
codexZip = pkgs.fetchurl {
url = "https://persistent.oaistatic.com/codex-app-prod/ChatGPT-darwin-arm64-${appVersion}.zip";
hash = "sha256-8Nb8q26xxmrE+FhbxbVpJrLYdwDHt8wRRCnntUAZP9Y=";
};
codex = self.packages.${system}.codex;
in
{
devShells.default = pkgs.mkShell {
HOSTED_CODEX_APP_ZIP = codexZip;
packages = [
codex
pkgs.nodejs
pkgs.unzip
pkgs.patch
];
};
packages =
let
nodeSources = pkgs.srcOnly pkgs.nodejs;
npmDeps = pkgs.importNpmLock {
npmRoot = ./.;
};
betterSqlite3Native = pkgs.stdenv.mkDerivation {
pname = "better-sqlite3-native";
version = "12.9.0";
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./package.json
./package-lock.json
];
};
inherit npmDeps;
npmRebuildFlags = [ "--ignore-scripts" ];
nativeBuildInputs = [
pkgs.importNpmLock.npmConfigHook
pkgs.nodejs
pkgs.python3
pkgs.removeReferencesTo
]
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [ pkgs.cctools ];
buildPhase = ''
runHook preBuild
pushd node_modules/better-sqlite3
npm run build-release --offline --nodedir="${nodeSources}"
rm -rf build/Release/{.deps,obj,obj.target,test_extension.node}
find build -type f -exec ${pkgs.lib.getExe pkgs.removeReferencesTo} -t "${nodeSources}" {} \;
popd
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
cp -R node_modules/better-sqlite3/build "$out/build"
runHook postInstall
'';
};
in
{
default = pkgs.buildNpmPackage {
HOSTED_CODEX_APP_ZIP = codexZip;
pname = "codex-web";
version = "1.0.0";
src = ./.;
inherit npmDeps;
npmConfigHook = pkgs.importNpmLock.npmConfigHook;
npmBuildScript = "build";
npmRebuildFlags = [ "--ignore-scripts" ];
npmPruneFlags = [ "--ignore-scripts" ];
nativeBuildInputs = [
pkgs.unzip
pkgs.patch
];
preBuild = ''
patchShebangs scripts
'';
preInstall = ''
# npm pack always runs the package prepare lifecycle. Nix already ran
# the explicit build script above, so remove prepare in the sandbox.
node -e '
const fs = require("fs");
const packageJsonPath = "package.json";
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
delete packageJson.scripts.prepare;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
'
# Keep only extracted asar artifacts for packaging.
rm -rf scratch/ChatGPT.app
# npm pack drops directories named node_modules, so rename the nested
# asar tree in-place to keep it in the package output.
mv scratch/asar/node_modules scratch/asar/asar_node_modules
'';
postInstall = ''
mv $out/lib/node_modules/codex-web/scratch/asar/{asar_,}node_modules
addon="$out/lib/node_modules/codex-web/node_modules/better-sqlite3"
rm -rf "$addon/build"
ln -s ${betterSqlite3Native}/build "$addon/build"
'';
};
codex_remote_proxy = pkgs.writeShellApplication {
name = "codex_remote_proxy";
runtimeInputs = with pkgs; [
bash
coreutils
websocat
];
text = builtins.readFile ./scripts/codex_remote_proxy;
};
};
}
)