NixOS on Servers: What Changes When Your OS Becomes Code
Explore how NixOS transforms server management using declarative configurations, smooth rollbacks, and reproducible builds while keeping persistent data in mind.

Stock photo for illustration only, not from the actual event
- Traditional servers often accumulate manual hotfixes that turn them into black boxes.
- NixOS replaces imperative setup steps with a declarative desired state.
- It enables safe testing, switching, and rolling back of system generations.
- Databases and persistent mutable data still require a separate backup strategy.
A server running for three years with script setups and manual hotfixes often becomes an archaeological project that nobody dares to touch. The core issue isn't a lack of automation, but rather that the machine is defined by its history—every one-off decision and quick patch applied during past incidents.
NixOS approaches infrastructure differently by letting you describe the exact state you want rather than the steps to get there. Services, users, packages, and firewall rules live in a declarative configuration, transforming the operating system into something you can build, review, and version control.
Treating the operating system itself as code helps eliminate server drift, where servers that started identical gradually diverge due to manual tweaks. Storing these configurations in Git introduces standard code review workflows like pull requests to infrastructure management.
Traditional Linux distributions set up web servers through a sequence of imperative commands. If a single step is missed or altered, supposedly identical servers drift apart. NixOS avoids this by declaring system properties directly instead of relying on previous machine states.

Stock photo for illustration only, not from the actual event
While theory provides the foundation, configuration files make the model tangible. A typical setup combines Nginx, key-based SSH access, firewalls, and ACME HTTPS certificates. One parameter to note is system.stateVersion, which controls compatibility defaults for stateful services rather than indicating the actual NixOS release version.
NixOS provides a clear, progressive workflow for applying changes safely:
sudo nixos-rebuild build: Evaluates and builds the new generation without touching the live system.sudo nixos-rebuild test: Tests the configuration on the running system temporarily.sudo nixos-rebuild switch: Activates the new generation and makes it the default boot option.sudo nixos-rebuild switch --rollback: Reverts back to the previous generation if issues arise.
Source: Dev.to
Found something wrong in this article? Report an issue with this article
Comments
Leave a Comment