From f9530b0a5cdeba9fd08f838e2c2269e65e023c2a Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 15 Oct 2026 17:37:49 +0900 Subject: [PATCH] Share the Cabal v2 mobile packaging adapter with Nix probes --- flake.nix | 34 ++-------------------------------- scripts/nix/mobile-library.nix | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 scripts/nix/mobile-library.nix diff --git a/flake.nix b/flake.nix index 0a7f8deb63..b731b12f25 100644 --- a/flake.nix +++ b/flake.nix @@ -90,38 +90,8 @@ }; in # by defualt we don't need to pass extra-modules. let drv = pkgs': drv' { extra-modules = []; inherit pkgs'; }; in - # V2 slices ignore component.override and do not run postBuild/postInstall. - # Relink while their full package database still exists, then package after - # the normal install phase. The compiler is the exact slice/TH wrapper. - let withComponentPhases = component: change: component.overrideAttrs (old: - change old // { - passthru = (old.passthru or {}) // { - inherit (component) checkAgainstPlan; - isSlice = true; - }; - }); in - let mobileLibrary = { kind, packageName ? "simplex-chat", linkOptions ? [], postInstall }: old: - let compiler = builtins.head old.nativeBuildInputs; - prefix = compiler.targetPrefix or ""; - in { - buildPhase = old.buildPhase + '' - discoverStore - test -n "$ghcDir" - ${pkgs.bash}/bin/bash ${./scripts/nix/link-mobile-library.sh} \ - ${compiler}/bin/${prefix}ghc ${compiler}/bin/${prefix}ghc-pkg \ - "$ghcDir/$storePkgDb" ${pkgs.lib.escapeShellArg packageName} \ - ${pkgs.lib.escapeShellArg kind} "$buildRoot/mobile-bundle" \ - ${pkgs.lib.escapeShellArgs linkOptions} - ''; - installPhase = old.installPhase + '' - ( - cd "$buildRoot/mobile-bundle" - ${postInstall} - ) - ''; - }; in - let withMobileLibrary = component: options: - withComponentPhases component (mobileLibrary options); in + let inherit (import ./scripts/nix/mobile-library.nix { inherit pkgs; }) + withComponentPhases withMobileLibrary; in let chatExports = [ "chat_close_store" "chat_decrypt_file" diff --git a/scripts/nix/mobile-library.nix b/scripts/nix/mobile-library.nix new file mode 100644 index 0000000000..6760e3c937 --- /dev/null +++ b/scripts/nix/mobile-library.nix @@ -0,0 +1,34 @@ +{ pkgs }: +# V2 slices ignore component.override and do not run postBuild/postInstall. +# Relink while their full package database still exists, then package after +# the normal install phase. The compiler is the exact slice/TH wrapper. +let withComponentPhases = component: change: component.overrideAttrs (old: + change old // { + passthru = (old.passthru or {}) // { + inherit (component) checkAgainstPlan; + isSlice = true; + }; + }); in +let mobileLibrary = { kind, packageName ? "simplex-chat", linkOptions ? [], postInstall }: old: + let compiler = builtins.head old.nativeBuildInputs; + prefix = compiler.targetPrefix or ""; + in { + buildPhase = old.buildPhase + '' + discoverStore + test -n "$ghcDir" + ${pkgs.bash}/bin/bash ${./link-mobile-library.sh} \ + ${compiler}/bin/${prefix}ghc ${compiler}/bin/${prefix}ghc-pkg \ + "$ghcDir/$storePkgDb" ${pkgs.lib.escapeShellArg packageName} \ + ${pkgs.lib.escapeShellArg kind} "$buildRoot/mobile-bundle" \ + ${pkgs.lib.escapeShellArgs linkOptions} + ''; + installPhase = old.installPhase + '' + ( + cd "$buildRoot/mobile-bundle" + ${postInstall} + ) + ''; + }; in +let withMobileLibrary = component: options: + withComponentPhases component (mobileLibrary options); in +{ inherit withComponentPhases withMobileLibrary; }