Setting Up Your Own NixOS Home Server: A Comprehensive Guide
NixOS stands out as a remarkable Linux distribution for server environments, primarily due to its robust configuration capabilities. It enables users to define their system setup in a configuration file, which can be easily shared and replicated across deployments. This guide will walk you through the process of establishing your very own NixOS home server.
Downloading NixOS: Your First Step
To get started with NixOS, you’ll need to download the operating system from its official website. Simply visit NixOS.org and locate the “Download” button.
After clicking on "Download," scroll down to the section titled “NixOS: the operating system,” where you can select between the Gnome or Plasma desktop ISOs. For users relying on a wireless connection, it’s advisable to go for a graphical desktop version, which includes Wi-Fi support.
Once you’ve chosen your desired edition, your browser will initiate the download to your system. Depending on your internet speed, this process may take a while. Be sure to have a USB flash drive ready for the next steps.
Creating a NixOS Installation Medium
Creating a USB installation medium is essential for the installation of NixOS on your home server. A straightforward way to accomplish this is by using a tool called “Etcher,” which is available for Windows, Linux, and Mac OS. You can download it from the official Etcher website.
After installing Etcher, follow these steps to create your NixOS installation medium:
- Flash the NixOS ISO: Open Etcher, click on the “Flash from file” button, and navigate to the NixOS ISO you downloaded.
- Select the USB Drive: Click on “Select target” and choose the USB flash drive as your target for the NixOS ISO.
- Start Flashing: Click on “Flash!” to begin the process. This may take some time, so patience is required!
Once the flashing is complete, reboot your home server and configure your BIOS to boot from the USB drive, launching the NixOS installer.
Installing NixOS: A Unique Installation Process
The installation approach for NixOS diverges from other operating systems. Although it provides a GUI installer, it maintains a declarative configuration model, necessitating that you predefine your settings.
To kick off the installation, ensure your server is connected to the internet via Ethernet or WiFi. Access the GUI installer, select your preferred language, and proceed by clicking “Next.”
You will then need to set your timezone by locating your region on a world map, followed by configuring the keyboard layout, server hostname, user account, and password. Each setup step concludes by clicking “Next.”
For a home server, opt for the “No desktop” configuration, as a desktop environment is unnecessary. If you prefer to use unfree software, make sure to check the corresponding box.
When arriving at the disk selection screen, choose the target disk for the NixOS installation and select “Erase” to format the disk. After this, confirm your configurations and click ‘Next’ to initiate the installation process. Upon completion, disconnect the USB drive and boot into your new NixOS system.
Configuring NixOS as a Home Server
Once NixOS is installed, the next step is configuring it as a home server. Start by enabling SSH server access through the command line. Navigate to the /etc/nixos/
directory using the command:
cd /etc/nixos/
Create a new configuration file for the SSH server using the following command:
sudo touch ssh-server.nix
Open the ssh-server.nix
module in Nano and insert the following code to enable OpenSSH daemon:
sudo nano -w /etc/nixos/ssh-server.nix
{ config, pkgs, ... }:
{
services.openssh.enable = true;
programs.gnupg.agent = {
enable = true;
enableSSHSupport = true;
};
# Additional configurations can be added here
}
After saving your changes (Ctrl + O, then exit with Ctrl + X), add this file to your imports within configuration.nix
:
sudo nano -w /etc/nixos/configuration.nix
{ config, pkgs, ... }:
{
imports = [
./hardware-configuration.nix
./ssh-server.nix
];
# Other configurations...
}
To finalize the setup and enable SSH access, run:
sudo nixos-rebuild switch
Basic Server Configuration: Enhancing Your Home Server
For a foundational server setup, consider enabling services like Nginx, PostgreSQL, or Cron. You can easily download a pre-configured “basic-server.nix” module, which includes various applications, by executing the following commands:
cd /etc/nixos/
sudo wget https://raw.githubusercontent.com/soltros/configbuilder/main/server-modules/basic-server.nix
Next, open configuration.nix
again in Nano and add the new module to your imports:
sudo nano -w /etc/nixos/configuration.nix
{ config, pkgs, ... }:
{
imports = [
./hardware-configuration.nix
./ssh-server.nix
./basic-server.nix
];
# Other configurations...
}
After adding basic-server.nix
, initiate another rebuild to activate the new applications:
sudo nixos-rebuild switch
Conclusion
Setting up NixOS as a home server provides a highly customizable and reliable environment for various server applications. By following this guide, you’ll have a solid starting point for your NixOS configuration, allowing for future expansions and enhancements tailored to your specific needs.