nixpkgs/pkgs/development/compilers/flutter/flutter-tools.nix
Yueh-Shun Li 91b3db1309 treewide: fix sourceRoot for fetchgit-based src
According to Nixpkgs manual[1] and NixOS 23.11 Release Note[2], the
`sourceRoot` attribute passed to `stdenv.mkDerivation` should be
specified as `"${src.name}"` or `"${src.name}/subdir"` when `src` is
produced using `fetchgit`-based fetchers.

`sourceRoot = "source"` or `sourceRoot = "source/subdir"` is based on
the assumption that the `name` attribute of these pre-unpacked fetchers
are always `"source"`, which is not the case. Expecting constant `name`
also makes the source FODs prone to irrelevent hashes during version
bumps.

[1]: https://nixos.org/manual/nixpkgs/unstable/#var-stdenv-sourceRoot
[2]: https://nixos.org/manual/nixos/stable/release-notes#sec-release-23.11
2024-03-09 07:53:25 +08:00

61 lines
1.6 KiB
Nix

{ lib
, stdenv
, systemPlatform
, buildDartApplication
, git
, which
, dart
, version
, flutterSrc
, patches ? [ ]
, pubspecLock
, darwin
}:
buildDartApplication.override { inherit dart; } rec {
pname = "flutter-tools";
inherit version;
dartOutputType = "jit-snapshot";
src = flutterSrc;
sourceRoot = "${src.name}/packages/flutter_tools";
postUnpack = ''chmod -R u+w "$NIX_BUILD_TOP/source"'';
inherit patches;
# The given patches are made for the entire SDK source tree.
prePatch = ''pushd "$NIX_BUILD_TOP/source"'';
postPatch = ''
popd
''
# Remove impure references to `arch` and use arm64 instead of arm64e.
+ lib.optionalString stdenv.isDarwin ''
substituteInPlace lib/src/ios/xcodeproj.dart \
--replace-fail /usr/bin/arch '${darwin.adv_cmds}/bin/arch' \
--replace-fail arm64e arm64
'';
# When the JIT snapshot is being built, the application needs to run.
# It attempts to generate configuration files, and relies on a few external
# tools.
nativeBuildInputs = [ git which ];
preConfigure = ''
export HOME=.
export FLUTTER_ROOT="$NIX_BUILD_TOP/source"
mkdir -p "$FLUTTER_ROOT/bin/cache"
ln -s '${dart}' "$FLUTTER_ROOT/bin/cache/dart-sdk"
'';
dartEntryPoints."flutter_tools.snapshot" = "bin/flutter_tools.dart";
dartCompileFlags = [ "--define=NIX_FLUTTER_HOST_PLATFORM=${systemPlatform}" ];
# The Dart wrapper launchers are useless for the Flutter tool - it is designed
# to be launched from a snapshot by the SDK.
postInstall = ''
pushd "$out"
rm ${builtins.concatStringsSep " " (builtins.attrNames dartEntryPoints)}
popd
'';
inherit pubspecLock;
}