NixOS server configuration and switch to Podman
Introduction
II was on the lookout for a lightweight Linux distro to replace Ubuntu, and I discovered NixOS. It’s clean and allows centralized configuration for users, groups, packages, and more. The ease of switching configurations and performing rollbacks is a game changer.
Additionally, I switched from Docker to Podman because of its open-source, daemonless architecture—read more about it here.
How To
Virtual Machine installation
Within Proxmox, I added NixOS as a VM by downloading the Graphical ISO image (Plasma Desktop, 64-bit Intel/AMD).
I uploaded the ISO to the Proxmox local storage, selected SHA-256
as the hash algorithm, and verified the checksum from the NixOS download site.
To place NixOS in the server VLAN, I adjusted the following settings within the node (pve
):
- Select the node
- Navigate to
System
>Network
- Edit the Linux Bridge
- Enable
VLAN aware
and clickOK
- Enter the
VLAN Tag
in the network device settings of the NixOS VM (underHardware
)
Finally, I connected to the Plasma Desktop GUI via the console and completed the installation steps.
NixOS configuration
Here is the configuration.nix
file located at /etc/nixos
, with my additional custom configurations:
-
unstableTarball
: Add the unstable channel declaratively which can be useful if you need services or packages with a higher version. Then you can use for exampleunstable.cockpit
as package or just usecockpit
to use the standard channel. I’ve made a separate note for this -
cockpit-apps
: Custom packages for Cockpit -
fs.inotify settings
: For optimization for Syncthing, among others. -
DHCP
: For the main networking interface. The MAC address comes from the VM and is given a reserved static IP address by the Unifi gateway -
Extra
user options
. This is self-evident -
allow unfree packages
: Could be useful (or not) -
systempackages
, including:openssl
: Useful for generating certificatescifs-utils
: For the cifs mounts. The package may not even need to be added here, but it is then only useful to have for the man pages
-
environment.etc."current-system-packages".text
: After switching configurations, a file is created where you can easily find all installed system packages and the corresponding versions! Just usecat /etc/current-system-packages
-
nix daemon config
: Automatic garbage collection and store optimization. Very handy -
openssh service
is enabled -
security.sudo.wheelNeedsPassword
: Run sudo without a password. This may not always be recommended -
services.fstrim
is enabled. I was told this would be better for my SSD -
services.qemuGuest.enable
: Guest agent for Proxmox. Don’t forget to set theQEMU Guest Agent
toEnabled
in theOptions
of the NixOS VM -
cifs mount
: So that I can access files on my fileserver that runs as a container within Proxmox. ReplaceIP
and and enter your username and password in thesmb-secrets
file -
services.cockpit
: Cockpit is a web-based GUI to administer servers
Podman specific
system.activationScripts
: This will run a script to create folders needed for Podman containers. It will also create a Caddyfile for Caddy and the configuration for phpMyAdmin.virtualisation
: Podman is set as backend. I have set up the containers with separate nix files (for example Homer, Caddy, MariaDB and phpMyAdmin).systemd.services.create-podman-network
: This ensures that the Podman macvlan network I use for all containers is always created if it doesn’t exist. This is very useful, for example when installing a new NixOS VM. Within the IP addresses I replacexx
with my VLAN tag.
Desktop environment specific
services.xserver
: This will setup KDE Plasma as desktop environment. Because this is a server configuration, the default settings are sufficient for me as described here. I will use the terminal more often.environment.plasma5.excludePackages
: Not all applications that come pre-installed with the KDE Plasma desktop environment are desirable for me.services.xrdp
: Very basic settings for XDRP server so I can use remote desktop to connect to the KDE desktop. Guacamole can be used to access the desktop environment and CLI with a web browser.
Switching between NixOS configurations
After modifying the configuration.nix
, run sudo nixos-rebuild switch
to switch between configurations. If it doesn’t work as desired, you can revert with sudo nixos-rebuild switch --rollback
. You can read more about updating and upgrading NixOS here.
Each switch adds a generation, viewable with sudo nix-env -p /nix/var/nix/profiles/system --list-generations
. You can delete old generations using sudo nix-env --profile /nix/var/nix/profiles/system --delete-generations old
.
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.