Nixpkgs: package request: flutter

Created on 10 Mar 2018  路  60Comments  路  Source: NixOS/nixpkgs

Issue description

I am trying to package flutter but it's not a success, so can you please try to package it or help me to do it?

Website: https://flutter.io
Source: https://github.com/flutter/flutter

package (new)

Most helpful comment

Hello, I have made a PR with a working example of flutter. There is still a few missing things (like libimobiledevice and probably flutter web).

Other than that, it works with Android SDK downloaded from Android Studio, and it will detect if you have android studio installed or not.

You can install it via nix-env:

nix-env -iA flutter -f  https://github.com/babariviere/nixpkgs/tarball/flutter-init 

or in nix-build / nix-shell / nixos-rebuild with:

flutter = (import (builtins.fetchTarball
    "https://github.com/babariviere/nixpkgs/archive/flutter-init.tar.gz") {}).flutter;

You can also use beta or dev channels by replacing flutter with:

  • flutterPackages.beta
  • flutterPackages.dev

If you have any issue, don't hesitate to comment the PR. I will try to fix them ASAP.

All 60 comments

I'm interested in helping, I want to be able to use Flutter as well. I can't figure out how to install it based on the guide though because it seems to just come with an executable to install it.

Ok, I'm going through the installation process by hand now in order to figure out the necessary steps:

  1. Fix shebangs in scripts (opened an issue for this https://github.com/flutter/flutter/issues/16130)
  2. flutter/bin/flutter doctor => Will fail after downloading the cached version of dart
  3. Patch the cached dart ELF
  4. flutter/bin/flutter doctor again
  5. Will update as I continue

Prerequisites: Needs JDK and Android SDK (androidsdk + androidsdk_extras) pre-installed, won't work with Android Studio installed for some reason (I don't really feel like looking into this because it took me like an hour to get it to work without Android Studio--this file tries to get the Java version that Android Studio uses but on the NixOS package that doesn't exist).

My only solution was to build an fhs user env but I get certificates error.

Because we can't fix downloaded sdk (the flutter doctor retry infinitely)

It might be possible to host the executables in another package and download them along with Flitter before the build sequence, I have to look into that. Did you manage to get it to fully install?

Nope, I can't

I just tried to get flutter working. I downloaded the latest beta version that was offered in the manual. I can install the package without much hassle.

The problem I am running into is that it tries to lock a file within the nix store.

The expression I hacked together is:

{ stdenv, fetchurl }:
stdenv.mkDerivation {
  name = "flutter-0.5.1beta";
  src = fetchurl {
    url = https://storage.googleapis.com/flutter_infra/releases/beta/linux/flutter_linux_v0.5.1-beta.tar.xz;
    sha256 = "1fiw66fzdbp60fcb0hwa1ckrf90k1vmv5gsp8zjrdkmww0ka0rmc";
  };

  buildPhase = null;

  installPhase = ''
    mkdir $out
    cp -avr . $out
    find $out/bin/ -executable -exec patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \;
  '';
}

The error I am getting is:

command

flutter help

exception

FileSystemException: FileSystemException: Cannot open file, path = '/nix/store/41sfdaid5gl4v5a0lyaxl1wpr8y5phs0-flutter-0.5.1beta/bin/cache/lockfile' (OS Error: Read-only file system, errno = 30)

#0      _File.open.<anonymous closure> (dart:io/file_impl.dart:368)
#1      _rootRunUnary (dart:async/zone.dart:1134)
#2      _CustomZone.runUnary (dart:async/zone.dart:1031)
#3      _FutureListener.handleValue (dart:async/future_impl.dart:129)
#4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633)
#5      Future._propagateToListeners (dart:async/future_impl.dart:662)
#6      Future._completeWithValue (dart:async/future_impl.dart:477)
#7      Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:507)
#8      _rootRun (dart:async/zone.dart:1126)
#9      _CustomZone.run (dart:async/zone.dart:1023)
#10     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949)
#11     _microtaskLoop (dart:async/schedule_microtask.dart:41)
#12     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#13     _runPendingImmediateCallback (dart:isolate-patch/dart:isolate/isolate_patch.dart:113)
#14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:166)

flutter doctor

encountered exception: ProcessException: No such file or directory
  Command: /nix/store/cl4cn7h2aqj0n82pss172ygnx7vjc387-android-studio-3.1.3.0/jre/bin/java -version

#0      _ProcessImpl._runAndWait (dart:io-patch/process_patch.dart:485)
#1      _runNonInteractiveProcessSync (dart:io-patch/process_patch.dart:631)
#2      Process.runSync (dart:io-patch/process_patch.dart:66)
#3      LocalProcessManager.runSync (package:process/src/interface/local_process_manager.dart:83)
#4      AndroidStudio._init (package:flutter_tools/src/android/android_studio.dart:253)
#5      new AndroidStudio (package:flutter_tools/src/android/android_studio.dart:34)
#6      new AndroidStudio.fromHomeDot (package:flutter_tools/src/android/android_studio.dart:76)
#7      AndroidStudio._allLinuxOrWindows (package:flutter_tools/src/android/android_studio.dart:204)
#8      AndroidStudio.allInstalled (package:flutter_tools/src/android/android_studio.dart:137)
#9      AndroidStudioValidator.allValidators (package:flutter_tools/src/android/android_studio_validator.dart:20)
#10     _DefaultDoctorValidatorsProvider.validators (package:flutter_tools/src/doctor.dart:55)
#11     Doctor.validators (package:flutter_tools/src/doctor.dart:80)
#12     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:87)
#13     Doctor.diagnose (package:flutter_tools/src/doctor.dart:145)
<asynchronous suspension>
#14     _doctorText.<anonymous closure> (package:flutter_tools/runner.dart:194)
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:142)
<asynchronous suspension>
#16     _rootRun (dart:async/zone.dart:1126)
#17     _CustomZone.run (dart:async/zone.dart:1023)
#18     runZoned (dart:async/zone.dart:1501)
#19     AppContext.run (package:flutter_tools/src/base/context.dart:141)
<asynchronous suspension>
#20     _doctorText (package:flutter_tools/runner.dart:193)
<asynchronous suspension>
#21     _createLocalCrashReport (package:flutter_tools/runner.dart:171)
<asynchronous suspension>
#22     _handleToolError (package:flutter_tools/runner.dart:126)
<asynchronous suspension>
#23     run.<anonymous closure> (package:flutter_tools/runner.dart:63)
<asynchronous suspension>
#24     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:142)
<asynchronous suspension>
#25     _rootRun (dart:async/zone.dart:1126)
#26     _CustomZone.run (dart:async/zone.dart:1023)
#27     runZoned (dart:async/zone.dart:1501)
#28     AppContext.run (package:flutter_tools/src/base/context.dart:141)
<asynchronous suspension>
#29     runInContext (package:flutter_tools/src/context_runner.dart:43)
<asynchronous suspension>
#30     run (package:flutter_tools/runner.dart:50)
#31     main (package:flutter_tools/executable.dart:49)
<asynchronous suspension>
#32     main (file:///b/build/slave/Linux_Flutter_Packaging/build/archive/flutter/packages/flutter_tools/bin/flutter_tools.dart:8)
#33     _startIsolate.<anonymous closure> (dart:isolate-patch/dart:isolate/isolate_patch.dart:277)
#34     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:165)

