Skip to content

iancleary/infra

Repository files navigation

infra

Personal Infrastructure as code

This repo demonstrates my use of the Infrastructure as Code philosophy using NixOS, Ansible, and Chocolatey.

Tooling

Install nix with the Determinate Systems Nix Installer.

See the README's in each folder and use justfiles with the just command.

Ansible

I used to use an UnRaid server at home, that I use as Network Attached Storage (NAS) server. It also run many docker containers, and several virtual machines (Home Assistant). It became a server that I had confidence in, but couldn't recreate or adjust easily. I've since moved to a NixOS server, and use Ansible to manage it.

Why Ansible? I've used Ansible for a few years now, and I'm comfortable with it. It allows me to template docker compose easilty and it's vault is familiar to me. There are ways to use NixOS entirely manage the server, but I'm not there yet (and don't want to have to create the secrets files manually). I haven't seen how tools on NixOS handle secrets without manually making the file after ssh'ing into the server.

To me, I see the NixOS server as a way to manage the server and it's configuration, packages, networking, and anything to do with the host. On top of that extremely stable base, the Ansible playbooks are a tried and true way to manage the configuration of the containers.

There are ways to use NixOS to manage the containers, but there are currently more questions than paved road solutions. I'm not sure how to handle the secrets files (/nix/store is world readible). I haven't seen how tools on NixOS handle secrets without manually making the file after ssh'ing into the server. To me it seems like a good idea to use Ansible to manage the containers, and NixOS to manage the host.

When I change the ansible files for the NixOS configuration, it will fail to build if I have an issue that impacts the host.

Full stop! That is powerful. The only thing to avoid is to make a change that removes tailscale...which would remove my ability to ssh into the server. I could go grab the server, plug in a keyboard and monitor, and revert with GRUB. That is a pain, but is a nice physical backup plan.

Networking and open ports

I don't believe it is a good idea to open any ports from that server up to the internet, from my local network.

I use Tailscale to connect back to these systems and am protected by WireGuard and no exposed ports to the internet.

The docker-compose files all use a Tailscale sidecar to connect to the Tailscale network. This allows me to connect to the containers from my local machine, and from the server, but not from the internet. It also sets up HTTPS for the containers, using Let's Encrypt.

See Contain your excitement: A deep dive into using Tailscale with Docker, by Alex Kretzschmar.

I allow some local ports to be exposed to the local area network, but only ones needed to configure my Wireless Access Points (to facilitate there adoption).

The default is to not expose a port, and use HTTPS with my Tailnet.

Operating Systems

MacOS

I used to use a Macbook Air and use it for development, catching up with friends, and when I just need to get some personal things done. Since Nix runs very well on Apple Silicon Macs, I have started to do a lot of configuration with Nix. This removes the need for Development Containers and any virtualization...speed!

Windows Laptops and Desktops

I originally started down a path of using dotfiles and ansible to manage my (Ubuntu LTS) desktop configuration, iancleary/ubuntu-dev-playbook.

Since then, I've discovered the Nix package manager, and the NixOS Operating System.

I still use a dotfiles repo, iancleary/dotfiles, but have switched from yadm to chezmoi, as the latter supports Windows, while yadm is Unix only. I recommend both, but Chezmoi fit my changing needs.

At work (RF Systems Engineering on Communications Satellites), the ubiquitous operating system is Windows.

I've dabbled with Ubuntu LTS as a host operating system, but the Microsoft ecosystem can be high friction, depending on what kind of tasks you do, day to day. I went to try Windows Subsystem for Linux, but experienced issues while connecting to the work VPN and DNS issues, when using WSL2. There are probably ways to get that to work now (at the time of writing this) or in the future. However, that's not where I want to spend my time. So, for now, I've focused on how to cultivate all the tools and systems I'd like, while using Windows as the host Operating System.

I explored various options in Virtual Machines, while on a Windows host: Hyper-V, VirtualBox. The performance of Hyper-V was intriguing to me, but the lack of static IP Addresses was frustrating. Again, there might be ways to setup Hyper-V to consistently address VMs by IP Address, across reboots, but the only workflow I found was to use PowerShell to get the IP Address after reboot. That worked fairly well with Ubuntu guests, but I experienced intermittent issues recently. See iancleary/local-ssh-config for a Python package that helps script the update process (get IP Address, update ssh config files).

I've landed on Virtual Box, with a few tricks to make SSH consistent across reboots. Port Forwarding!

TBD to add a repo, but search online for "Virtual Box Port Forwarding +SSH" and you'll find the solution. It maps a host port to a guest's port 22 (or whatever port the guest uses for the openssh server).

So my solution, Virtual Box, allows me to use NixOS, have an immutable file system with rollbacks via GRUB entries, that I can pause/resume as needed. I really enjoyed learning Ansible, and it is a fantastic tool, but the discover of the recovery and rollback features of NixOS were a *illuminating discovery for me. The build with fail if it causes issues with other parts of the configuration.

Virtualbox This is only needed when dealing with external requests and needing docker...i.e. other internal services on a work network...WSL2 works fine with nix and local dev without docker

NixOS

I have dabbled with NixOS as a desktop Operating System and can say it is fantastic.

My Desktop NixOS Configuration is in the iancleary/nixos-config repo. Right now, I generally use WSL to have the same workflow at work and at home, and some software availability keeps me on Windows. See iancleary/wsl-config

There are some excellent write up on Nix and NixOS, so I'll defer to them rather than repeat them (poorly) here:

First Party Nix Articles (nixos.org/wiki)

Third Party Nix Articles