Skip to content

Commit 2f5ccad

Browse files
Desktop: Reduce Nix package closure size (#3737)
1 parent acab171 commit 2f5ccad

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

.nix/deps/cef.nix

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
{ pkgs, inputs, ... }:
22

33
let
4-
cef = pkgs.cef-binary.overrideAttrs {
4+
cefPath = pkgs.cef-binary.overrideAttrs (finalAttrs: {
55
postInstall = ''
6-
strip $out/Release/*.so*
7-
'';
8-
};
9-
10-
cefPath = pkgs.runCommand "cef-path" { } ''
11-
mkdir -p $out
6+
rm -r $out/* $out/.* || true
7+
strip ./Release/*.so*
8+
mv ./Release/* $out/
9+
find "./Resources/locales" -maxdepth 1 -type f ! -name 'en-US.pak' -delete
10+
mv ./Resources/* $out/
11+
mv ./include $out/
1212
13-
ln -s ${cef}/include $out/include
14-
find ${cef}/Release -name "*" -type f -exec ln -s {} $out/ \;
15-
find ${cef}/Resources -name "*" -maxdepth 1 -exec ln -s {} $out/ \;
16-
17-
echo '${
18-
builtins.toJSON {
19-
type = "minimal";
20-
name = builtins.baseNameOf cef.src.url;
21-
sha1 = "";
22-
}
23-
}' > $out/archive.json
24-
'';
13+
echo '${
14+
builtins.toJSON {
15+
type = "minimal";
16+
name = builtins.baseNameOf finalAttrs.src.url;
17+
sha1 = "";
18+
}
19+
}' > $out/archive.json
20+
'';
21+
});
2522
in
2623
{
2724
env.CEF_PATH = cefPath;

.nix/flake.lock

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

.nix/pkgs/graphite-bundle.nix

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ let
2020
build = ''
2121
mkdir -p out
2222
mkdir -p out/bin
23-
cp ${graphite}/bin/.graphite-wrapped out/bin/graphite
23+
cp ${graphite}/bin/graphite out/bin/graphite
2424
chmod -v +w out/bin/graphite
25-
patchelf --set-rpath '$ORIGIN/../lib:$ORIGIN/../lib/cef' --set-interpreter '/lib64/ld-linux-x86-64.so.2' out/bin/graphite
25+
patchelf \
26+
--set-rpath '$ORIGIN/../lib:$ORIGIN/../lib/cef' \
27+
--set-interpreter '/lib64/ld-linux-x86-64.so.2' \
28+
--remove-needed libGL.so \
29+
out/bin/graphite
30+
cp -r ${graphite}/share out/share
2631
mkdir -p out/lib/cef
2732
mkdir -p ./cef
2833
tar -xvf ${pkgs.cef-binary.src} -C ./cef --strip-components=1
2934
cp -r ./cef/Release/* out/lib/cef/
3035
cp -r ./cef/Resources/* out/lib/cef/
3136
find "out/lib/cef/locales" -type f ! -name 'en-US*' -delete
3237
${pkgs.bintools}/bin/strip out/lib/cef/*.so*
33-
cp -r ${graphite}/share out/share
3438
'';
3539
install =
3640
if tar then

.nix/pkgs/graphite.nix

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ let
3030
mkdir -p $out
3131
tar -xvf ${brandingTar} -C $out --strip-components 1
3232
'';
33+
cargoVendorDir = deps.crane.lib.vendorCargoDeps { inherit (info) src; };
3334
resourcesCommon = {
3435
pname = "${info.pname}-resources";
3536
inherit (info) version src;
37+
inherit cargoVendorDir;
3638
strictDeps = true;
37-
doCheck = false;
3839
nativeBuildInputs = tools.frontend;
3940
env.CARGO_PROFILE = if dev then "dev" else "release";
4041
cargoExtraArgs = "--target wasm32-unknown-unknown -p graphite-wasm --no-default-features --features native";
42+
doCheck = false;
4143
};
4244
resources = deps.crane.lib.buildPackage (
4345
resourcesCommon
@@ -52,7 +54,7 @@ let
5254
npmConfigScript = "setup";
5355
makeCacheWritable = true;
5456

55-
nativeBuildInputs = tools.frontend ++ [ pkgs.importNpmLock.npmConfigHook ];
57+
nativeBuildInputs = tools.frontend ++ [ pkgs.importNpmLock.npmConfigHook pkgs.removeReferencesTo ];
5658

5759
prePatch = ''
5860
mkdir branding
@@ -72,13 +74,18 @@ let
7274
mkdir -p $out
7375
cp -r frontend/dist/* $out/
7476
'';
77+
78+
postFixup = ''
79+
find "$out" -type f -exec remove-references-to -t "${cargoVendorDir}" '{}' +
80+
'';
7581
}
7682
);
7783
common = {
7884
inherit (info) pname version src;
85+
inherit cargoVendorDir;
7986
strictDeps = true;
8087
buildInputs = libs.desktop-all;
81-
nativeBuildInputs = tools.desktop ++ [ pkgs.makeWrapper ];
88+
nativeBuildInputs = tools.desktop ++ [ pkgs.makeWrapper pkgs.removeReferencesTo ];
8289
env = deps.cef.env // {
8390
CARGO_PROFILE = if dev then "dev" else "release";
8491
};
@@ -138,9 +145,12 @@ deps.crane.lib.buildPackage (
138145
'';
139146

140147
postFixup = ''
141-
wrapProgram "$out/bin/graphite" \
142-
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath libs.desktop-all}:${deps.cef.env.CEF_PATH}" \
143-
--set CEF_PATH "${deps.cef.env.CEF_PATH}"
148+
remove-references-to -t "${cargoVendorDir}" $out/bin/graphite
149+
150+
patchelf \
151+
--set-rpath "${pkgs.lib.makeLibraryPath libs.desktop-all}:${deps.cef.env.CEF_PATH}" \
152+
--add-needed libGL.so \
153+
$out/bin/graphite
144154
'';
145155
}
146156
)

0 commit comments

Comments
 (0)