You can set to your configuration.nix: nix.readOnlyStore = false; and normally your solution will works

Well, that isn't really a solution. I just posted this here to give someone more context whenever someone wants to spent time on this.

I'll leave my store as read-only and I'd advise against your suggestion. It will probably not do any good...

Yes that's the problem

I'm keen to help on this one - what needs to happen @andir @babariviere ?

Does anyone has an update on flutter?

Okay, I got flutter "running" with a lot of hacks. Now I will need to see, if I can put this into a derivation somehow :)

Okay, I got flutter "running" with a lot of hacks. Now I will need to see, if I can put this into a derivation somehow :)

Hello, I'm trying to run flutter on nixos, but I did'nt found how to fix it. Could you explain what you did to do it ?

Thanks @bkchr

any updates?

I'd quite like to have this, so I'll be trying to hack it together over at -> https://github.com/jmackie/flutter-nix

Any help/input welcome!

Any news on that ?

I couldn't make a working flutter derivation due to its need to write in its install directory
but i managed to get it running thanks to this (also allow to run any binary normally)
https://brianmckenna.org/blog/running_binaries_on_nixos
thought you guys might enjoy it ^
image

Well the fhs can't access the network so flutter pub get failed, the best workaround i found was to create a symlink to ld in /lib64 and now it works fine without fhs

