-
Notifications
You must be signed in to change notification settings - Fork 5
/
flake.nix
188 lines (158 loc) · 6.19 KB
/
flake.nix
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
};
outputs = { nixpkgs, ... }:
let
inherit (nixpkgs) lib;
makePackages = (system: dev:
let
pkgs = import nixpkgs {
inherit system;
};
rustManifest = lib.importTOML ./Cargo.toml;
makeCefBinaryAttrs =
let
platforms = {
"x86_64-linux" = { platformUrl = "linux64"; projectArchCmake = "x86_64"; };
# TODO test if arm builds/works before adding these
# "aarch64-linux" = { platformUrl = "linuxarm64"; projectArchCmake = "arm64"; };
# "armv7l-linux" = { platformUrl = "linuxarm"; projectArchCmake = "arm"; };
# TODO need to remove unsupported rpath's on libcef
# "x86_64-darwin" = { platformUrl = "macosx64"; projectArchCmake = "x86_64"; };
# "aarch64-darwin" = { platformUrl = "macosarm64"; projectArchCmake = "arm64"; };
};
platforms."x86_64-linux".hash = "sha256-0IjhTFlcDBmmHxxKfPUNklFHuTawrj4j211Z29/gPMY=";
# platforms."aarch64-linux".hash = "";
# platforms."armv7l-linux".hash = "";
# platforms."x86_64-darwin".hash = "";
# platforms."aarch64-darwin".hash = "";
inherit (platforms.${pkgs.stdenv.hostPlatform.system}) platformUrl projectArchCmake hash;
in
(prev: rec {
version = "131.2.5+gb351dee+chromium-131.0.6778.86";
src = pkgs.fetchzip {
inherit hash;
name = "cef_binary-${version}";
url = "https://cef-builds.spotifycdn.com/cef_binary_${version}_${platformUrl}.tar.bz2";
};
installPhase = prev.installPhase + ''
# cef wants icu file next to the .so
mv -v $out/share/cef/* $out/lib/
rmdir $out/share/cef $out/share
# old: needed to fix "FATAL:udev_loader.cc(48)] Check failed: false."
# needs libudev.so.1 now instead of previous ^ so.0 to link at compile time
patchelf --add-rpath "${lib.makeLibraryPath [ pkgs.udev ]}" $out/lib/*.so
'';
cmakeFlags =
if builtins.length prev.cmakeFlags == 1
then [ "-DPROJECT_ARCH=${projectArchCmake}" ]
else throw "cmakeFlags changed?";
meta = prev.meta // {
platforms = builtins.attrNames platforms;
};
});
makeDefaultAttrs = (cef_binary: rec {
pname = rustManifest.package.name;
version = rustManifest.package.version;
src = lib.sourceByRegex ./. [
"^\.cargo(/.*)?$"
"^build\.rs$"
"^Cargo\.(lock|toml)$"
"^cef_interface(/.*)?$"
"^src(/.*)?$"
];
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"async-dispatcher-0.1.0" = "sha256-rqpQ176/PnI9vvPrwQvK3GJbryjb3hHkb+o1RyCZ3Vg=";
"clap-4.2.7" = "sha256-PccqMT2KltTC2gVL9/xfCNFOAu3+6ash9HqM/TkpgmU=";
"classicube-helpers-3.0.0+classicube.1.3.7" = "sha256-3hWKS6NmAH0x+SOi/nBKJLIQi/3ilG7WSRrPvF++wGE=";
};
};
nativeBuildInputs = with pkgs; [
cmake
pkg-config
rustPlatform.bindgenHook
] ++ (if dev then
with pkgs; ([
cargo-release
clippy
(rustfmt.override { asNightly = true; })
rust-analyzer
]) else [ ]);
LIBCEF_LIB_DIR = "${cef_binary}/lib";
LIBCEF_INCLUDE_DIR = "${cef_binary}/include";
LIBCEF_DLL_WRAPPER_LIB_DIR = LIBCEF_LIB_DIR;
ZSTD_SYS_USE_PKG_CONFIG = "1";
OPENSSL_LIB_DIR = "${lib.getLib pkgs.openssl}/lib";
OPENSSL_INCLUDE_DIR = "${lib.getDev pkgs.openssl}/include";
buildInputs = with pkgs; [
cef_binary
openssl
zstd
];
dontUseCargoParallelTests = true;
postFixup = ''
mv -v $out/lib $out/plugins
mv -v $out/bin $out/cef
mkdir -vp $out/cef/cef_binary
ln -vs ${cef_binary}/lib/* $out/cef/cef_binary/
'';
# so that when developing we don't get spammed with
# "warning _FORTIFY_SOURCE requires compiling with optimization (-O)"
hardeningDisable =
if dev
then [ "all" ]
else [ ];
});
in
rec {
default = pkgs.rustPlatform.buildRustPackage (makeDefaultAttrs cef_binary);
debug = (pkgs.enableDebugging {
inherit (pkgs) stdenv;
override = (attrs: pkgs.makeRustPlatform ({
inherit (pkgs) rustc cargo;
} // attrs));
}).buildRustPackage (
let
attrs = makeDefaultAttrs cef_binary_debug;
in
(attrs // {
pname = "${attrs.pname}-debug";
buildType = "debug";
hardeningDisable = [ "all" ];
})
);
cef_binary = pkgs.libcef.overrideAttrs makeCefBinaryAttrs;
cef_binary_debug = (pkgs.enableDebugging pkgs.libcef).overrideAttrs (prev:
let
attrs = makeCefBinaryAttrs prev;
in
attrs // {
pname = "${prev.pname}-debug";
cmakeBuildType = "Debug";
installPhase = builtins.replaceStrings [ "/Release/" ] [ "/Debug/" ] attrs.installPhase;
hardeningDisable = [ "all" ];
});
}
);
in
builtins.foldl' lib.recursiveUpdate { } (builtins.map
(system: {
devShells.${system} = makePackages system true;
packages.${system} = makePackages system false;
})
[
"x86_64-linux"
# TODO
"aarch64-linux"
# TODO
# cef "Linux ARM" is armv7
"armv7l-linux"
# TODO
"x86_64-darwin"
# TODO
"aarch64-darwin"
]);
}