-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.nix
More file actions
134 lines (119 loc) · 3.73 KB
/
Copy pathpackage.nix
File metadata and controls
134 lines (119 loc) · 3.73 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
{
lib,
stdenv,
rustPlatform,
fetchFromGitHub,
fetchurl,
installShellFiles,
clang,
cmake,
gitMinimal,
libclang,
libcap,
makeBinaryWrapper,
openssl,
pkg-config,
ripgrep,
versionCheckHook,
installShellCompletions ? stdenv.buildPlatform.canExecute stdenv.hostPlatform,
}:
let
rustyV8Version = "149.2.0";
rustyV8Archive =
if stdenv.hostPlatform.system == "x86_64-linux" then
fetchurl {
url = "https://github.com/denoland/rusty_v8/releases/download/v${rustyV8Version}/librusty_v8_release_x86_64-unknown-linux-gnu.a.gz";
hash = "sha256-iu2YY323533Iv7i7R1nsW95HLQv3lD9Y4OYqNQlFxVk=";
}
else if stdenv.hostPlatform.system == "aarch64-linux" then
fetchurl {
url = "https://github.com/denoland/rusty_v8/releases/download/v${rustyV8Version}/librusty_v8_release_aarch64-unknown-linux-gnu.a.gz";
hash = "sha256-+XdRJ8pk3MSjZi0BpSGizvuluY+DOUOog9hHc7Kv88U=";
}
else
throw "Unsupported platform for codex rusty_v8 archive: ${stdenv.hostPlatform.system}";
in
rustPlatform.buildRustPackage (finalAttrs: {
pname = "codex";
version = "0.144.4";
src = fetchFromGitHub {
owner = "openai";
repo = "codex";
tag = "rust-v${finalAttrs.version}";
hash = "sha256-NmYZxjNFPkRWN4rw+eeka10pJt6/oU3ZoLXBxj3dPRU=";
};
sourceRoot = "${finalAttrs.src.name}/codex-rs";
cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
extraRegistries = {
# Avoid crates.io API downloads, which have been flaky in GitHub Actions.
"https://github.com/rust-lang/crates.io-index" = "https://static.crates.io/crates";
};
};
nativeBuildInputs = [
clang
cmake
gitMinimal
installShellFiles
makeBinaryWrapper
pkg-config
];
buildInputs = [
libclang
libcap
openssl
];
preBuild = ''
# extraRegistries is needed only while Nix fetches crates. The generated
# Cargo config duplicates crates-io, so remove that stanza before build.
find /build -maxdepth 4 -path '*/.cargo/config.toml' -exec \
sed -i '/^[[:space:]]*\[source\."https:\/\/github\.com\/rust-lang\/crates\.io-index"\]$/,+2d' {} \;
'';
env = {
LIBCLANG_PATH = "${lib.getLib libclang}/lib";
NIX_CFLAGS_COMPILE = toString (
lib.optionals stdenv.cc.isGNU [ "-Wno-error=stringop-overflow" ]
++ lib.optionals stdenv.cc.isClang [ "-Wno-error=character-conversion" ]
);
# rust-v0.118.0 pulled in rusty_v8, whose build script otherwise attempts
# a network download that fails inside Nix sandboxed builds.
RUSTY_V8_ARCHIVE = rustyV8Archive;
# Upstream release profile uses fat LTO + single codegen unit, which is
# expensive on GitHub Actions runners.
CARGO_PROFILE_RELEASE_LTO = "off";
CARGO_PROFILE_RELEASE_CODEGEN_UNITS = "16";
};
cargoBuildFlags = [
"--package"
"codex-cli"
"--bin"
"codex"
];
cargoInstallFlags = [
"--package"
"codex-cli"
"--bin"
"codex"
];
doCheck = false;
postInstall = lib.optionalString installShellCompletions ''
installShellCompletion --cmd codex \
--bash <($out/bin/codex completion bash) \
--fish <($out/bin/codex completion fish) \
--zsh <($out/bin/codex completion zsh)
'';
postFixup = ''
wrapProgram $out/bin/codex --prefix PATH : ${lib.makeBinPath [ ripgrep ]}
'';
doInstallCheck = true;
nativeInstallCheckInputs = [ versionCheckHook ];
meta = {
description = "Lightweight coding agent that runs in your terminal";
homepage = "https://github.com/openai/codex";
changelog = "https://raw.githubusercontent.com/openai/codex/refs/tags/rust-v${finalAttrs.version}/CHANGELOG.md";
license = lib.licenses.asl20;
mainProgram = "codex";
platforms = lib.platforms.unix;
};
})