People might be interested in the following:

I'm still working out some issues with my flutter overlay.

Was there any progress on this?

Was there any progress on this?

Well i just made a simlink to ld in /lib64 and can run the flutter executable
i'm not sure it can be patched tho as flutter tries to write to its installation directory in other to work

can you show me exactly what you did?

@trisimix it isn't the way you are supposed to do stuff in nix but here you go:

sudo mkdir /lib64;sudo ln -sf $(file -L /usr/bin/env | cut -d"," -f5 | cut -d" " -f3) /lib64/ld-linux-x86-64.so.2

then follow the install instruction there
https://flutter.dev/docs/get-started/install/linux
also you can download the android sdk from android studio and you might have to set
the ANDROID_HOME env variable to the path you downloaded the android sdk to

Also for flutter install to work you will need adb to be installed

Massive thank you. I wish there was a way we could package this.

@trisimix yeah, well you can still make a nix shell that will work too but packaging it is tougher

There might be a way to do it if you sed the source code of flutter so it tries using a lockfile that isn't in the nix store, otherwise unless you let the flutter install path to be rw which isn't a good thing to do regarding nix, you can't do it

I've had some success trying to "sed the source code of flutter so it tries using a lockfile that isn't in the nix store".

{ stdenv, fetchurl, git, curl, unzip, which, xz}:

stdenv.mkDerivation rec {
  name = "flutter";
  version = "1.9.1+hotfix.6";
  src = fetchurl {
    url = "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.9.1+hotfix.6-stable.tar.xz";
    sha256 = "066rkw16ik6izdvx24pr8hljd9nshb7bl89r25ndf7jnrq656zxn";
  };

  buildInputs = [ git curl unzip which xz ];

  phases = [ "unpackPhase" "patchPhase" "fixupPhase" "buildPhase" "installPhase" ];

  patchPhase = ''
    HOME=$PWD
    #because flutter's analytics touches home dir on every run, including the ones during build

    sed -i 's/"$PUB" upgrade/"$PUB" upgrade --offline/' ./bin/flutter
    #because flutter self updates itself every run but we dont have network in build phase

    sed -i "s/fs.file(fs.path.join(flutterRoot, 'bin', 'cache'/fs.file(fs.path.join(platform.environment['HOME'], '.cache', 'flutter'/" ./packages/flutter_tools/lib/src/cache.dart 
    #because flutter touches a lockfile every run and this cannot be in nix profile

    sed -i "s/await FlutterVersion.instance.ensureVersionFile()/\/\/&/" ./packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
    #because flutter rewrites version file every run
  '';

  fixupPhase = ''
    patchShebangs --build ./bin/
    find ./bin/ -executable -type f -exec patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \;
  '';

  buildPhase = ''
    mkdir -p $HOME/.cache/flutter

    rm ./bin/cache/flutter_tools.stamp
    rm ./bin/cache/flutter_tools.snapshot

    ./bin/flutter --version
    #rebuild flutter_tools after we deleted snapshot and applied patches

    sed -i 's/(upgrade_flutter) 3< "$PROG_NAME"/#&/' ./bin/flutter
    #disable flutter self update/fix because nix profile is read only and there is no point, also it tries to create a lockfile

    echo ${version} >> ./version
  '';

  installPhase = ''
    mkdir $out
    cp -r . $out
  '';
}

