This is an example project using NixOS to declaratively configure a VM with multiple services that can run on a free tier micro instance (see howto for details).
The configuration is mostly not specific to the cloud service and can be adapted to other providers (e.g. Amazon EC2).
Following services are defined using NixOS options.
- ACME
- This uses the lego client to manage and renew SSL certificates from Let's Encrypt.
- Wildcard certificate verification using dns verification check (connecting to Websupport DNS API)
- Auto restarts dependent services upon certificate renewal.
- nginx
- Use as a reverse proxy to manage multiple subdomains and forward traffic to the respective services.
- Host a static website on the root domain
- Force SSL on all endpoints
- Gate specific subdomains behind SSO login using the auth_request module and the vouch-proxy service.
- node-red
- Home automation toolbox
- Protected by SSO (https://node-red.tomaskrupka/cz)
- mosquitto
- mqtt broker with two listeners defined
- Unauthenticated traffic for local services
- mqtt over SSL for remote connections
- mqtt broker with two listeners defined
- restic
- Daily backups of user data to a GCS bucket:
- node-red data directory
- flatnotes data directory
- website root
- Daily backups of user data to a GCS bucket:
Following services are packaged in the modules
directory of this repository:
- vouch-proxy
- SSO solution for nginx
- Configured to use Google OAuth 2.0 and only pass whitelisted users
- See details in the
modules/vouch.nix
file
- inadyn
- Dynamic DNS service
- Runs periodically to check the VM public address and update DNS records (Websupport DynDNS API)
- See details in the
modules/inadyn.nix
file
- flatnotes
- Personal note taking
- Protected by SSO (https://notes.tomaskrupka.cz)
- See details in the
modules/flatnotes.nix
file
The services require quite a few keys / tokens / secrets to be able to run. All the secrets are managed using sops-nix:
- Secrets definitions are in the
secrets.nix
file - Encrypted secrets are included in the
secrets
directory - The secrets are decrypted on the VM during system activation and have permissions set to read-only either for root or a specific service user.
The static content of the website is expected to be served from /home/github-actions/www
:
- The
github-actions
user is defined in the configuration file - The
nginx
user has read access to its home directory - An authorized ssh public key is configured so that the content can be uploaded from another machine