forked from ilysenko/codex-desktop-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
151 lines (134 loc) · 4.23 KB
/
Copy pathflake.nix
File metadata and controls
151 lines (134 loc) · 4.23 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
{
description = "Codex Desktop for Linux installer";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
sourceRoot = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
pkgs.lib.cleanSourceFilter path type
&& (let
pathStr = toString path;
in
!(pkgs.lib.hasSuffix "/.codex" pathStr || pkgs.lib.hasInfix "/.codex/" pathStr));
};
codexDmg = pkgs.fetchurl {
url = "https://persistent.oaistatic.com/codex-app-prod/Codex.dmg";
hash = "sha256-kN13FvJgE1t28/Ej+LcFfr57Z720MtAJgyzpDQBcx1M=";
};
electronLibs = with pkgs; [
glib
gtk3
pango
cairo
gdk-pixbuf
atk
at-spi2-atk
at-spi2-core
nss
nspr
dbus
cups
expat
libdrm
mesa
libgbm
alsa-lib
libX11
libXcomposite
libXdamage
libXext
libXfixes
libXrandr
libxcb
libxkbcommon
libxcursor
libxi
libxtst
libxscrnsaver
libglvnd
systemd
wayland
];
electronLibPath = pkgs.lib.makeLibraryPath electronLibs;
installer = pkgs.writeShellApplication {
name = "codex-desktop-installer";
runtimeInputs = [
pkgs.bash
pkgs.nodejs
pkgs.python3
pkgs.p7zip
pkgs.curl
pkgs.unzip
pkgs.gnumake
pkgs.gcc
pkgs.patchelf
];
text = ''
set -euo pipefail
root_dir="$(pwd)"
workdir="$(mktemp -d)"
source_dir="$workdir/source"
cleanup() {
rm -rf "$workdir"
}
trap cleanup EXIT
mkdir -p "$source_dir"
cp -R ${sourceRoot}/. "$source_dir"
chmod -R u+w "$source_dir"
cp ${codexDmg} "$source_dir/Codex.dmg"
chmod +x "$source_dir/install.sh"
cd "$source_dir"
export CODEX_INSTALL_DIR="''${CODEX_INSTALL_DIR:-$root_dir/codex-app}"
${pkgs.bash}/bin/bash "$source_dir/install.sh" "$source_dir/Codex.dmg" "$@"
install_dir="''${CODEX_INSTALL_DIR:-$root_dir/codex-app}"
# Patch the Electron binary for NixOS.
if [ -f "$install_dir/electron" ]; then
echo "[NIX] Patching Electron binary for NixOS..."
patchelf --set-interpreter "$(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker)" \
--set-rpath "$install_dir:${electronLibPath}" \
"$install_dir/electron"
if [ -f "$install_dir/chrome_crashpad_handler" ]; then
patchelf --set-interpreter "$(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker)" \
"$install_dir/chrome_crashpad_handler" || true
fi
if [ -f "$install_dir/chrome-sandbox" ]; then
patchelf --set-interpreter "$(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker)" \
"$install_dir/chrome-sandbox" || true
fi
find "$install_dir" -maxdepth 1 -name "*.so*" -type f | while read -r so; do
patchelf --set-rpath "${electronLibPath}" "$so" 2>/dev/null || true
done
echo "[NIX] Electron patched successfully"
fi
'';
};
in
{
packages = {
default = installer;
installer = installer;
};
apps.default = {
type = "app";
program = "${installer}/bin/codex-desktop-installer";
};
devShells.default = pkgs.mkShell {
packages = [
pkgs.nodejs
pkgs.python3
pkgs.p7zip
pkgs.curl
pkgs.unzip
pkgs.gnumake
pkgs.gcc
];
};
}
);
}