Building Flutter Web apps on NixOS

Hi all,

I’m trying to build a Flutter Web app. I have an existing flake.nix that works great for Android development (combined with some local adb setup in my configuration.nix):

{
  description = "A Flutter app";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flutter-nix.url = "github:ilkecan/flutter-nix";
    flutter-nix.inputs.flake-utils.follows = "flake-utils";
  };
  outputs = { self, nixpkgs, flake-utils, flutter-nix }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
        config = {
          android_sdk.accept_license = true;
          allowUnfree = true;
        };
      };

      buildToolsVersion = "30.0.3";
      androidComposition = pkgs.androidenv.composeAndroidPackages {
        buildToolsVersions = [ buildToolsVersion "28.0.3" ];
        platformVersions = [ "31" "28" ];
        abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
      };
      androidSdk = androidComposition.androidsdk;


    in
    {

      devShells.${system}.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          flutter
          dart
          androidSdk
          jdk11
        ];
      };
    };
}

If I plug my phone in and run flutter run, it works fine. If I unplug my phone, I get given the choice between building for linux or web. If I choose web, I get the following error:

Launching lib/main.dart on Chrome in debug mode...
Error: Unable to read the 'libraries.json' specification file:
  "include" path 'file:///home/cameron/.cache/flutter/dart-sdk/lib/libraries.json' could not be read: FileSystemException(uri=file:///home/cameron/.cache/flutter/dart-sdk/lib/libraries.json; message=No such file or directory).
Waiting for connection from debug service on Chrome...        

I’m aware that Flutter doesn’t play nicely with Nix, but I’m not sure how to get this to work. Flutter has almost no documentation on libraries.json. Has anyone got this to work?

1 Like

No, stuck on the same issue …
Did you ever get this to work?

Unfortunately not - never got past the libraries.json issue, ended up going back to my arch partition for flutter web :confused:

You have to add CHROME_EXECUTABLE = pkgs.chromedriver + "/bin/chromedriver"; to the pkgs.mkShell. That should look like this:

{

      devShells.${system}.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          flutter
          dart
          androidSdk
          jdk11
        ];
        CHROME_EXECUTABLE = pkgs.chromedriver + "/bin/chromedriver";
      };
    };

If you want to start the process you have to have the Package google-chrome installed on your system. There is a other option you can run it in server mode with this command flutter run --release -d web-server.

1 Like