Nixpkgs: Should dart and cache be made available when installing Flutter?

Created on 21 Sep 2020  路  22Comments  路  Source: NixOS/nixpkgs

Describe the bug
I have installed flutter using Nix, everything related to flutter seems to be working great. Having some issues though when it comes to editor integration (I'm trying to set up Emacs with lsp-dart) . The problem seems to be that lsp-dart wants to use the dart version that comes with the flutter installation. Usually it can be found in $FLUTTER_ROOT/bin/dart and $FLUTTER_ROOT/bin/cache. I have found a solution where i edited flutter.nix to create symlinks to flutter unwrapped dir, where dart and cache is available. This doesn't integrate well with lsp-dart, but by setting the flutter sdk directory manually to the unwrapped dir in /nix/store I got it working. This will however require me to update my Emacs config whenever nix is changed.

I considered writing an overlay to take care of this, but as I'm pretty new to both nix and flutter I couldn't figure out where to begin. Therefore I decided to ask, how do you deal with dart and dart_analysis_server? Should dart and cache directory be made available somehow?

Any help would be greatly appreciated!

Notify maintainers
@babariviere
@ericdallo

Metadata

  • system: "x86_64-linux"
  • host os: Linux 5.4.0-47-generic, Ubuntu, 20.04.1 LTS (Focal Fossa)
  • multi-user?: no
  • sandbox: yes
  • version: nix-env (Nix) 2.3.7
  • channels(storvik): "home-manager, nixpkgs-21.03pre243111.51428e8d382"
  • nixpkgs: /home/storvik/.nix-defexpr/channels/nixpkgs
bug

Most helpful comment

Great work @ericdallo ! Thank you very much 馃コ

All 22 comments

Yeah, I already asked myself that, IMO a good way to solve that would be the flutter derivation use the dart derivation and creates a cache folder with the dart bin inside.
But for your issue with lsp-dart, you can set lsp-dart-sdk-dir to your dart derivation like here.

Ahh, thanks! I was wondering if I could solve it by installing dart separately, but wasn't sure it was recommended as dart version may differ from dart used by Flutter. I also have some issues when using flutter-dev as lsp-dart looks for flutter. Any workarounds here? Maybe it's better if lsp-dart adds a defcustom for customizing flutter executable name?

I see that you are the maintainer of lsp-dart. Great work, much appreciated!

Thanks :)
lsp-dart already have these variables to customize, you can (setq lsp-dart-sdk-dir "your-dart-sdk") and (setq lsp-dart-flutter-sdk-dir "flutter-sdk-dir"), but I think the issue here is that the nix flutter derivation, does not include the dart sdk under bin/cache/dart-sdk, I'll try to open a PR adding the dart-derivation under this path for the flutter derivation, this should solve most problems, what do you think?

I agree, this would be a good solution when it comes to getting lsp-dart to use the same dart version as flutter.

Somehow related issue is when using the flutter-dev and flutter-beta package in nix. The lsp-dart-flutter-command in lsp-dart looks for an executable called flutter, and does not allow the user to configure this. This means that even if I specify lsp-dart-flutter-sdk-dir it won't find flutter, and an error message is displayed when opening a flutter project.

[LSP Dart] Flutter command not found in path

This is however more related to lsp-dart, then nix, so maybe I should open an issue there instead? I think the simplest solution would be to add an option to customize flutter binary name in lsp-dart. This way one could easily jump between using flutter, flutter-beta and flutter-dev in different projects, for example using .dir-locals.el.

Yeah, maybe flutter recent releases changed the binary path from flutter sdk, currently lsp-dart uses bin/flutter.
But you can open a lsp-dart issue to track it there :)

Thanks! Should we keep this open until you find a way to include the dart derivation for the flutter derivation or should we just close it?

I think so, I think adding dart to flutter is something to improve on nix side too and I intend to do that soon :)

@ericdallo Don't know if you have read this blog post, but it seems like Flutter and Dart are changing some things with it's newest version. Flutter 1.22 includes Dart 2.10 and a new dart CLI tool. May be worth looking into if you intended to change the Flutter derivation :-)

Thanks for the heads up @storvik, yeah, this will certainly need to do some changes

Looks good @ericdallo, great work 馃憦 Closing this.

Glad to see that you updated Flutter too. Out of curiosity, how much time does it usually take for changes to reach nixpkgs unstable?

@storvik thanks :)
We still need to get the PR merged but for my experience, after the there merge take some days to be available to unstable channel.
What I do for instantly use a derivation from master is add this overlay, then I can use it this way

Thanks for the tip, very useful! I was actually looking for a way to use derivations from master branch directly.

A dirty little workaround until the PR makes it to unstable, if you want to use niv (which I picked up from https://github.com/babariviere/flutter-nix-hello-world):
add ericdallo's PR branch to niv:
niv add ericdallo/nixpkgs -n nixpkgs-flutter -b add-dart-to-flutter
and then use nixpkgs-flutter.flutter.stable in your shell.nix:

{ sources ? import ./nix/sources.nix }:

let
  pkgs = import sources.nixpkgs { config.android_sdk.accept_license = true;};
  flPkg = import sources.nixpkgs-flutter {};
  android = pkgs.callPackage ./nix/android.nix { };
in pkgs.mkShell {
  buildInputs = with pkgs; [
    # from pkgs
    flPkg.flutter.stable
    flutter
    jdk
    niv
    dart
    #from ./nix/*
    android.platform-tools ];

  ANDROID_HOME = "${android.androidsdk}/libexec/android-sdk";
  JAVA_HOME = pkgs.jdk;
  ANDROID_AVD_HOME = (toString ./.) + "/.android/avd";
}

I'm running into a new issue now though: flutter says that it cannot run adb
Unable to run "adb", check your Android SDK installation and ANDROID_SDK_ROOT environment variable: /nix/store/8axzrmsm5c2mnckdm581r23nyfj4g9m7-androidsdk/libexec/android-sdk/platform-tools/adb

even though it's there:

/nix/store/8axzrmsm5c2mnckdm581r23nyfj4g9m7-androidsdk/libexec/android-sdk/platform-tools/adb --version
Android Debug Bridge version 1.0.41
Version 29.0.6-6198805
Installed as /nix/store/ypvhjd74az2dm51zcwvs41y5jfnpy6h6-platform-tools-29.0.6/libexec/android-sdk/platform-tools/adb

Could it be a wrong adb version?
At this point I'm seriously considering just setting up a VM with android studio for the time being :sweat_smile: I've been trying to setup my environment since friday :/

This should work as said here

what could even be the problem when flutter says unable to run a binary file that I can execute just fine from the shell?
I'm pretty new to nixos btw :p

I have just updated my config to use the pull request. flutter run works without any issues for me. Note that I'm running Nix on my Ubuntu box, and everything related to Android tools is downloaded through Android Studio and lies within $home/Android/.

However, @ericdallo, it seems like Dart is failing. For instance running dart help gives me the error:

Unable to find DartDev snapshot.

It this something you bumped into when working on this PR?

As far as I recall no @storvik :thinking:

After removing everything in (use-package :config ...) in my Emacs config everything seems to be working @ericdallo. Thanks for the PR!

@storvik https://github.com/NixOS/nixpkgs/pull/99920 is merged, now nix flutter will have the corresponding dart sdk built-in :)

Great work @ericdallo ! Thank you very much 馃コ

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yawnt picture yawnt  路  3Comments

copumpkin picture copumpkin  路  3Comments

teto picture teto  路  3Comments

sid-kap picture sid-kap  路  3Comments

lverns picture lverns  路  3Comments