How to setup flutter development on MacOS M-Processors?

I don’t understand how I shall setup a flutter development environment using nix.
I am running on an Apple-M-Processor (system = “aarch64-darwin”) and have a system-wide nix setup, using flakes and home-manager.
I started with my Mac from scratch and so far installed & configured everything using Nix (a global profile).

I started adding flutter dependencies, mainly the Android SDK, to this configuration. I wanted to have all configuration in a separate file, flutter.nix. Doing so I got the impression, that the way described in the nix wiki (Nixpkgs Reference Manual) doesn’t work - seems like aarch64-darwin is not supported (at least that was the error message where I stopped). So I used android-nixpkgs (GitHub - tadfisher/android-nixpkgs: Nix-packaged Android SDK). But strangely nothing got installed, not did I get any error message.

After digging deep in the web, I got the impression that I am doing it wrong - and that I am supposed to configure this project specific. While I am the only developer, using only one machine, I want to have a reproducible setup. And binding this to the project makes sense - even though I am working on only one project right now - I might want to reproduce its state at a specific time in the future … ok.

But how to do that? I trieft to use the setup from android-nixpgks with flakes and home-manager, with aa flake.nix in the project’s root. But nix develop complains, that my flake “does not provide attribute ‘devShells.aarch64-darwin.default’, ‘devShell.aarch64-darwin’, ‘packages.aarch64-darwin.default’ or ‘defaultPackage.aarch64-darwin’” … and googling for that suggest to re-install nix!

So, here is my confusion, and my ask for help (and many thanks for reading so far!):

How can I setup a flake.nix for flutter development with codium the most pragmatic way?

What do I have to use, given my setup? E.g. home-manager? Or is that optional? Can I inherit from my global nix profile, like the currentSystem? Or is it better and not much of an overhead to use flakeUtils?

I want to keep it as simple as possible (and hope that the answer will help others like me :slight_smile: ):

  • use a flake, as I am using flakes in my global setup as well
  • using the “standard” way of installing the android sdk, which works for aarch64-darwin
  • install emulator and profiles via nix, so that I don’t have to install android-studio

Many thanks!

if you want to set up a project, so that all the dependencies are in your dev-shell, you don’t need to use flakes. A shell.nix with a call to pkgs.mkShell. But you can also set up a flake. Here I use the flake-utils to build a dev shell for every system.

   description = "dev flake";

inputs = {
   nixpkgs.url      = "github:NixOS/nixpkgs/nixos-unstable";
   flake-utils.url  = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils, ... }:
   flake-utils.lib.eachDefaultSystem (system:
         devShells.default = nixpkgs.legacyPackages.${system}.mkShell {
            name = "devshell";
            buildInputs = [
                # your dev packages

            shellHook = ''
               # export VAR="hey :)"

As you can see from nix flake show there is now a dev shell for every system

    │   └───default omitted (use '--all-systems' to show)
    │   └───default omitted (use '--all-systems' to show)
    │   └───default omitted (use '--all-systems' to show)
        └───default: development environment 'devshell'

The android-tools package should work on aarch64-darwin.

I personally recommend using this with because that enables you to automatically enter the dev environment when you change into the projects directory.

I hope that was helpful :]

Thanks a lot! Yes, that helped a lot. Turns out I had a small mistake, but thanks to you I actually understand what the lines are doing, and that this is disconnected from my global nix profile.
Thanks for the direnv hint!

1 Like