Skip to content

Commit

Permalink
dart: Spoof Git dependency version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hacker1024 committed May 11, 2023
1 parent 6b5781c commit 5e0fa3e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
17 changes: 16 additions & 1 deletion pkgs/build-support/dart/fetch-dart-deps/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ stdenvNoCC
, lib
, makeSetupHook
, writeShellScriptBin
, dart
, git
, cacert
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions pkgs/build-support/dart/fetch-dart-deps/setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ _setupPubCache() {
exit 1
fi
}

# Performs the given pub get command with an appropriate environment.
doPubGet() {
PATH="@gitSourceWrapper@/bin:$PATH" "$@"
}
2 changes: 1 addition & 1 deletion pkgs/build-support/flutter/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/tools/misc/dart-sass/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ stdenvNoCC.mkDerivation (finalAttrs: rec {

configurePhase = ''
runHook preConfigure
dart pub get --offline
doPubGet dart pub get --offline
runHook postConfigure
'';

Expand Down
2 changes: 1 addition & 1 deletion pkgs/misc/dart-sass-embedded/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ stdenvNoCC.mkDerivation (finalAttrs: {

configurePhase = ''
runHook preConfigure
dart pub get --offline
doPubGet dart pub get --offline
mkdir build
ln -s ${embedded-protocol} build/embedded-protocol
runHook postConfigure
Expand Down

0 comments on commit 5e0fa3e

Please sign in to comment.