2023-04-13 14:00:24 +02:00
|
|
|
{ lib
|
2023-04-15 16:17:41 +02:00
|
|
|
, callPackage
|
2021-11-23 12:02:55 +01:00
|
|
|
, stdenvNoCC
|
2023-08-27 15:11:24 +02:00
|
|
|
, runCommand
|
2023-04-16 11:25:42 +02:00
|
|
|
, makeWrapper
|
2023-04-13 14:00:24 +02:00
|
|
|
, llvmPackages_13
|
|
|
|
, cacert
|
|
|
|
, flutter
|
2023-04-22 08:42:22 +02:00
|
|
|
, jq
|
2021-11-23 12:02:55 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
# absolutely no mac support for now
|
|
|
|
|
2023-04-15 16:17:41 +02:00
|
|
|
{ pubGetScript ? "flutter pub get"
|
2023-04-16 11:25:42 +02:00
|
|
|
, flutterBuildFlags ? [ ]
|
|
|
|
, runtimeDependencies ? [ ]
|
2023-04-16 19:01:32 +02:00
|
|
|
, customPackageOverrides ? { }
|
2023-04-22 16:32:24 +02:00
|
|
|
, autoDepsList ? false
|
2023-04-22 08:42:22 +02:00
|
|
|
, depsListFile ? null
|
2023-05-05 01:26:13 +02:00
|
|
|
, vendorHash ? ""
|
2023-04-15 17:49:43 +02:00
|
|
|
, pubspecLockFile ? null
|
2023-04-15 16:17:41 +02:00
|
|
|
, nativeBuildInputs ? [ ]
|
2023-04-22 08:42:22 +02:00
|
|
|
, preUnpack ? ""
|
2023-04-16 11:25:42 +02:00
|
|
|
, postFixup ? ""
|
2023-05-14 17:10:49 +02:00
|
|
|
, extraWrapProgramArgs ? ""
|
2023-04-15 16:17:41 +02:00
|
|
|
, ...
|
|
|
|
}@args:
|
2021-11-23 12:02:55 +01:00
|
|
|
let
|
2023-04-15 16:17:41 +02:00
|
|
|
flutterSetupScript = ''
|
2023-08-27 15:11:24 +02:00
|
|
|
# Pub needs SSL certificates. Dart normally looks in a hardcoded path.
|
|
|
|
# https://github.com/dart-lang/sdk/blob/3.1.0/runtime/bin/security_context_linux.cc#L48
|
|
|
|
#
|
|
|
|
# Dart does not respect SSL_CERT_FILE...
|
|
|
|
# https://github.com/dart-lang/sdk/issues/48506
|
|
|
|
# ...and Flutter does not support --root-certs-file, so the path cannot be manually set.
|
|
|
|
# https://github.com/flutter/flutter/issues/56607
|
|
|
|
# https://github.com/flutter/flutter/issues/113594
|
|
|
|
#
|
|
|
|
# libredirect is of no use either, as Flutter does not pass any
|
|
|
|
# environment variables (including LD_PRELOAD) to the Pub process.
|
|
|
|
#
|
|
|
|
# Instead, Flutter is patched to allow the path to the Dart binary used for
|
|
|
|
# Pub commands to be overriden.
|
|
|
|
export NIX_FLUTTER_PUB_DART="${runCommand "dart-with-certs" { nativeBuildInputs = [ makeWrapper ]; } ''
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
makeWrapper ${flutter.dart}/bin/dart "$out/bin/dart" \
|
|
|
|
--add-flags "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt"
|
|
|
|
''}/bin/dart"
|
|
|
|
|
2023-04-15 16:17:41 +02:00
|
|
|
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;
|
2023-04-15 17:49:43 +02:00
|
|
|
inherit pubGetScript vendorHash pubspecLockFile;
|
2023-04-15 16:17:41 +02:00
|
|
|
buildDrvArgs = args;
|
|
|
|
};
|
2023-04-16 18:48:10 +02:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
baseDerivation = llvmPackages_13.stdenv.mkDerivation (finalAttrs: args // {
|
|
|
|
inherit flutterBuildFlags runtimeDependencies;
|
2023-04-16 18:48:10 +02:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
outputs = [ "out" "debug" ];
|
2023-04-16 07:56:14 +02:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
nativeBuildInputs = [
|
|
|
|
makeWrapper
|
|
|
|
deps
|
|
|
|
flutter
|
2023-04-22 08:42:22 +02:00
|
|
|
jq
|
2023-04-16 19:01:32 +02:00
|
|
|
] ++ nativeBuildInputs;
|
2023-04-13 14:00:24 +02:00
|
|
|
|
2023-04-22 08:42:22 +02:00
|
|
|
preUnpack = ''
|
2023-04-22 16:32:24 +02:00
|
|
|
${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
|
|
|
|
''}
|
2023-04-22 08:42:22 +02:00
|
|
|
|
|
|
|
${preUnpack}
|
|
|
|
'';
|
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
${flutterSetupScript}
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
mkdir -p build/flutter_assets/fonts
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-05-11 16:44:11 +02:00
|
|
|
doPubGet flutter pub get --offline -v
|
2023-04-16 19:01:32 +02:00
|
|
|
flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") finalAttrs.flutterBuildFlags)}
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
built=build/linux/*/release/bundle
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
mkdir -p $out/bin
|
|
|
|
mv $built $out/app
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
for f in $(find $out/app -iname "*.desktop" -type f); do
|
|
|
|
install -D $f $out/share/applications/$(basename $f)
|
|
|
|
done
|
2022-02-20 18:44:18 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
for f in $(find $out/app -maxdepth 1 -type f); do
|
|
|
|
ln -s $f $out/bin/$(basename $f)
|
|
|
|
done
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
# make *.so executable
|
|
|
|
find $out/app -iname "*.so" -type f -exec chmod +x {} +
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02: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
|
2021-11-23 12:02:55 +01:00
|
|
|
|
2023-04-16 19:01:32 +02:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2023-04-16 11:25:42 +02:00
|
|
|
|
2023-04-16 19:01:32 +02: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-14 17:10:49 +02:00
|
|
|
--suffix LD_LIBRARY_PATH : '${lib.makeLibraryPath finalAttrs.runtimeDependencies}' \
|
|
|
|
${extraWrapProgramArgs}
|
2023-04-16 19:01:32 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
${postFixup}
|
|
|
|
'';
|
2023-04-22 08:42:22 +02:00
|
|
|
|
2023-08-28 18:14:13 +02:00
|
|
|
passthru = (args.passthru or {}) // {
|
2023-04-22 08:42:22 +02:00
|
|
|
inherit (deps) depsListFile;
|
|
|
|
};
|
2023-04-16 19:01:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
packageOverrideRepository = (callPackage ../../development/compilers/flutter/package-overrides { }) // customPackageOverrides;
|
2023-04-22 16:32:24 +02:00
|
|
|
productPackages = builtins.filter (package: package.kind != "dev")
|
|
|
|
(if autoDepsList
|
2023-05-05 21:39:20 +02:00
|
|
|
then lib.importJSON deps.depsListFile
|
2023-04-22 16:32:24 +02:00
|
|
|
else
|
|
|
|
if depsListFile == null
|
|
|
|
then [ ]
|
2023-05-05 21:39:20 +02:00
|
|
|
else lib.importJSON depsListFile);
|
2023-04-16 19:01:32 +02:00
|
|
|
in
|
|
|
|
builtins.foldl'
|
|
|
|
(prev: package:
|
|
|
|
if packageOverrideRepository ? ${package.name}
|
2023-04-17 06:40:18 +02:00
|
|
|
then
|
|
|
|
prev.overrideAttrs
|
|
|
|
(packageOverrideRepository.${package.name} {
|
|
|
|
inherit (package)
|
|
|
|
name
|
|
|
|
version
|
|
|
|
kind
|
|
|
|
source
|
|
|
|
dependencies;
|
|
|
|
})
|
2023-04-16 19:01:32 +02:00
|
|
|
else prev)
|
|
|
|
baseDerivation
|
|
|
|
productPackages
|