BACK TO THE HOMEPAGE

Mar 10, 2025 2 min read

Nix Firebase

A quick blog post on using nix with Firebase.

Getting Firebase to work with Nix just requires a few package to get going 😂 If you have worked with Firebase, you know setting up the environment can be royal pain. Never fear, Nix can help with getting you ready to start developing locally.

Firebase provides a fantastic suite of tools for building modern web and mobile applications. Nix enhances this by providing a declarative and reproducible way to manage your deployment pipeline. Use Nix to define your Firebase project dependencies, configuration files, and deployment scripts, ensuring that your applications are always deployed in a consistent and reliable manner. This combination simplifies the process of managing complex Firebase projects and ensures that your applications are always deployed in a predictable and reproducible way.

Firebase Packages

Firebase uses nodejs for its development environment. However it also requires additional packages depending on which Firebase tools you require.

  1. Lets create a shell.nix script
with import <nixpkgs> {};

pkgs.mkShell {
  name = "firebase-dev";

  nativeBuildInputs = with pkgs; [
    nodejs_20                    # Nodejs 20
    nodePackages_latest.webpack  # Webpack support
    firebase-tools               # Firebase Tools
    cacert                       # Support certificates
  ];

  LANGUAGE = "Firebase";
  VERSION  = "firebase --version";

  shellHook = ''
    # Optional: Script environment start up
    echo "Welcome to $LANGUAGE Development Environment"
    $VERSION
  '';
}

The above script will still give us a firebase development environment complete with a nice message to let us know the shell is running.

In general Firebase will require both nodejs,cacert and firebase-tools. The additional of webpack is optional.

  1. Run a Pure environment

Remember a pure environment tries to ignore the existing host configuration 😂 Nix will automatically look for the file shell.nix so you dont need to added this parameter 🥰

nix-shell --pure

Expected Output:

Welcome to Firebase Development Environment
13.35.1

Awesome, Firebase is configured and ready to go!

  1. Exit the Nix Shell
exit

Nice we now have a super quick and easy way to run Firebase on a Nix machine. Nix will take care of the machine config and setup.