Skip to content

Flutter fails on Nix/macOS due to write attempts in read-only SDK path #175842

@jimmyff

Description

@jimmyff

Steps to reproduce

When the Flutter SDK is installed via the Nix package manager on macOS, the SDK is placed in the read-only /nix/store. The flutter tool currently attempts to create a cache/artifacts directory relative to its own executable path. This fails because the location is immutable, causing any build or run command for macOS to fail with a FileSystemException.

This issue prevents Flutter from being used for macOS development when installed via Nix.

This problem was previously identified and a solution was proposed in PR #155139, but the PR went stale and was closed. I am encountering the same issue and believe that PR's approach is still the correct way to resolve this.

Steps to reproduce

  1. Install the Flutter SDK on macOS using the Nix package manager.
  2. Create a new, default Flutter application: flutter create my_app
  3. Change into the project directory: cd my_app
  4. Attempt to run the application on the macOS target: flutter run -d macos (or build directly from Xcode).

Expected results

The Flutter application builds and runs successfully on macOS without any file system permission errors.

Actual results

The build fails with a FileSystemException. The flutter tool throws an error because it cannot create a directory within the read-only /nix/store path where the SDK is located.

Key error from the logs:

Error: Flutter failed to create a directory at
"/nix/store/vp16mw78rjzca3ar9whk0cni9z0q25ag-flutter-3.35.2-unwrapped/bin/cache/artifacts".
Please ensure that the SDK and/or project is installed in a location that has read/write
permissions for the current user.

Full stack trace snippet:

[        ] Target debug_unpack_macos failed: Error: Flutter failed to create a directory at
"/nix/store/vp16mw78rjzca3ar9whk0cni9z0q25ag-flutter-3.35.2-unwrapped/bin/cache/artifacts".
[        ]         Please ensure that the SDK and/or project is installed in a location that has read/write
permissions for the current user.
[        ]         #0      throwToolExit (package:flutter_tools/src/base/common.dart:34:3)
[        ]         #1      _throwFileSystemException (package:flutter_tools/src/base/error_handling_io.dart:828:3)
[        ]         #2      _handlePosixException (package:flutter_tools/src/base/error_handling_io.dart:737:3)
[        ]         #3      _runSync (package:flutter_tools/src/base/error_handling_io.dart:562:7)
[        ]         #4      ErrorHandlingDirectory.createSync
(package:flutter_tools/src/base/error_handling_io.dart:398:12)
[        ]         #5      Cache.getCacheDir (package:flutter_tools/src/cache.dart:620:11)
[        ]         #6      Cache.getCacheArtifacts (package:flutter_tools/src/cache.dart:630:36)
[        ]         #7      Cache.getArtifactDirectory (package:flutter_tools/src/cache.dart:638:12)
[        ]         #8      CachedArtifacts._getHostArtifactPath (package:flutter_tools/src/artifacts.dart:809:51)
[        ]         #9      CachedArtifacts.getArtifactPath (package:flutter_tools/src/artifacts.dart:531:16)
[        ]         #10     UnpackDarwin.copyFramework
(package:flutter_tools/src/build_system/targets/darwin.dart:26:51)
[        ]         #11     UnpackMacOS.build (package:flutter_tools/src/build_system/targets/macos.dart:61:11)
...

Code sample

This issue is environment-specific and not related to application code. It can be reproduced with the default application template generated by flutter create. No specific code sample is required.

Screenshots or Video

n/a

Logs

Logs
/tmp on ☁️  jimmyffflutter create my_app --platforms macos
Creating project my_app...
Resolving dependencies in `my_app`... 
Downloading packages... 
Got dependencies in `my_app`.
Wrote 39 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd my_app
  $ flutter run

Your application code is in my_app/lib/main.dart.


/tmp on ☁️  jimmyffcd my_app/

/tmp/my_app is 📦 v1.0.0+1 via 🎯 v3.9.0 on ☁️  jimmyffflutter run --debug --device-id macos
Resolving dependencies... 
Downloading packages... 
  characters 1.4.0 (1.4.1 available)
  flutter_lints 5.0.0 (6.0.0 available)
  lints 5.1.1 (6.0.0 available)
  material_color_utilities 0.11.1 (0.13.0 available)
  meta 1.16.0 (1.17.0 available)
  test_api 0.7.6 (0.7.7 available)
Got dependencies!
6 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
Launching lib/main.dart on macOS in debug mode...
Target debug_unpack_macos failed: Error: Flutter failed to create a directory at "/nix/store/vp16mw78rjzca3ar9whk0cni9z0q25ag-flutter-3.35.2-unwrapped/bin/cache/artifacts".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.

Target kernel_snapshot_program failed: Error: Flutter failed to create a directory at "/nix/store/vp16mw78rjzca3ar9whk0cni9z0q25ag-flutter-3.35.2-unwrapped/bin/cache/artifacts".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
Failed to package /private/tmp/my_app.
Command PhaseScriptExecution failed with a nonzero exit code
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this issue, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

Building macOS application...                                           
Error: Build process failed

/tmp/my_app is 📦 v1.0.0+1 via 🎯 v3.9.0 on ☁️  jimmyff took 5s 

Flutter Doctor output

Doctor output
flutter doctor -v
[✓] Flutter (Channel stable, 3.35.2, on macOS 15.6.1 24G90 darwin-arm64, locale en-GB) [230ms]
    • Flutter version 3.35.2 on channel stable at
      /nix/store/qzqgrqqwmjx70978k8ddx3p56fy0lhpq-flutter-wrapped-3.35.2-sdk-links
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision nixpkgs000 (), 1970-01-01 00:00:00
    • Engine revision a8bfdfc394
    • Dart version 3.9.0
    • DevTools version 2.48.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android,
      enable-ios, cli-animations, enable-lldb-debugging

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [1,805ms]
    • Android SDK at /nix/store/4kmlxalnjc2ixvvqkdyyxqbg1l2w8qvs-android-sdk-env/share/android-sdk
    • Emulator version 36.2.9.0 (build_id 14097453) (CL:N/A)
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /nix/store/4kmlxalnjc2ixvvqkdyyxqbg1l2w8qvs-android-sdk-env/share/android-sdk
    • ANDROID_SDK_ROOT = /nix/store/4kmlxalnjc2ixvvqkdyyxqbg1l2w8qvs-android-sdk-env/share/android-sdk
    • Java binary at: /nix/store/c0zwkd0idwp22ic1aw5ax3ncn0648689-zulu-ca-jdk-17.0.12/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Zulu17.52+17-CA (build 17.0.12+7-LTS)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,446ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google
    Chrome.app/Contents/MacOS/Google Chrome) [10ms]
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2025.1) [9ms]
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.7+-13880790-b1038.58)

[✓] Connected device (2 available) [5.8s]
    • Pixel 5 (mobile) • 0A021FDD4003PN • android-arm64 • Android 14 (API 34)
    • macOS (desktop)  • macos          • darwin-arm64  • macOS 15.6.1 24G90 darwin-arm64

[✓] Network resources [655ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectfyi-toolFor the attention of Flutter Tool teamplatform-macBuilding on or for macOS specificallyteam-macosOwned by the macOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-macosTriaged by the macOS platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions