about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhacker1024 <hacker1024@users.sourceforge.net>2023-04-17 03:01:32 +1000
committerhacker1024 <hacker1024@users.sourceforge.net>2023-04-17 03:21:01 +1000
commit0495725a1f8e9df1ac3996459a9bb82305e69242 (patch)
tree9d4f8ad6ada1fe511b526bc6a11be8ce65574d72
parent329c494d0c9e5983da84d5230a00c325b932f79c (diff)
flutter.buildFlutterApplication: Introduce a package override repository
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.
-rw-r--r--pkgs/build-support/flutter/default.nix128
-rw-r--r--pkgs/development/compilers/flutter/package-overrides/default.nix4
2 files changed, 74 insertions, 58 deletions
diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix
index 932306e86d1b3..8c732c3377940 100644
--- a/pkgs/build-support/flutter/default.nix
+++ b/pkgs/build-support/flutter/default.nix
@@ -12,6 +12,7 @@
 { pubGetScript ? "flutter pub get"
 , flutterBuildFlags ? [ ]
 , runtimeDependencies ? [ ]
+, customPackageOverrides ? { }
 , vendorHash
 , pubspecLockFile ? null
 , nativeBuildInputs ? [ ]
@@ -31,79 +32,90 @@ let
     buildDrvArgs = args;
   };
 
-in
-llvmPackages_13.stdenv.mkDerivation (finalAttrs: args // {
-  inherit flutterBuildFlags runtimeDependencies;
+  baseDerivation = llvmPackages_13.stdenv.mkDerivation (finalAttrs: args // {
+    inherit flutterBuildFlags runtimeDependencies;
 
-  outputs = [ "out" "debug" ];
+    outputs = [ "out" "debug" ];
 
-  nativeBuildInputs = [
-    makeWrapper
-    deps
-    flutter
-  ] ++ nativeBuildInputs;
+    nativeBuildInputs = [
+      makeWrapper
+      deps
+      flutter
+    ] ++ nativeBuildInputs;
 
-  configurePhase = ''
-    runHook preConfigure
+    configurePhase = ''
+      runHook preConfigure
 
-    ${flutterSetupScript}
+      ${flutterSetupScript}
 
-    runHook postConfigure
-  '';
+      runHook postConfigure
+    '';
 
-  buildPhase = ''
-    runHook preBuild
+    buildPhase = ''
+      runHook preBuild
 
-    mkdir -p build/flutter_assets/fonts
+      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)}
+      flutter packages get --offline -v
+      flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") finalAttrs.flutterBuildFlags)}
 
-    runHook postBuild
-  '';
+      runHook postBuild
+    '';
 
-  installPhase = ''
-    runHook preInstall
+    installPhase = ''
+      runHook preInstall
 
-    built=build/linux/*/release/bundle
+      built=build/linux/*/release/bundle
 
-    mkdir -p $out/bin
-    mv $built $out/app
+      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 -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
+      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 {} +
+      # 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
+      # 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
-  '';
+      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}
-  '';
-})
+    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
diff --git a/pkgs/development/compilers/flutter/package-overrides/default.nix b/pkgs/development/compilers/flutter/package-overrides/default.nix
new file mode 100644
index 0000000000000..4a3fcd1cded04
--- /dev/null
+++ b/pkgs/development/compilers/flutter/package-overrides/default.nix
@@ -0,0 +1,4 @@
+{ callPackage }:
+
+{
+}