Desktop: Reduce Nix package closure size (#3737)

This commit is contained in:
Timon 2026-02-08 21:31:38 +00:00 committed by GitHub
parent acab171bc5
commit 2f5ccad5ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 37 deletions

View File

@ -1,27 +1,24 @@
{ pkgs, inputs, ... }:
let
cef = pkgs.cef-binary.overrideAttrs {
cefPath = pkgs.cef-binary.overrideAttrs (finalAttrs: {
postInstall = ''
strip $out/Release/*.so*
rm -r $out/* $out/.* || true
strip ./Release/*.so*
mv ./Release/* $out/
find "./Resources/locales" -maxdepth 1 -type f ! -name 'en-US.pak' -delete
mv ./Resources/* $out/
mv ./include $out/
echo '${
builtins.toJSON {
type = "minimal";
name = builtins.baseNameOf finalAttrs.src.url;
sha1 = "";
}
}' > $out/archive.json
'';
};
cefPath = pkgs.runCommand "cef-path" { } ''
mkdir -p $out
ln -s ${cef}/include $out/include
find ${cef}/Release -name "*" -type f -exec ln -s {} $out/ \;
find ${cef}/Resources -name "*" -maxdepth 1 -exec ln -s {} $out/ \;
echo '${
builtins.toJSON {
type = "minimal";
name = builtins.baseNameOf cef.src.url;
sha1 = "";
}
}' > $out/archive.json
'';
});
in
{
env.CEF_PATH = cefPath;

View File

@ -2,11 +2,11 @@
"nodes": {
"crane": {
"locked": {
"lastModified": 1763938834,
"narHash": "sha256-j8iB0Yr4zAvQLueCZ5abxfk6fnG/SJ5JnGUziETjwfg=",
"lastModified": 1770169865,
"narHash": "sha256-iPiy13xzDQ9GjpOez+NNIjh/qjl7i4RDf9dF2x5mF9I=",
"owner": "ipetkov",
"repo": "crane",
"rev": "d9e753122e51cee64eb8d2dddfe11148f339f5a2",
"rev": "8254ccf3b5b5131890ee073776f2e61c6d1e55d4",
"type": "github"
},
"original": {
@ -49,11 +49,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1764242076,
"narHash": "sha256-sKoIWfnijJ0+9e4wRvIgm/HgE27bzwQxcEmo2J/gNpI=",
"lastModified": 1770197578,
"narHash": "sha256-AYqlWrX09+HvGs8zM6ebZ1pwUqjkfpnv8mewYwAo+iM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "2fad6eac6077f03fe109c4d4eb171cf96791faa4",
"rev": "00c21e4c93d963c50d4c0c89bfa84ed6e0694df2",
"type": "github"
},
"original": {
@ -79,11 +79,11 @@
]
},
"locked": {
"lastModified": 1764297505,
"narHash": "sha256-qrLpVu2/hA9Cu6IovMEsgh9YRyvmmWS+bSx7C1JGChA=",
"lastModified": 1770347142,
"narHash": "sha256-uz+ZSqXpXEPtdRPYwvgsum/CfNq7AUQ/0gZHqTigiPM=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "9623580f8ce09ec444b9aca107566ec5db110e62",
"rev": "2859683cd9ef7858d324c5399b0d8d6652bf4044",
"type": "github"
},
"original": {

View File

@ -20,9 +20,14 @@ let
build = ''
mkdir -p out
mkdir -p out/bin
cp ${graphite}/bin/.graphite-wrapped out/bin/graphite
cp ${graphite}/bin/graphite out/bin/graphite
chmod -v +w out/bin/graphite
patchelf --set-rpath '$ORIGIN/../lib:$ORIGIN/../lib/cef' --set-interpreter '/lib64/ld-linux-x86-64.so.2' out/bin/graphite
patchelf \
--set-rpath '$ORIGIN/../lib:$ORIGIN/../lib/cef' \
--set-interpreter '/lib64/ld-linux-x86-64.so.2' \
--remove-needed libGL.so \
out/bin/graphite
cp -r ${graphite}/share out/share
mkdir -p out/lib/cef
mkdir -p ./cef
tar -xvf ${pkgs.cef-binary.src} -C ./cef --strip-components=1
@ -30,7 +35,6 @@ let
cp -r ./cef/Resources/* out/lib/cef/
find "out/lib/cef/locales" -type f ! -name 'en-US*' -delete
${pkgs.bintools}/bin/strip out/lib/cef/*.so*
cp -r ${graphite}/share out/share
'';
install =
if tar then

View File

@ -30,14 +30,16 @@ let
mkdir -p $out
tar -xvf ${brandingTar} -C $out --strip-components 1
'';
cargoVendorDir = deps.crane.lib.vendorCargoDeps { inherit (info) src; };
resourcesCommon = {
pname = "${info.pname}-resources";
inherit (info) version src;
inherit cargoVendorDir;
strictDeps = true;
doCheck = false;
nativeBuildInputs = tools.frontend;
env.CARGO_PROFILE = if dev then "dev" else "release";
cargoExtraArgs = "--target wasm32-unknown-unknown -p graphite-wasm --no-default-features --features native";
doCheck = false;
};
resources = deps.crane.lib.buildPackage (
resourcesCommon
@ -52,7 +54,7 @@ let
npmConfigScript = "setup";
makeCacheWritable = true;
nativeBuildInputs = tools.frontend ++ [ pkgs.importNpmLock.npmConfigHook ];
nativeBuildInputs = tools.frontend ++ [ pkgs.importNpmLock.npmConfigHook pkgs.removeReferencesTo ];
prePatch = ''
mkdir branding
@ -72,13 +74,18 @@ let
mkdir -p $out
cp -r frontend/dist/* $out/
'';
postFixup = ''
find "$out" -type f -exec remove-references-to -t "${cargoVendorDir}" '{}' +
'';
}
);
common = {
inherit (info) pname version src;
inherit cargoVendorDir;
strictDeps = true;
buildInputs = libs.desktop-all;
nativeBuildInputs = tools.desktop ++ [ pkgs.makeWrapper ];
nativeBuildInputs = tools.desktop ++ [ pkgs.makeWrapper pkgs.removeReferencesTo ];
env = deps.cef.env // {
CARGO_PROFILE = if dev then "dev" else "release";
};
@ -138,9 +145,12 @@ deps.crane.lib.buildPackage (
'';
postFixup = ''
wrapProgram "$out/bin/graphite" \
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath libs.desktop-all}:${deps.cef.env.CEF_PATH}" \
--set CEF_PATH "${deps.cef.env.CEF_PATH}"
remove-references-to -t "${cargoVendorDir}" $out/bin/graphite
patchelf \
--set-rpath "${pkgs.lib.makeLibraryPath libs.desktop-all}:${deps.cef.env.CEF_PATH}" \
--add-needed libGL.so \
$out/bin/graphite
'';
}
)