3 ms·
I use NixOS, which allows you to define machines declaratively. To the points that he raises: How do you deploy your application? Just rsync it to the server?
by danieldk 8y ago
I use NixOS, which allows you to define machines declaratively. To the points that he raises:
How do you deploy your application? Just rsync it to the server?
Define an overlay for your application. For a typical application, this is just a few lines of code with stdenv.
What about dependencies? If you use python or ruby you're going to have to install them on the server. Do you intend to just run the commands manually?
If you have an overlay for your applications, you can specify dependencies in the derivation of your application. Even though these are not web apps (I primarily work on local applications), I have derivations for some of my applications, so that I can install them on every machine with little effort. Two examples:
https://github.com/danieldk/nix-home/blob/master/overlays/30-alpinocorpus.nix https://github.com/danieldk/nix-home/blob/master/overlays/30...
https://github.com/danieldk/nix-home/blob/master/overlays/20-finalfrontier.nix https://github.com/danieldk/nix-home/blob/master/overlays/20...
If I want to develop one of the applications, say alpinocorpus, I can just drop in a shell with all the dependencies (cmake, boost, Berkeley DB XML, etc.) available:
nix-shell '<nixpkgs>' -A alpinocorpus
When you exit the shell, you are again in your usual environment. Another option is to create a default.nix file in a project directory and use direnv to automatically load the environment when you switch to a directory.
How are you going to run the application? Will you simply start the binary in the background and nohup it?
You can define (systemd) services in a NixOS configuration.
How will you handle running multiple applications with different domain names or http paths? (you'll probably need to setup haproxy or nginx)
NixOS has support for defining nginx virtual hosts. You can also enable Let's Encrypt and Nix will set up systemd timers to automatically renew the certificates. E.g. here is a configuration of one of my machines with a bunch of virtual hosts with Let's Encrypt:
https://github.com/danieldk/nixos-config/blob/master/machines/castle.nix https://github.com/danieldk/nixos-config/blob/master/machine...
Suppose you update your application. How do you rollout the change? Stop the service, deploy the code, restart the service? How do you avoid downtime?
nixos-rebuild switch --upgrade
Or with nixops you can deploy and update machines remotely.
What if you screw up the deployment? Any way to rollback? (Symlink a folder...? this simple script isn't sounding so simple anymore)
Yes, every change creates a new generation. You can always switch into or boot into an older generation as long as it isn't garbage collected. And this works for the whole system, including kernel updates, etc.
Does your application use other services like redis? How do you configure those services?
Declaratively ;). Adding services.redis.enable = true; to your NixOS configuration does the trick.
As a bonus, with nixops you can deploy a machine configurations on real-hardware, VPS, Virtual Box, KVM, etc.