From 936c66911831243ecd0f24583d14492ee3e41c55 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 7 May 2022 00:01:31 +0200 Subject: [PATCH] Add nix flake --- .gitignore | 2 + flake.lock | 184 ++++++++++++++++++ flake.nix | 116 +++++++++++ nix/dart.nix | 74 +++++++ nix/flutter.nix | 24 +++ nix/flutter_builder.nix | 178 +++++++++++++++++ nix/flutter_patches/disable-auto-update.patch | 37 ++++ nix/flutter_patches/move-cache.patch | 77 ++++++++ 8 files changed, 692 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/dart.nix create mode 100644 nix/flutter.nix create mode 100644 nix/flutter_builder.nix create mode 100644 nix/flutter_patches/disable-auto-update.patch create mode 100644 nix/flutter_patches/move-cache.patch diff --git a/.gitignore b/.gitignore index 0fa6b67..0f0410a 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,5 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f75652d --- /dev/null +++ b/flake.lock @@ -0,0 +1,184 @@ +{ + "nodes": { + "android-nixpkgs": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1651782096, + "narHash": "sha256-rrj0HPwmDf6Q14sljnVf2hkMvc97rndgi4PJkFtpFPk=", + "owner": "tadfisher", + "repo": "android-nixpkgs", + "rev": "ccd2a8f58709ea3413fcb72769b2f62a98332215", + "type": "github" + }, + "original": { + "owner": "tadfisher", + "repo": "android-nixpkgs", + "type": "github" + } + }, + "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1650900878, + "narHash": "sha256-qhNncMBSa9STnhiLfELEQpYC1L4GrYHNIzyCZ/pilsI=", + "owner": "numtide", + "repo": "devshell", + "rev": "d97df53b5ddaa1cfbea7cddbd207eb2634304733", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "locked": { + "lastModified": 1649676176, + "narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nix-dart": { + "inputs": { + "flake-utils": "flake-utils_4", + "nixpkgs": [ + "nixpkgs" + ], + "pub2nix": "pub2nix" + }, + "locked": { + "lastModified": 1651781526, + "narHash": "sha256-q01e+S69g4UDrMcEitaQOccr2aHeiJ+VEmPS94h/7WY=", + "owner": "tadfisher", + "repo": "nix-dart", + "rev": "71d2fda0f9590d5de917fb736dee312d9fef7e27", + "type": "github" + }, + "original": { + "owner": "tadfisher", + "repo": "nix-dart", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1643381941, + "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1651743098, + "narHash": "sha256-NuQNu6yHh54li0kZffM59FRC5bWCJusygL4Cy+3O0fY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d4191fe35cbe52f755ef73009d4d37b9e002efa2", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-21.11", + "type": "indirect" + } + }, + "pub2nix": { + "flake": false, + "locked": { + "lastModified": 1594192744, + "narHash": "sha256-pDvcXSG1Mh2BpwkqAcNDJzcupV3pIAAtZJLfkiHMAz4=", + "owner": "paulyoung", + "repo": "pub2nix", + "rev": "0c7ecca590fcd1616db8c6468f799ffef36c85e9", + "type": "github" + }, + "original": { + "owner": "paulyoung", + "repo": "pub2nix", + "type": "github" + } + }, + "root": { + "inputs": { + "android-nixpkgs": "android-nixpkgs", + "flake-utils": "flake-utils_3", + "nix-dart": "nix-dart", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6f3f0c9 --- /dev/null +++ b/flake.nix @@ -0,0 +1,116 @@ +{ + description = "A dictionary app for studying japanese"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-21.11"; + + flake-utils = { + url = "github:numtide/flake-utils"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + android-nixpkgs = { + url = "github:tadfisher/android-nixpkgs"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + nix-dart = { + url = "github:tadfisher/nix-dart"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + # nix-flutter = { + # url = "path:/home/h7x4/git/flutter_linux_2.5.1-stable/flutter"; + # inputs.nixpkgs.follows = "nixpkgs"; + # }; + }; + + outputs = { self, nixpkgs, flake-utils, android-nixpkgs, nix-dart }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + config = { + android_sdk.accept_license = true; + allowUnfree = true; + }; + }; + + dartVersion = "2.14.2"; + dartChannel = "stable"; + + flutterVersion = "2.5.1"; + flutterChannel = "stable"; + in { + + packages.${system} = { + android-sdk = android-nixpkgs.sdk.${system} (sdkPkgs: with sdkPkgs; [ + cmdline-tools-latest + build-tools-32-0-0 + build-tools-31-0-0 + build-tools-30-0-2 + build-tools-29-0-2 + platform-tools + platforms-android-32 + platforms-android-31 + platforms-android-30 + platforms-android-29 + emulator + ]); + + # dart = nix-dart.packages.${system}.dart; + dart = (pkgs.callPackage ./nix/dart.nix {}); + + inherit (pkgs.callPackage ./nix/flutter.nix { inherit (self.packages.${system}) dart; }) flutter; + + # pub2nix-lock = nix-dart.packages.${system}.pub2nix-lock; + }; + + # apps.${system} = { + # web-debug = { + # type = "app"; + # program = ""; + # }; + # web-release = { + # type = "app"; + # program = ""; + # }; + # apk-debug = { + # type = "app"; + # program = ""; + # }; + # apk-release = { + # type = "app"; + # program = "${self.packages.${system}.flutter}/bin/flutter run --release"; + # }; + # default = self.apps.${system}.apk-debug; + # }; + + devShell.${system} = let + inherit (pkgs) lcov google-chrome sqlite sqlite-web; + inherit (self.packages.${system}) android-sdk flutter dart; + inherit (nix-dart.packages.${system}) pub2nix-lock; + java = pkgs.jdk8; + in pkgs.mkShell rec { + ANDROID_JAVA_HOME="${java.home}"; + ANDROID_SDK_ROOT = "${android-sdk}/share/android-sdk"; + CHROME_EXECUTABLE = "${google-chrome}/bin/google-chrome-stable"; + FLUTTER_SDK="${flutter}"; + GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/32.0.0/aapt2"; + JAVA_HOME="${ANDROID_JAVA_HOME}"; + USE_CCACHE=0; + + buildInputs = [ + android-sdk + dart + flutter + google-chrome + java + lcov + pub2nix-lock + sqlite + sqlite-web + ]; + }; + }; +} diff --git a/nix/dart.nix b/nix/dart.nix new file mode 100644 index 0000000..f1e3edc --- /dev/null +++ b/nix/dart.nix @@ -0,0 +1,74 @@ +{ stdenv +, lib +, fetchurl +, unzip +, version ? "2.16.2" +, sources ? let + base = "https://storage.googleapis.com/dart-archive/channels"; + x86_64 = "x64"; + i686 = "ia32"; + aarch64 = "arm64"; + # Make sure that if the user overrides version parameter they're + # also need to override sources, to avoid mistakes + version = "2.16.2"; + in + { + "${version}-aarch64-darwin" = fetchurl { + url = "${base}/stable/release/${version}/sdk/dartsdk-macos-${aarch64}-release.zip"; + sha256 = "sha256-DDE4DpA2m8wKkUZuQDn4NpXVvtaJ6sIHeKNjk3RbpYE="; + }; + "${version}-x86_64-darwin" = fetchurl { + url = "${base}/stable/release/${version}/sdk/dartsdk-macos-${x86_64}-release.zip"; + sha256 = "sha256-s6bkwh2m5KdRr/WxWXwItO9YaDpp/HI3xjnS2UHmN+I="; + }; + "${version}-x86_64-linux" = lib.trace version fetchurl { + url = "${base}/stable/release/${version}/sdk/dartsdk-linux-${x86_64}-release.zip"; + sha256 = "sha256-egrYd7B4XhkBiHPIFE2zopxKtQ58GqlogAKA/UeiXnI="; + }; + "${version}-i686-linux" = fetchurl { + url = "${base}/stable/release/${version}/sdk/dartsdk-linux-${i686}-release.zip"; + sha256 = "sha256-SRq5TtxS+bwCqVxa0U2Zhn8J1Wtm4Onq+3uQS+951sw="; + }; + "${version}-aarch64-linux" = fetchurl { + url = "${base}/stable/release/${version}/sdk/dartsdk-linux-${aarch64}-release.zip"; + sha256 = "sha256-iDbClCNDUsxT6K6koc4EQuu7dppTbOfzCVedpQIKI5U="; + }; + } +}: + +assert version != null && version != ""; +assert sources != null && (builtins.isAttrs sources); + +stdenv.mkDerivation { + pname = "dart"; + inherit version; + + nativeBuildInputs = [ unzip ]; + + src = sources."${version}-${stdenv.hostPlatform.system}" or (throw "unsupported version/system: ${version}/${stdenv.hostPlatform.system}"); + + installPhase = '' + mkdir -p $out + cp -R * $out/ + echo $libPath + '' + lib.optionalString(stdenv.isLinux) '' + find $out/bin -executable -type f -exec patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \; + ''; + + libPath = lib.makeLibraryPath [ stdenv.cc.cc ]; + + dontStrip = true; + + meta = with lib; { + homepage = "https://www.dartlang.org/"; + maintainers = with maintainers; [ grburst flexagoon ]; + description = "Scalable programming language, with robust libraries and runtimes, for building web, server, and mobile apps"; + longDescription = '' + Dart is a class-based, single inheritance, object-oriented language + with C-style syntax. It offers compilation to JavaScript, interfaces, + mixins, abstract classes, reified generics, and optional typing. + ''; + platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + license = licenses.bsd3; + }; +} diff --git a/nix/flutter.nix b/nix/flutter.nix new file mode 100644 index 0000000..52aa995 --- /dev/null +++ b/nix/flutter.nix @@ -0,0 +1,24 @@ +{ flutterPackages, fetchurl, dart }: +let + dartVersion = "2.16.2"; + flutterVersion = "2.10.5"; + + channel = "stable"; + filename = "flutter_linux_${flutterVersion}-${channel}.tar.xz"; + + getPatches = dir: + let files = builtins.attrNames (builtins.readDir dir); + in map (f: dir + ("/" + f)) files; +in +{ + flutter = flutterPackages.mkFlutter { + version = flutterVersion; + inherit dart; + pname = "flutter"; + src = fetchurl { + url = "https://storage.googleapis.com/flutter_infra_release/releases/${channel}/linux/${filename}"; + sha256 = "DTZwxlMUYk8NS1SaWUJolXjD+JnRW73Ps5CdRHDGnt0="; + }; + patches = getPatches ./flutter_patches; + }; +} diff --git a/nix/flutter_builder.nix b/nix/flutter_builder.nix new file mode 100644 index 0000000..86355a5 --- /dev/null +++ b/nix/flutter_builder.nix @@ -0,0 +1,178 @@ +{ pname +, version +, patches +, dart +, src +}: + +{ bash +, buildFHSUserEnv +, cacert +, git +, runCommand +, stdenv +, lib +, alsa-lib +, dbus +, expat +, libpulseaudio +, libuuid +, libX11 +, libxcb +, libXcomposite +, libXcursor +, libXdamage +, libXfixes +, libXrender +, libXtst +, libXi +, libXext +, libGL +, nspr +, nss +, systemd +, which +, callPackage +}: +let + drvName = "flutter-${version}"; + flutter = stdenv.mkDerivation { + name = "${drvName}-unwrapped"; + + buildInputs = [ git ]; + + inherit src patches version; + + postPatch = '' + patchShebangs --build ./bin/ + ''; + + buildPhase = '' + export FLUTTER_ROOT="$(pwd)" + export FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools" + export SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/flutter_tools.dart" + export SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot" + export STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp" + export DART_SDK_PATH="${dart}" + HOME=../.. # required for pub upgrade --offline, ~/.pub-cache + # path is relative otherwise it's replaced by /build/flutter + pushd "$FLUTTER_TOOLS_DIR" + ${dart}/bin/pub get --offline + popd + local revision="$(cd "$FLUTTER_ROOT"; git rev-parse HEAD)" + ${dart}/bin/dart --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH" + echo "$revision" > "$STAMP_PATH" + echo -n "${version}" > version + rm -r bin/cache/{artifacts,dart-sdk,downloads} + rm bin/cache/*.stamp + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out + cp -r . $out + mkdir -p $out/bin/cache/ + ln -sf ${dart} $out/bin/cache/dart-sdk + runHook postInstall + ''; + + doInstallCheck = true; + installCheckInputs = [ which ]; + installCheckPhase = '' + runHook preInstallCheck + export HOME="$(mktemp -d)" + $out/bin/flutter config --android-studio-dir $HOME + $out/bin/flutter config --android-sdk $HOME + $out/bin/flutter --version | fgrep -q '${version}' + runHook postInstallCheck + ''; + }; + + # Wrap flutter inside an fhs user env to allow execution of binary, + # like adb from $ANDROID_HOME or java from android-studio. + fhsEnv = buildFHSUserEnv { + name = "${drvName}-fhs-env"; + multiPkgs = pkgs: [ + # Flutter only use these certificates + (runCommand "fedoracert" { } '' + mkdir -p $out/etc/pki/tls/ + ln -s ${cacert}/etc/ssl/certs $out/etc/pki/tls/certs + '') + pkgs.zlib + ]; + targetPkgs = pkgs: + with pkgs; [ + bash + curl + dart + git + unzip + which + xz + + # flutter test requires this lib + libGLU + + # for android emulator + alsa-lib + dbus + expat + libpulseaudio + libuuid + libX11 + libxcb + libXcomposite + libXcursor + libXdamage + libXext + libXfixes + libXi + libXrender + libXtst + libGL + nspr + nss + systemd + ]; + }; + +in +let +self = (self: +runCommand drvName +{ + startScript = '' + #!${bash}/bin/bash + export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"} + export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1 + ${fhsEnv}/bin/${drvName}-fhs-env ${flutter}/bin/flutter --no-version-check "$@" + ''; + preferLocalBuild = true; + allowSubstitutes = false; + passthru = { + unwrapped = flutter; + inherit dart; + mkFlutterApp = callPackage ../../../build-support/flutter { + flutter = self; + }; + }; + meta = with lib; { + description = "Flutter is Google's SDK for building mobile, web and desktop with Dart"; + longDescription = '' + Flutter is Google’s UI toolkit for building beautiful, + natively compiled applications for mobile, web, and desktop from a single codebase. + ''; + homepage = "https://flutter.dev"; + license = licenses.bsd3; + platforms = [ "x86_64-linux" ]; + maintainers = with maintainers; [ babariviere ericdallo ]; + }; +} '' + mkdir -p $out/bin + mkdir -p $out/bin/cache/ + ln -sf ${dart} $out/bin/cache/dart-sdk + echo -n "$startScript" > $out/bin/${pname} + chmod +x $out/bin/${pname} +'') self; +in +self \ No newline at end of file diff --git a/nix/flutter_patches/disable-auto-update.patch b/nix/flutter_patches/disable-auto-update.patch new file mode 100644 index 0000000..6712643 --- /dev/null +++ b/nix/flutter_patches/disable-auto-update.patch @@ -0,0 +1,37 @@ +diff --git i/bin/internal/shared.sh w/bin/internal/shared.sh +index 05cba4393b..2a775bf24f 100644 +--- i/bin/internal/shared.sh ++++ w/bin/internal/shared.sh +@@ -217,8 +217,6 @@ function shared::execute() { + # FLUTTER_TOOL_ARGS="--enable-asserts $FLUTTER_TOOL_ARGS" + # FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432" + +- upgrade_flutter 7< "$PROG_NAME" +- + BIN_NAME="$(basename "$PROG_NAME")" + case "$BIN_NAME" in + flutter*) +diff --git i/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart w/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +index 396756808e..4915f71f18 100644 +--- i/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart ++++ w/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +@@ -241,7 +241,6 @@ class FlutterCommandRunner extends CommandRunner { + globals.flutterUsage.suppressAnalytics = true; + } + +- globals.flutterVersion.ensureVersionFile(); + final bool machineFlag = topLevelResults['machine'] as bool? ?? false; + final bool ci = await globals.botDetector.isRunningOnBot; + final bool redirectedCompletion = !globals.stdio.hasTerminal && +@@ -250,11 +249,6 @@ class FlutterCommandRunner extends CommandRunner { + final bool versionCheckFlag = topLevelResults['version-check'] as bool? ?? false; + final bool explicitVersionCheckPassed = topLevelResults.wasParsed('version-check') && versionCheckFlag; + +- if (topLevelResults.command?.name != 'upgrade' && +- (explicitVersionCheckPassed || (versionCheckFlag && !isMachine))) { +- await globals.flutterVersion.checkFlutterVersionFreshness(); +- } +- + // See if the user specified a specific device. + globals.deviceManager?.specifiedDeviceId = topLevelResults['device-id'] as String?; + diff --git a/nix/flutter_patches/move-cache.patch b/nix/flutter_patches/move-cache.patch new file mode 100644 index 0000000..12ab261 --- /dev/null +++ b/nix/flutter_patches/move-cache.patch @@ -0,0 +1,77 @@ +diff --git i/packages/flutter_tools/lib/src/asset.dart w/packages/flutter_tools/lib/src/asset.dart +index ed42baea29..e7308372e7 100644 +--- i/packages/flutter_tools/lib/src/asset.dart ++++ w/packages/flutter_tools/lib/src/asset.dart +@@ -5,6 +5,7 @@ + import 'package:meta/meta.dart'; + import 'package:package_config/package_config.dart'; + ++import 'base/common.dart'; + import 'base/context.dart'; + import 'base/deferred_component.dart'; + import 'base/file_system.dart'; +@@ -16,6 +17,7 @@ import 'convert.dart'; + import 'dart/package_map.dart'; + import 'devfs.dart'; + import 'flutter_manifest.dart'; ++import 'globals.dart' as globals; + import 'license_collector.dart'; + import 'project.dart'; + +@@ -504,7 +506,7 @@ class ManifestAssetBundle implements AssetBundle { + } + final Uri entryUri = _fileSystem.path.toUri(asset); + result.add(_Asset( +- baseDir: _fileSystem.path.join(Cache.flutterRoot!, 'bin', 'cache', 'artifacts', 'material_fonts'), ++ baseDir: _fileSystem.path.join(globals.fsUtils.homeDirPath!, '.cache', 'flutter', 'artifacts', 'material_fonts'), + relativeUri: Uri(path: entryUri.pathSegments.last), + entryUri: entryUri, + package: null, +diff --git i/packages/flutter_tools/lib/src/cache.dart w/packages/flutter_tools/lib/src/cache.dart +index defc86cc20..5078375f02 100644 +--- i/packages/flutter_tools/lib/src/cache.dart ++++ w/packages/flutter_tools/lib/src/cache.dart +@@ -22,6 +22,7 @@ import 'base/user_messages.dart'; + import 'build_info.dart'; + import 'convert.dart'; + import 'features.dart'; ++import 'globals.dart' as globals; + + const String kFlutterRootEnvironmentVariableName = 'FLUTTER_ROOT'; // should point to //flutter/ (root of flutter/flutter repo) + const String kFlutterEngineEnvironmentVariableName = 'FLUTTER_ENGINE'; // should point to //engine/src/ (root of flutter/engine repo) +@@ -322,8 +323,15 @@ class Cache { + return; + } + assert(_lock == null); ++ ++ final Directory dir = _fileSystem.directory(_fileSystem.path.join(globals.fsUtils.homeDirPath!, '.cache', 'flutter')); ++ if (!dir.existsSync()) { ++ dir.createSync(recursive: true); ++ globals.os.chmod(dir, '755'); ++ } ++ + final File lockFile = +- _fileSystem.file(_fileSystem.path.join(flutterRoot!, 'bin', 'cache', 'lockfile')); ++ _fileSystem.file(_fileSystem.path.join(globals.fsUtils.homeDirPath!, '.cache', 'flutter', 'lockfile')); + try { + _lock = lockFile.openSync(mode: FileMode.write); + } on FileSystemException catch (e) { +@@ -383,7 +391,8 @@ class Cache { + String get devToolsVersion { + if (_devToolsVersion == null) { + const String devToolsDirPath = 'dart-sdk/bin/resources/devtools'; +- final Directory devToolsDir = getCacheDir(devToolsDirPath, shouldCreate: false); ++ final Directory devToolsDir = ++ _fileSystem.directory(_fileSystem.path.join(flutterRoot!, 'bin', 'cache', devToolsDirPath)); + if (!devToolsDir.existsSync()) { + throw Exception('Could not find directory at ${devToolsDir.path}'); + } +@@ -536,7 +545,7 @@ class Cache { + if (_rootOverride != null) { + return _fileSystem.directory(_fileSystem.path.join(_rootOverride!.path, 'bin', 'cache')); + } else { +- return _fileSystem.directory(_fileSystem.path.join(flutterRoot!, 'bin', 'cache')); ++ return _fileSystem.directory(_fileSystem.path.join(globals.fsUtils.homeDirPath!, '.cache', 'flutter')); + } + } +