One thing to note is that the source has to be storage.googleapis.com and not a github clone. Because the flutter github clone needs additional downloads (the dart sdk, skia engine etc.) in order to be the full flutter sdk.
The files served by google on their web site are bundles and already have all these components included. And more importantly it also includes a pub-cache dir which includes a copy of every library used by the flutter tools themselves. We can then use this local cache to rebuild flutter tools in the build phase. Without accessing network.

The instructions to compile this tar package is on their wiki. But since there is no network access during the build phase, we cannot depend on the flutter tools to download its own dependencies.

After the lockfile sed, I found that there is another file called version which is written to every run.
I had to sed the source files again to comment out a single line. And we instead manually write to that file during build.

After a successful build, I installed this to my local profile and had to mkdir -p .cache/flutter on my home dir. (because I didnt know how to do this in the derivation).

flutter doctor detected android studio by itself, but crashed after it tried to get java -version in android studio's nix profile. I tried flutter doctor in android-studios terminal and it ran and complained about missing SDK. This is some nix magic that is beyond me but I'm guessing this has to do with the way android studio itself if packaged in nix. With FHSUserEnv and whatnot.

After setting ANDROID_HOME I got my first successful flutter doctor message.

Finally I tried flutter packages get and it is failing after trying to get packages.
flutter packages get --verbose tells me that the dart's pub tool is failing with a handshake exception. I'm guessing we're close and with a correct patch to flutters dart or pub, it will actually work.

Flutter's dart lives in /bin/cache/dart-sdk/bin/dart if anyone knows how to fix it.

About that dart handshake exception, not sure if it is relevant, but I had to add

export DART_VM_OPTIONS=--root-certs-file=/etc/ssl/certs/ca-certificates.crt

in my FHS shell env for flutter to work.

Thanks! I put it in my .profile and it worked.
But now it looks like flutters pub tries to download to its install dir's .pub-cache and fails because its read only.

After setting the PUB_CACHE environment variable flutter packages get works!


Updated

{ stdenv, fetchurl, git, makeWrapper}:

stdenv.mkDerivation rec {
  name = "flutter";
  version = "1.9.1+hotfix.6";
  src = fetchurl {
    url = "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.9.1+hotfix.6-stable.tar.xz";
    sha256 = "066rkw16ik6izdvx24pr8hljd9nshb7bl89r25ndf7jnrq656zxn";
  };

  buildInputs = [ git makeWrapper ];

  patchPhase = ''
    sed -i 's/"$PUB" upgrade/"$PUB" upgrade --offline/' ./bin/flutter
    #because flutter self updates itself every run but we dont have network in build phase

    sed -i "s/fs.file(fs.path.join(flutterRoot, 'bin', 'cache'/fs.file(fs.path.join(platform.environment['HOME'], '.cache', 'flutter'/" ./packages/flutter_tools/lib/src/cache.dart 
    #because flutter touches a lockfile every run and this cannot be in nix profile

    sed -i "s/await FlutterVersion.instance.ensureVersionFile()/\/\/&/" ./packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
    #because flutter rewrites version file every run

    patchShebangs --build ./bin/
    find ./bin/ -executable -type f -exec patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \;
  '';

  buildPhase = ''
    HOME=$PWD
    #because flutter's analytics touches home dir on every run, including the ones during build

    rm ./bin/cache/flutter_tools.stamp
    rm ./bin/cache/flutter_tools.snapshot

    mkdir -p $HOME/.cache/flutter
    ./bin/flutter --version
    #rebuild flutter_tools after we deleted snapshot and applied patches

    sed -i 's/(upgrade_flutter) 3< "$PROG_NAME"/#&/' ./bin/flutter
    #disable flutter self update/fix because nix profile is read only and there is no point, also it tries to create a lockfile

    echo ${version} >> ./version

    rm -r ./.pub-cache
  '';

  installPhase = ''
    mkdir $out
    cp -r . $out

    wrapProgram $out/bin/cache/dart-sdk/bin/pub --set DART_VM_OPTIONS "--root-certs-file=/etc/ssl/certs/ca-certificates.crt"
    wrapProgram $out/bin/flutter --set PUB_CACHE "\$HOME/.cache/pub"
  '';
}

