Manual Flutter Install NixOS, Override Nixpkgs Flutter Version?

There are a handful of posts on the topic of getting flutter working which is where I am coming from: this site, the nix wiki, github and stack overflow. I think the stack overflow linked flake file was closest to working for me. For all of these, I create a flake.nix file, then run nix develop, get dropped into a shell, and attempt to flutter run my current work project.

I’ve tried quite a few different flake environments. The problem is it seems that even when I can get a new flutter app built (from running flutter create), I haven’t been able to find a flake that works on my current project. We keep things up to date where I work, and even the unstable nixpkgs branch is too out of date for my current project, giving me a message like:

Exception: [!] Your app is using an unsupported Gradle project. To fix this problem, create a new project by running `flutter create -t app <app-directory>`
and then move the dart code, assets and pubspec.yaml to the new project.

We recently updated our android build with this exact method, but now it seems the new one is not backwards compatible. Also, there were some std lib changes in a recent flutter version that we have fixed in the app, but all of the flutter versions provided from nix aren’t up to date with this change (namely the PopScope widget). Is there a way I can create a nix shell with all of the android deps and some FHS env for flutter, but manage my flutter install myself? Flutter has good tooling and versioning imo, so if I can get around the nix method of flutter versions I think I can avoid some head aches around this (But maybe introduce some that are much worse… idk).

I installed the flutter binary, added it to my path with a basic android shell installed, but I got an error that led me to the nixos wiki on packaging binaries. I assume there is a linking error, so if there is a way to run in an FHS env that may fix it?

Happy to post more info or link to flakes I’ve tried, sorry I’m still new to nixos but I think I grasp the concepts so I’m not totally helpless :sweat_smile:

Thanks in advance!

I found this article, I’m going to try and see if I can create an environment to run a local flutter binary with nix-ld or steam-run perhaps, seems like that is maybe what I am looking for…

Still no solution on this. I tried creating a flake.nix file, running nix develop and using the latest downloaded version of flutter, but I only ran into problems. Tried using nix-ld but I cannot understand what is going on with the documentation provided. I realized that possibly a simpler method is to just create an override of some sort on the flutter package and update the version it installs to latest? Does anyone know how that could be done?

nixpkgs, at its core, it’s a collection of nix scripts needed to get and compile packages
There are many packages that are actually updated automatically, you can create your own package definition.
Dev envs are, simplifying, just throwing a bunch of packages together into a session path, so what you’re looking for is a nix file that allows you to build and install flutter, either from nix pkgs or made by yourself

This said, you should checkout the latest commit at nixpkgs repo as it’s constanlty updated, take into account that channels are a collection of packages taken from a commit from nix pkgs, so even if you are on unstable it might not be on the latest nix pkgs commit

If Im using flakes to create the dev environment, I found this post about pinning to a specific commit:

But using the latest commit on unstable (which matches master’s flutter at time of writing) its the same version. I tried looking at the flutter package definition but it is not clear to me how the version of flutter is decided. Is this the approach you mean?
nix flutter pkg

It seems that versioning occurs at this file. https://github.com/NixOS/nixpkgs/blob/14cb8882a6302acc82407574c4a49b68716bf5c6/pkgs/development/compilers/flutter/default.nix

If you’re not sure on what’s going on you could probably email any of the mantainers and request and update.

image