How do you deploy nix derivation and why?

As there are many options out there, I am wondering how do the Nix guru deploy their derivation, and why.

Right now I have some idea of the flow of using Nix to deploy to a non-NixOS machine(using nix in Dockerfile, and the rest is the same with Docker deployment flow), but does a better alternative exists for Nix? What is the best deployment flow and tools in your opinion, given you cannot pick a machine with NixOS to deploy to?

If you have bare metal instances, then you can use nixops, and you can deploy both packages and services.

If you have an existing docker workflow, you can export a docker file using pkgs.dockerTools

Thanks you for your reply. dockerTools looks promising to me. So I guess I use Nix derivation to build my project, pkgs.dockerTools to create the image. But if I need to start an Nginx reverse proxy service in my target VPS(non-bare metal and not NixOS), is the rest out of control of Nix?

But if I need to start an Nginx reverse proxy service in my target VPS(non-bare metal and not NixOS), is the rest out of control of Nix?

That sounds like a really common use case for a vps, I’m sure that workflow wouldn’t be that difficult without nix.

I am wondering how do the Nix guru deploy their derivation, and why.

I would use the official nixos ami’s if I’m deploying to aws. Install NixOS on Amazon EC2 - NixOS Wiki.

For azure you can generate your own images, but I haven’t tested those waters in over a year.

What is the best deployment flow and tools in your opinion, given you cannot pick a machine with NixOS to deploy to?

Depends on the platform, already available tools, and whether you can launch your own images. You can create your own vm images with nix as well. If the platform has good support for docker, I would just ship docker images.

1 Like

Thanks! Your advice is really helpful because I really don’t have much experience in deployment.

This is my current plan of attack after some more research. I guess I will just pay a little more for less hassle:

  • get a hosting that has NixOS

  • configure nginx with Nix as reverse proxy(I am not sure what other alternative I have, ansible? terraform?)

  • use docker-compose for managing my programs, and route traffic to it through nginx