Looks like dependencies other than git are not necessary. And we can remove the included .pub-cache after build to save a bit of disk space.
For setting DART_VM_OPTIONS=--root-certs-file=/etc/ssl/certs/ca-certificates.crt and PUB_CACHE=$HOME/.cache/pub we can use wrapProgram instead.
As for the lock-file directory I wonder if we can use /tmp ?

Maybe $TMPDIR that many nix derivations use on the build/install phase?

Problem is we need a writable directory after install. Flutter needs to write to its lockfile every time it is run. $TMPDIR would work during build, but then we'd need to patch the source again to change it somewhere else.
I'm using $HOME/.cache/flutter but it needs to be created manually after install which isnt very nice. Flutter source code could be modified to create the cache dir if it doesnt exist. But I'm trying to keep the patches to a minimum.

@teal77 is there anything we could propose to upstream that they might accept? Maybe we could open an issue if one doesn't exist? Some projects have been fairly open to contributions from nixos members.

3 things for upstream. (That I know of so far).

  • Have lockfile be written to somewhere else. (Could be /tmp, XDG_RUNTIME_DIR or XDG_HOME_CACHE)
  • Have a config to disable writing to version file on every command. For this they could check the --no-version-check argument which already exists.
  • Have a config to disable the self update function in the flutter bash script.

The last one can be easily patched out by us because it's just commenting out a function call in the bash script. The first two require patching the source code and rebuilding the flutter tool.

@teal77 do you have the motivation/time/energy to create a PR upstream?

Not at the moment, I'm still trying to get the derivation working with XDG_RUNTIME_DIR. (and it isn't working for some reason).
As for PR, keep in mind, they have to support windows and macos with the exact same release so they might not accept linux specific patches. ie Pointing lockfile to /tmp or XDG dirs.

By the way, I believe the patches we did are acceptable for the moment. It's only 4 changes. Two of which are commenting out a line. Is there any reason to bother upstream with this?

I gave up on XDG_RUNTIME_DIR for lockfile. Something in nix build keeps setting that variable to empty. And since we run the flutter command in build, It needs to be set.


Updated

{ stdenv, fetchurl, git, makeWrapper}:

stdenv.mkDerivation rec {
  name = "flutter";
  version = "1.9.1+hotfix.6";
  src = fetchurl {
    url = "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.9.1+hotfix.6-stable.tar.xz";
    sha256 = "066rkw16ik6izdvx24pr8hljd9nshb7bl89r25ndf7jnrq656zxn";
  };

  buildInputs = [ git makeWrapper ];

  patchPhase = ''
    sed -i 's/"$PUB" upgrade/"$PUB" upgrade --offline/' ./bin/flutter
    #because flutter self updates itself every run but we dont have network in build phase

    sed -i "s/fs.file(fs.path.join(flutterRoot, 'bin', 'cache', 'lockfile'/fs.file(fs.path.join('\/tmp', 'flutter-${version}-lockfile'/" ./packages/flutter_tools/lib/src/cache.dart 
    #because flutter touches a lockfile every run and this cannot be in nix profile

    sed -i "s/await FlutterVersion.instance.ensureVersionFile()/\/\/&/" ./packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
    #because flutter rewrites version file every run

    patchShebangs --build ./bin/
    find ./bin/ -executable -type f -exec patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \;
  '';

  buildPhase = ''
    HOME=$PWD
    #because flutter's analytics touches home dir on every run, including the ones during build

    rm ./bin/cache/flutter_tools.stamp
    rm ./bin/cache/flutter_tools.snapshot

    ./bin/flutter --version
    #rebuild flutter_tools after we deleted snapshot and applied patches

    sed -i 's/(upgrade_flutter) 3< "$PROG_NAME"/#&/' ./bin/flutter
    #disable flutter self update/fix because nix profile is read only and there is no point, also it tries to create a lockfile

    echo ${version} >> ./version

    rm -r ./.pub-cache
  '';

  installPhase = ''
    mkdir $out
    cp -r . $out

    wrapProgram $out/bin/cache/dart-sdk/bin/pub --set DART_VM_OPTIONS "--root-certs-file=/etc/ssl/certs/ca-certificates.crt"
    wrapProgram $out/bin/flutter --set-default PUB_CACHE "\$HOME/.cache/pub" --add-flags "--no-version-check"
    #disable flutters version check because it writes to install dir
  '';
}

