fly-apps / nix-base

Nix overlays for supporting Nix deployments on Fly.io
16 stars 4 forks source link

This repo houses Nix modules for simplifying shared development environments and production deployments based purely on Nix. Today, this repo contains modules targetting Rails applications. The goal is to extend it for other runtimes, frameworks and deployment scenarios.

Currently, the module system is capable of taking a standard Rails application from development to production using only Nix conventions and a few wrapper shell scripts. A prerequisite for using it in development is having installed Nix itself. You can check out the sample Rails application that's setup to use these modules.

This guide assumes you generally understand what Nix is and why it's useful. We'll be writing about that and linking to that writing here.

Note that nothing here is tailored for Fly.io infrastruture, though flyctl will integrate it for running builds on remote builder VMs. We encourage comments and collaboration from others interested in Nix-based deployments!

Usage

For usage instructions, check out the Rails sample app.

Features

The module system offers these features:

You can see how these options are used in the Rails sample project default.nix.

Rails support

These modules should work with most Rails apps that use rails asset:precompile for asset compilation.

Most pure-Ruby gems should work fine. Most popular Gems requiring binary builds should work, but we don't know if they're all covered here. For special cases we've added a Nix overlay.

Caching builds for reuse

One nix killer feature is the ability to cache any build in a remote store as a simple tarball. We've setup a binary cache on cachix.org for storing our custom Ruby builds, and perhaps gems and other useful things.

A starting point for this is in this Github Actions workflow.

Developing on nix-base

If your project is in the same directory as nix-base:

 $ ls
 my-project
 nix-base
 $ cd my-project
 $ nix-build --arg fly-base '(import ../nix-base {})' [...]

Future plans

Things we'd like to do next: