Skip to content

Commit ad4d946

Browse files
authored
Add flake.nix for Nix / NixOS (#220)
* feat: add flake.nix * refactor: improve code style and add more information to flake.nix * chore(nix): ignore build result symlink * chore(nix): use unversioned pytest packages
1 parent 95a98b6 commit ad4d946

3 files changed

Lines changed: 265 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ js/dist/
4646
*.whl
4747
AGENTS.md
4848
.beads
49+
result
4950

5051
# Private docs (launch posts, strategy)
5152
docs/

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
{
2+
description = "CloakBrowser development shell with Nix-packaged Chromium binaries";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
};
7+
8+
outputs = { self, nixpkgs }:
9+
let
10+
inherit (nixpkgs) lib;
11+
12+
supportedSystems = [
13+
"x86_64-linux"
14+
"aarch64-linux"
15+
];
16+
17+
forAllSystems = lib.genAttrs supportedSystems;
18+
19+
packageInfo = {
20+
x86_64-linux = {
21+
platformTag = "linux-x64";
22+
version = "146.0.7680.177.3";
23+
hash = "sha256-WvAn+q+x/vmTPreEwJS3ZHBt4io3KizuhLwRf8SrU38=";
24+
};
25+
aarch64-linux = {
26+
platformTag = "linux-arm64";
27+
version = "146.0.7680.177.3";
28+
hash = "sha256-i3HOU7T9ExMnMxox+6ODXXGILRm/qr3njdD1OQvRb0U=";
29+
};
30+
};
31+
32+
cloakbrowserBinaryLicense = {
33+
shortName = "cloakbrowser-binary";
34+
fullName = "CloakBrowser Binary License";
35+
url = "https://github.com/CloakHQ/CloakBrowser/blob/main/BINARY-LICENSE.md";
36+
free = false;
37+
redistributable = false;
38+
};
39+
40+
mkPkgs = system: import nixpkgs {
41+
inherit system;
42+
config.allowUnfree = true;
43+
};
44+
45+
runtimeLibraries = pkgs: with pkgs; [
46+
alsa-lib
47+
at-spi2-atk
48+
at-spi2-core
49+
atk
50+
cairo
51+
cups
52+
dbus
53+
expat
54+
fontconfig
55+
freetype
56+
gdk-pixbuf
57+
glib
58+
gtk3
59+
libdrm
60+
libgbm
61+
libGL
62+
libpulseaudio
63+
libxkbcommon
64+
mesa
65+
nspr
66+
nss
67+
pango
68+
systemd
69+
wayland
70+
libx11
71+
libxcb
72+
libxcomposite
73+
libxcursor
74+
libxdamage
75+
libxext
76+
libxfixes
77+
libxi
78+
libxrandr
79+
libxrender
80+
libxscrnsaver
81+
libxshmfence
82+
libxtst
83+
];
84+
85+
fontPackages = pkgs: with pkgs; [
86+
freefont_ttf
87+
ipafont
88+
liberation_ttf
89+
noto-fonts
90+
noto-fonts-cjk-sans
91+
noto-fonts-color-emoji
92+
tlwg
93+
unifont
94+
wqy_zenhei
95+
];
96+
97+
desktopPackages = pkgs: with pkgs; [
98+
adwaita-icon-theme
99+
gsettings-desktop-schemas
100+
xdg-utils
101+
];
102+
103+
mkCloakBrowserChromium = pkgs: system:
104+
let
105+
info = packageInfo.${system} or (throw "CloakBrowser flake package currently supports only x86_64-linux and aarch64-linux.");
106+
archiveName = "cloakbrowser-${info.platformTag}.tar.gz";
107+
chromiumVersion = info.version;
108+
libs = runtimeLibraries pkgs;
109+
desktopDeps = desktopPackages pkgs;
110+
fonts = fontPackages pkgs;
111+
fontsConf = pkgs.makeFontsConf {
112+
fontDirectories = fonts;
113+
};
114+
in
115+
pkgs.stdenvNoCC.mkDerivation {
116+
pname = "cloakbrowser-chromium";
117+
version = chromiumVersion;
118+
119+
src = pkgs.fetchurl {
120+
url = "https://cloakbrowser.dev/chromium-v${chromiumVersion}/${archiveName}";
121+
inherit (info) hash;
122+
};
123+
124+
dontUnpack = true;
125+
126+
nativeBuildInputs = with pkgs; [
127+
autoPatchelfHook
128+
makeWrapper
129+
];
130+
131+
buildInputs = libs ++ desktopDeps;
132+
runtimeDependencies = libs;
133+
134+
installPhase = ''
135+
runHook preInstall
136+
137+
mkdir -p "$out/lib/cloakbrowser" "$out/bin"
138+
tar -xzf "$src" -C "$out/lib/cloakbrowser"
139+
chmod +x "$out/lib/cloakbrowser/chrome"
140+
chmod +x "$out/lib/cloakbrowser/chromedriver"
141+
142+
runHook postInstall
143+
'';
144+
145+
postFixup = ''
146+
makeWrapper "$out/lib/cloakbrowser/chrome" "$out/bin/cloakbrowser-chrome" \
147+
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath libs}" \
148+
--prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$XDG_ICON_DIRS" \
149+
--suffix PATH : "${lib.makeBinPath [ pkgs.xdg-utils ]}" \
150+
--set FONTCONFIG_FILE "${fontsConf}" \
151+
--set CHROME_WRAPPER "cloakbrowser-chrome"
152+
153+
makeWrapper "$out/lib/cloakbrowser/chromedriver" "$out/bin/cloakbrowser-chromedriver" \
154+
--prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath libs}"
155+
'';
156+
157+
meta = {
158+
description = "Official CloakBrowser patched Chromium binary";
159+
homepage = "https://github.com/CloakHQ/CloakBrowser";
160+
license = cloakbrowserBinaryLicense;
161+
mainProgram = "cloakbrowser-chrome";
162+
platforms = supportedSystems;
163+
sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];
164+
};
165+
};
166+
in
167+
{
168+
packages = forAllSystems (system:
169+
let
170+
pkgs = mkPkgs system;
171+
cloakbrowserChromium = mkCloakBrowserChromium pkgs system;
172+
in
173+
{
174+
inherit cloakbrowserChromium;
175+
default = cloakbrowserChromium;
176+
});
177+
178+
apps = forAllSystems (system:
179+
let
180+
cloakbrowserChromium = self.packages.${system}.cloakbrowserChromium;
181+
in
182+
{
183+
default = {
184+
type = "app";
185+
program = "${cloakbrowserChromium}/bin/cloakbrowser-chrome";
186+
meta.description = "Run CloakBrowser Chromium";
187+
};
188+
cloakbrowser-chrome = {
189+
type = "app";
190+
program = "${cloakbrowserChromium}/bin/cloakbrowser-chrome";
191+
meta.description = "Run CloakBrowser Chromium";
192+
};
193+
cloakbrowser-chromedriver = {
194+
type = "app";
195+
program = "${cloakbrowserChromium}/bin/cloakbrowser-chromedriver";
196+
meta.description = "Run the CloakBrowser Chromedriver binary";
197+
};
198+
});
199+
200+
devShells = forAllSystems (system:
201+
let
202+
pkgs = mkPkgs system;
203+
cloakbrowserChromium = self.packages.${system}.cloakbrowserChromium;
204+
python = pkgs.python312.withPackages (ps: with ps; [
205+
aiohttp
206+
geoip2
207+
hatchling
208+
httpx
209+
playwright
210+
pytest
211+
pytest-asyncio
212+
socksio
213+
websockets
214+
]);
215+
in
216+
{
217+
default = pkgs.mkShell {
218+
packages = [
219+
cloakbrowserChromium
220+
python
221+
pkgs.cacert
222+
pkgs.curl
223+
pkgs.git
224+
pkgs.jq
225+
pkgs.nodejs_20
226+
pkgs.which
227+
pkgs.xdotool
228+
pkgs.xvfb-run
229+
]
230+
++ runtimeLibraries pkgs
231+
++ fontPackages pkgs;
232+
233+
CLOAKBROWSER_BINARY_PATH = "${cloakbrowserChromium}/bin/cloakbrowser-chrome";
234+
};
235+
});
236+
};
237+
}

0 commit comments

Comments
 (0)