Other than that, we need to pass the --no-version-check flag to flutter command. Because it checks version once in a while and tries to write into install dir.

To recap. The problems with this derivation are.

  • Crash outside android-studio terminal. Because flutter auto detects android studio install and tries to get its bundled java version.
  • Needs ANDROID_HOME set. (Could this be solved by adding android sdk as a dependency and setting it in wrapProgram?)

OK I see your point about upstream patches. Always nice upstream, but sometimes not worth it. Setting ANDROID_HOME with wrapProgram sounds reasonable. Will setting ANDROID_HOME fix the crash?

Will setting ANDROID_HOME fix the crash?

Probably not, their code uses the .AndroidStudioX.Y dirs in user's home to detect android studio (here)
Looks like there is a file $HOME/.AndroidStudioX.Y/system/.home which points to android studio install dir. Flutter is using that to find the java binary.

On a side note, now that I look in there, there is a config called android-studio-dir which can also be used to supply android studio install. There's also a config android-sdk which supersedes ANDROID_HOME.

As for upstream patching, moving lockfile out of install dir is reasonable. But I don't know how to ask them about the version file in install root. Maybe open separate issues when we're ready.

Found a relevant upstream issue. https://github.com/flutter/flutter/issues/16898

@teal77 thank you for your efforts so far! If there is any specific support you need to continue with this please mention here and we can try to track the right people to help.

I must admit, I don't know enough nix to continue with this. Apart from the issues mentioned above.. We built one flutter version. How would you package other versions? And what if those other versions require different patches? Or same patch in a different place?
I've seen other packages ship different versions using callPackage but it all looks like magic to me.
https://nixos.org/nixpkgs/manual/#sec-versioning suggests to add all versions to all-packages.nix which doesn't sound right?
And I'm assuming users would have to use nix-shell to use multiple flutter versions in different projects. But again, I haven't used nix shell before so I don't know anything about this use case.

Oh and by the way, I'm pretty sure the flutter doctor crash outside android studio is a bug in upstream.
https://github.com/flutter/flutter/blob/e58dc16d7bec7199190f1408667e24e38328cc3b/packages/flutter_tools/lib/src/android/android_studio.dart#L299
They do have failure case for failing to detect java version. So a try catch block around that line should make it fail gracefully.
The flutter tool would then look at JAVA_HOME (among other things) to find the java executable. (refer)

you only have to put latest version @teal77. User's can pin nixpkgs to get a specific version of a package

I'm sorry to ask, I'm kind of new to the Nix thing, but since the Flutter nix package is still in development, is there a way to use Flutter on NixOS without packaging it first?

@froehlichA Just go a little up and i explained how to do so

For those who want an hacky way to install flutter without linking /lib64 (this is a personal preference), I have created a small script to patch flutter. The only inconvenient is you have to run it every time you upgrade flutter.

Here is the script:

