2023-04-29 16:46:19 +00:00
|
|
|
{ lib
|
|
|
|
, callPackage
|
2022-02-20 05:27:41 +00:00
|
|
|
, stdenvNoCC
|
2023-04-29 16:46:19 +00:00
|
|
|
, makeWrapper
|
|
|
|
, llvmPackages_13
|
2022-02-20 05:27:41 +00:00
|
|
|
, cacert
|
2023-04-29 16:46:19 +00:00
|
|
|
, flutter
|
|
|
|
, jq
|
2022-02-20 05:27:41 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
# absolutely no mac support for now
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
{ pubGetScript ? "flutter pub get"
|
|
|
|
, flutterBuildFlags ? [ ]
|
|
|
|
, runtimeDependencies ? [ ]
|
|
|
|
, customPackageOverrides ? { }
|
|
|
|
, autoDepsList ? false
|
|
|
|
, depsListFile ? null
|
2023-05-24 13:37:59 +00:00
|
|
|
, vendorHash ? ""
|
2023-04-29 16:46:19 +00:00
|
|
|
, pubspecLockFile ? null
|
|
|
|
, nativeBuildInputs ? [ ]
|
|
|
|
, preUnpack ? ""
|
|
|
|
, postFixup ? ""
|
2023-05-24 13:37:59 +00:00
|
|
|
, extraWrapProgramArgs ? ""
|
2023-04-29 16:46:19 +00:00
|
|
|
, ...
|
|
|
|
}@args:
|
2022-02-20 05:27:41 +00:00
|
|
|
let
|
2023-04-29 16:46:19 +00:00
|
|
|
flutterSetupScript = ''
|
|
|
|
export HOME="$NIX_BUILD_TOP"
|
|
|
|
flutter config --no-analytics &>/dev/null # mute first-run
|
|
|
|
flutter config --enable-linux-desktop >/dev/null
|
|
|
|
'';
|
2022-03-05 16:20:37 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
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
|
|
|
|
jq
|
|
|
|
] ++ nativeBuildInputs;
|
|
|
|
|
|
|
|
preUnpack = ''
|
|
|
|
${lib.optionalString (!autoDepsList) ''
|
|
|
|
if ! { [ '${lib.boolToString (depsListFile != null)}' = 'true' ] ${lib.optionalString (depsListFile != null) "&& cmp -s <(jq -Sc . '${depsListFile}') <(jq -Sc . '${finalAttrs.passthru.depsListFile}')"}; }; then
|
|
|
|
echo 1>&2 -e '\nThe dependency list file was either not given or differs from the expected result.' \
|
|
|
|
'\nPlease choose one of the following solutions:' \
|
|
|
|
'\n - Duplicate the following file and pass it to the depsListFile argument.' \
|
|
|
|
'\n ${finalAttrs.passthru.depsListFile}' \
|
|
|
|
'\n - Set autoDepsList to true (not supported by Hydra or permitted in Nixpkgs)'.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
''}
|
|
|
|
|
|
|
|
${preUnpack}
|
|
|
|
'';
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
${flutterSetupScript}
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
mkdir -p build/flutter_assets/fonts
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
doPubGet flutter pub get --offline -v
|
2023-04-29 16:46:19 +00:00
|
|
|
flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") finalAttrs.flutterBuildFlags)}
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
built=build/linux/*/release/bundle
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
mkdir -p $out/bin
|
|
|
|
mv $built $out/app
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
for f in $(find $out/app -iname "*.desktop" -type f); do
|
|
|
|
install -D $f $out/share/applications/$(basename $f)
|
|
|
|
done
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
for f in $(find $out/app -maxdepth 1 -type f); do
|
|
|
|
ln -s $f $out/bin/$(basename $f)
|
2022-02-20 05:27:41 +00:00
|
|
|
done
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
# make *.so executable
|
|
|
|
find $out/app -iname "*.so" -type f -exec chmod +x {} +
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
# 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
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
runHook postInstall
|
2022-02-20 05:27:41 +00:00
|
|
|
'';
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
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" \
|
2023-05-24 13:37:59 +00:00
|
|
|
--suffix LD_LIBRARY_PATH : '${lib.makeLibraryPath finalAttrs.runtimeDependencies}' \
|
|
|
|
${extraWrapProgramArgs}
|
2023-04-29 16:46:19 +00:00
|
|
|
done
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
${postFixup}
|
|
|
|
'';
|
2022-02-20 05:27:41 +00:00
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
passthru = {
|
|
|
|
inherit (deps) depsListFile;
|
|
|
|
};
|
2022-02-20 05:27:41 +00:00
|
|
|
});
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
packageOverrideRepository = (callPackage ../../development/compilers/flutter/package-overrides { }) // customPackageOverrides;
|
|
|
|
productPackages = builtins.filter (package: package.kind != "dev")
|
|
|
|
(if autoDepsList
|
2023-05-24 13:37:59 +00:00
|
|
|
then lib.importJSON deps.depsListFile
|
2022-02-20 05:27:41 +00:00
|
|
|
else
|
2023-04-29 16:46:19 +00:00
|
|
|
if depsListFile == null
|
|
|
|
then [ ]
|
2023-05-24 13:37:59 +00:00
|
|
|
else lib.importJSON depsListFile);
|
2022-02-20 05:27:41 +00:00
|
|
|
in
|
2023-04-29 16:46:19 +00:00
|
|
|
builtins.foldl'
|
|
|
|
(prev: package:
|
|
|
|
if packageOverrideRepository ? ${package.name}
|
|
|
|
then
|
|
|
|
prev.overrideAttrs
|
|
|
|
(packageOverrideRepository.${package.name} {
|
|
|
|
inherit (package)
|
|
|
|
name
|
|
|
|
version
|
|
|
|
kind
|
|
|
|
source
|
|
|
|
dependencies;
|
|
|
|
})
|
|
|
|
else prev)
|
|
|
|
baseDerivation
|
|
|
|
productPackages
|