Easy NixOS remote deployments

NixOS and Nix are revolutionizing linux distro space: providing a single programing environment that controls everything from building your kernel, ensuring your containers run to getting SSL cert from letsencrypt (it comes batteries included, you don't have to build the kernel if you don't want to).

There exists a mutitude of tooling to remotely manage nixos machines, each with its own features and compromises. However you can also just use a simple flake with nixos-rebuild --target-host.

This is the workflow I've been using to manage my systems.

I bootstrap the machines manually by following the nixos install guide, and copy over the generated configuration to config/<hostname>/configuration.nix.

On the root directory create flake.nix:

{
  description = "systems needed";
  inputs = {
     # extra inputs go here
  };

  outputs = { self, nixpkgs }@attrs: {
    # this is where we add new machines
    nixosConfigurations = {
     # host nixmachine
      nixmachine = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = attrs;
        modules = [
          # This points to the actual machine configuration
          (import ./config/nixmachine/configuration.nix)
        ];
      };
    };
  };
}

This can be deployed by

nixos-rebuild switch  --target-host root@<hostname> --flake '.#nixmachine'

A new host can be added by adding a new entry inside nixosConfigurations.

Should I do this?

I think this is an easier workflow for me to manage and debug, However a lot of things in this space has non-linear learning curves and has sparse documentation at best.

So maybe a tool with better documentation might work well for you?

This also relies heavily on flakes, which is “experimental”. In my experience, this translate to everyone uses flakes, but good documenation is hard to come by (I've herd good things about https://nixos-and-flakes.thiscute.world/, but haven't read it)

Comments?

Hit me up @nomycommit