{config, lib, pkgs, ...}:
let
  flutterDir = "$HOME/flutter";
  patchFlutter = pkgs.writeShellScriptBin "patch-flutter" ''
    isScript() {
        local fn="$1"
        local fd
        local magic
        exec {fd}< "$fn"
        read -r -n 2 -u "$fd" magic
        exec {fd}<&-
        if [[ "$magic" =~ \#! ]]; then return 0; else return 1; fi
    }

    stopNest() { true; }

    source ${<nixpkgs/pkgs/build-support/setup-hooks/patch-shebangs.sh>}
    patchShebangs --build ${flutterDir}/bin/
    find ${flutterDir}/bin/ -executable -type f -exec ${pkgs.patchelf}/bin/patchelf --set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 {} \;
  '';
in {
  environment.systemPackages = [ patchFlutter ]; # install on your system
}

To use it, just run:


This script assume you have flutter installed at $HOME/flutter but you can change it by modifying flutterDir.

For first install:

# unpack flutter as described in Flutter Install
tar xf flutter_*.tar.xz
patch-flutter
# export PATH to make flutter available globally
flutter doctor

You also have to export DART_VM_OPTIONS as explained above:

export DART_VM_OPTIONS=--root-certs-file=/etc/ssl/certs/ca-certificates.crt

Why not just package this script? It would solve everything.

you could even make a wrapper around flutter so that it runs that script before the first time

I will try making a wrapper, but I have to find a fix for adb first

Hello, I have made a PR with a working example of flutter. There is still a few missing things (like libimobiledevice and probably flutter web).

Other than that, it works with Android SDK downloaded from Android Studio, and it will detect if you have android studio installed or not.

You can install it via nix-env:

nix-env -iA flutter -f  https://github.com/babariviere/nixpkgs/tarball/flutter-init 

or in nix-build / nix-shell / nixos-rebuild with:

flutter = (import (builtins.fetchTarball
    "https://github.com/babariviere/nixpkgs/archive/flutter-init.tar.gz") {}).flutter;

You can also use beta or dev channels by replacing flutter with:

  • flutterPackages.beta
  • flutterPackages.dev

If you have any issue, don't hesitate to comment the PR. I will try to fix them ASAP.

Small update: you can now build for web and else. I have fixed it (for those who are interested).

I came across this issue and ran into more issues, especially because the nixos dart version is not compatible with the flutter version.

For anyone interested, I was able to successfully build a small flutter app using this default.nix:
```nix
{ }:

let

projectName = "MyApp";

pkgs = import { };
flutterPkgs = (import (builtins.fetchTarball "https://github.com/babariviere/nixpkgs/archive/flutter-init.tar.gz") {});
dartPkgs = (import (builtins.fetchTarball "https://github.com/GRBurst/nixpkgs/archive/dart.tar.gz") {});
in
pkgs.stdenv.mkDerivation {
name = "${projectName}";
buildInputs = with pkgs; [
flutterPkgs.flutter
dartPkgs.dart
android-studio
git
];

shellHook=''
  echo -e "\e[0;32mWelcome to ${projectName} Development\e[m"
'';

}

For those using android-studio: Choose flutterPkgs.flutter.unwrapped as path for the flutter sdk. You can e.g. output it in the shell hook:

    shellHook=''
      echo -e "\e[0;32mWelcome to ${projectName} Development\e[m"
      echo -e "Path to the Flutter SDK to enter in android-studio:"
      echo -e "\e[0;34m${flutterPackages.flutter.unwrapped}\e[m"

      echo -e "It is advised to add \e[1;34mprograms.adb.enable = true;\e[m to your nix configuration"
      echo -e "Furthermore, add your user to the \e[1;34madbusers\e[m group."
    '';

Merged in master :tada:

I can now successfully run flutter doctor but there is no way for me the accept the android studio license.

@rowanG077 did you try flutter doctor --android-licenses? there was a discussion about that topic in the corresponding pr #76420

this is not working on master anymore for me. flutter doctor --android-licenses doesnt work either

@arianvp What error do your get? There's been an update recently, maybe that broke something?

$ flutter doctor --android-licenses
Error: Unknown argument --licenses
Usage: 
  sdkmanager [--uninstall] [<common args>] \
    [--package_file <package-file>] [<packages>...]
  sdkmanager --update [<common args>]
  sdkmanager --list [<common args>]

In its first form, installs, or uninstalls, or updates packages.
    <package> is a sdk-style path (e.g. "build-tools;23.0.0" or 
             "platforms;android-23").
    <package-file> is a text file where each line is a sdk-style path
                   of a package to install or uninstall.
    Multiple --package_file arguments may be specified in combination
     with explicit paths.
In its second form (with --update), currently installed packages are
    updated to the latest version.
In its third form, all installed and available packages are printed out.


Was this page helpful?
0 / 5 - 0 ratings

Related issues

spacekitteh picture spacekitteh  路  3Comments

ghost picture ghost  路  3Comments

yawnt picture yawnt  路  3Comments

retrry picture retrry  路  3Comments

sid-kap picture sid-kap  路  3Comments