summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorhacker1024 <hacker1024@users.sourceforge.net>2023-05-12 00:44:11 +1000
committerhacker1024 <hacker1024@users.sourceforge.net>2023-05-12 23:04:33 +1000
commit49ce83d5b4d31c6dbd8d48f0a6c872b95f2f2774 (patch)
tree35b29782703be87f3c7a55aa9419c83ff6522ee4 /pkgs/build-support
parent4f4359d6caa2df9df9ff283efb92e35a694eb029 (diff)
dart: Spoof Git dependency version checks
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh2
-rw-r--r--pkgs/build-support/dart/fetch-dart-deps/default.nix17
-rw-r--r--pkgs/build-support/dart/fetch-dart-deps/setup-hook.sh5
-rw-r--r--pkgs/build-support/flutter/default.nix2
4 files changed, 23 insertions, 3 deletions
diff --git a/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh b/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh
index ee610f673d2b9..3e901995237d9 100644
--- a/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh
+++ b/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh
@@ -4,7 +4,7 @@ dartConfigHook() {
     echo "Executing dartConfigHook"
 
     echo "Installing dependencies"
-    eval "$pubGetScript" --offline
+    eval doPubGet "$pubGetScript" --offline
 
     echo "Finished dartConfigHook"
 }
diff --git a/pkgs/build-support/dart/fetch-dart-deps/default.nix b/pkgs/build-support/dart/fetch-dart-deps/default.nix
index 9deb99648c08a..8c45722109bb2 100644
--- a/pkgs/build-support/dart/fetch-dart-deps/default.nix
+++ b/pkgs/build-support/dart/fetch-dart-deps/default.nix
@@ -1,6 +1,7 @@
 { stdenvNoCC
 , lib
 , makeSetupHook
+, writeShellScriptBin
 , dart
 , git
 , cacert
@@ -170,12 +171,26 @@ let
     '';
   } // buildDrvInheritArgs);
 
+  # As of Dart 3.0.0, Pub checks the revision of cached Git-sourced packages.
+  # Git must be wrapped to return a positive result, as the real .git directory is wiped
+  # to produce a deteministic dependency derivation output.
+  # https://github.com/dart-lang/pub/pull/3791/files#diff-1639c4669c428c26e68cfebd5039a33f87ba568795f2c058c303ca8528f62b77R631
+  gitSourceWrapper = writeShellScriptBin "git" ''
+    args=("$@")
+    if [[ "''${args[0]}" == "rev-list" && "''${args[1]}" == "--max-count=1" ]]; then
+      revision="''${args[''${#args[@]}-1]}"
+      echo "$revision"
+    else
+      ${git}/bin/git "''${args[@]}"
+    fi
+  '';
+
   hook = (makeSetupHook {
     # The setup hook should not be part of the fixed-output derivation.
     # Updates to the hook script should not change vendor hashes, and it won't
     # work at all anyway due to https://github.com/NixOS/nix/issues/6660.
     name = "${name}-dart-deps-setup-hook";
-    substitutions = { inherit deps; };
+    substitutions = { inherit gitSourceWrapper deps; };
     propagatedBuildInputs = [ dart git ];
     passthru = {
       files = deps.outPath;
diff --git a/pkgs/build-support/dart/fetch-dart-deps/setup-hook.sh b/pkgs/build-support/dart/fetch-dart-deps/setup-hook.sh
index 37ef74aa62ddd..689e0e8c5b5fc 100644
--- a/pkgs/build-support/dart/fetch-dart-deps/setup-hook.sh
+++ b/pkgs/build-support/dart/fetch-dart-deps/setup-hook.sh
@@ -39,3 +39,8 @@ _setupPubCache() {
         exit 1
     fi
 }
+
+# Performs the given pub get command with an appropriate environment.
+doPubGet() {
+    PATH="@gitSourceWrapper@/bin:$PATH" "$@"
+}
diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix
index 04f9fe4f404c0..ecca6b081f258 100644
--- a/pkgs/build-support/flutter/default.nix
+++ b/pkgs/build-support/flutter/default.nix
@@ -76,7 +76,7 @@ let
 
       mkdir -p build/flutter_assets/fonts
 
-      flutter packages get --offline -v
+      doPubGet flutter pub get --offline -v
       flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") finalAttrs.flutterBuildFlags)}
 
       runHook postBuild