Locally deploy phoenix liveview using nix

Good to hear you got it working! I have gone through a similar process myself :wink:.

I implemented the SystemD services in three different parts for deployment on my server :

  • seed service (runs only once),
  • migration service (runs after the seed service and is restarted whenever the web service is restarted),
  • web service (depends on the migration service to exits successfully).

If you want, you can structure the NixOS module in a way that you setup the database, nginx proxy, ssl from one configuration.

In my NixOS config I can do the following:

services.my-project = {
  prod = {
    branch = "master";
    commit = "commit ref";
    port = "4000";
    host = "example.com";
  };
  staging = {
    branch = "dev";
    commit = "commit ref on dev branch";
    port = "4001";
    host = "staging.example.com";
  };
};

Any branch can be used to create a domain name with minimal configuration effort. Database names are just the name of the app with the branch as a suffix (maybe I will allow a explicit suffix in the config in the future). Having to specify the port is something I want to get rid of and just use Unix sockets instead. Using Systemd socket should allow for zero-downtime deployments, but there is still work to be done with regard to gen_tcp.

If you want to see how it works, I can post the aforementioned module in this thread.