mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-28 15:54:32 +00:00
0495725a1f
Some Flutter packages require additional attribute values to be added to buildFlutterApplication, to add things like libraries and environment variables. To prevent duplication in applications that use the packages, a repository of package overrides is kept. buildFlutterApplication will look for package overrides for each dependency, and apply them by calling overrideAttrs on itself.
122 lines
3.4 KiB
Nix
122 lines
3.4 KiB
Nix
{ lib
|
|
, callPackage
|
|
, stdenvNoCC
|
|
, makeWrapper
|
|
, llvmPackages_13
|
|
, cacert
|
|
, flutter
|
|
}:
|
|
|
|
# absolutely no mac support for now
|
|
|
|
{ pubGetScript ? "flutter pub get"
|
|
, flutterBuildFlags ? [ ]
|
|
, runtimeDependencies ? [ ]
|
|
, customPackageOverrides ? { }
|
|
, vendorHash
|
|
, pubspecLockFile ? null
|
|
, nativeBuildInputs ? [ ]
|
|
, postFixup ? ""
|
|
, ...
|
|
}@args:
|
|
let
|
|
flutterSetupScript = ''
|
|
export HOME="$NIX_BUILD_TOP"
|
|
flutter config --no-analytics &>/dev/null # mute first-run
|
|
flutter config --enable-linux-desktop >/dev/null
|
|
'';
|
|
|
|
deps = callPackage ../dart/fetch-dart-deps { dart = flutter; } {
|
|
sdkSetupScript = flutterSetupScript;
|
|
inherit pubGetScript vendorHash pubspecLockFile;
|
|
buildDrvArgs = args;
|
|
};
|
|
|
|
baseDerivation = llvmPackages_13.stdenv.mkDerivation (finalAttrs: args // {
|
|
inherit flutterBuildFlags runtimeDependencies;
|
|
|
|
outputs = [ "out" "debug" ];
|
|
|
|
nativeBuildInputs = [
|
|
makeWrapper
|
|
deps
|
|
flutter
|
|
] ++ nativeBuildInputs;
|
|
|
|
configurePhase = ''
|
|
runHook preConfigure
|
|
|
|
${flutterSetupScript}
|
|
|
|
runHook postConfigure
|
|
'';
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
|
|
mkdir -p build/flutter_assets/fonts
|
|
|
|
flutter packages get --offline -v
|
|
flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") finalAttrs.flutterBuildFlags)}
|
|
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
built=build/linux/*/release/bundle
|
|
|
|
mkdir -p $out/bin
|
|
mv $built $out/app
|
|
|
|
for f in $(find $out/app -iname "*.desktop" -type f); do
|
|
install -D $f $out/share/applications/$(basename $f)
|
|
done
|
|
|
|
for f in $(find $out/app -maxdepth 1 -type f); do
|
|
ln -s $f $out/bin/$(basename $f)
|
|
done
|
|
|
|
# make *.so executable
|
|
find $out/app -iname "*.so" -type f -exec chmod +x {} +
|
|
|
|
# remove stuff like /build/source/packages/ubuntu_desktop_installer/linux/flutter/ephemeral
|
|
for f in $(find $out/app -executable -type f); do
|
|
if patchelf --print-rpath "$f" | grep /build; then # this ignores static libs (e,g. libapp.so) also
|
|
echo "strip RPath of $f"
|
|
newrp=$(patchelf --print-rpath $f | sed -r "s|/build.*ephemeral:||g" | sed -r "s|/build.*profile:||g")
|
|
patchelf --set-rpath "$newrp" "$f"
|
|
fi
|
|
done
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
postFixup = ''
|
|
# Add runtime library dependencies to the LD_LIBRARY_PATH.
|
|
# For some reason, the RUNPATH of the executable is not used to load dynamic libraries in dart:ffi with DynamicLibrary.open().
|
|
#
|
|
# This could alternatively be fixed with patchelf --add-needed, but this would cause all the libraries to be opened immediately,
|
|
# which is not what application authors expect.
|
|
for f in "$out"/bin/*; do
|
|
wrapProgram "$f" \
|
|
--suffix LD_LIBRARY_PATH : '${lib.makeLibraryPath finalAttrs.runtimeDependencies}'
|
|
done
|
|
|
|
${postFixup}
|
|
'';
|
|
});
|
|
|
|
packageOverrideRepository = (callPackage ../../development/compilers/flutter/package-overrides { }) // customPackageOverrides;
|
|
packages = callPackage ../dart/list-dart-deps { dart = flutter; } deps;
|
|
productPackages = builtins.filter (package: package.kind != "dev") packages;
|
|
in
|
|
builtins.foldl'
|
|
(prev: package:
|
|
if packageOverrideRepository ? ${package.name}
|
|
then prev.overrideAttrs packageOverrideRepository.${package.name}
|
|
else prev)
|
|
baseDerivation
|
|
productPackages
|