From 0c864d613aefbe293de83a2b9985215b56069ee9 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Thu, 12 Nov 2026 00:01:29 -0500 Subject: [PATCH] build avif_native from source for nix --- linux/nix/pkg/avif_native.nix | 44 ++++++++++++----------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/linux/nix/pkg/avif_native.nix b/linux/nix/pkg/avif_native.nix index 59a5b96..64dcb81 100644 --- a/linux/nix/pkg/avif_native.nix +++ b/linux/nix/pkg/avif_native.nix @@ -1,24 +1,11 @@ # avif_native's build hook downloads its prebuilt library, which the sandbox -# can't do, so bundle it and point the manifest at the local copy instead +# can't do, so build it from source against nixpkgs' libavif, and point the +# manifest at it { stdenv, - fetchurl, + libavif, jq, }: -let - artifacts = { - x86_64-linux = { - arch = "x64"; - sha256 = "fa36210bc95b70abd14c20fd626204f57d0ef947297e9ff8ee66855c01e2c17f"; - }; - aarch64-linux = { - arch = "arm64"; - sha256 = "163487e98b5eee0676be0dc8d3f60b5e0e5b67191a8a0a2abb5c8fad14a3a506"; - }; - }; - inherit (artifacts.${stdenv.hostPlatform.system}) arch sha256; - key = "linux-${arch}-decode-dav1d"; -in { version, src, ... }: stdenv.mkDerivation { pname = "avif_native"; @@ -26,24 +13,23 @@ stdenv.mkDerivation { inherit (src) passthru; nativeBuildInputs = [ jq ]; + buildInputs = [ libavif ]; - library = fetchurl { - url = "https://github.com/Zhangw1998/avif_native/releases/download/native-v0.2.0/${key}-libavif_native.so.gz"; - inherit sha256; - }; + buildPhase = '' + $CC -shared -fPIC src/avif_shim.c -lavif -o native/libavif_native.so + ''; - # The hook checksums the library, so it must stay byte-identical + # The hook checksums the library, so it mustn't change after it's hashed dontFixup = true; + # Nexus only decodes, with dav1d, see hooks.user_defines in pubspec.yaml installPhase = '' - runHook preInstall - cp -r . $out - chmod -R u+w $out - gunzip -c $library > $out/native/libavif_native.so - jq '.artifacts["${key}"].path = "libavif_native.so"' \ - native/manifest.json > $out/native/manifest.json - - runHook postInstall + jq --arg hash "$(sha256sum native/libavif_native.so | cut -d " " -f 1)" \ + '.artifacts |= with_entries( + if .key | test("^linux-.*-decode-dav1d$") + then .value += { path: "libavif_native.so", librarySha256: $hash } + else . end + )' native/manifest.json > $out/native/manifest.json ''; }