After using Arch Linux for a long time I got to know NixOS and decided to give it a try. This repository contains my complete, version-controlled configuration for it.
The goal of this repository is to provide a fully reproducible and declarative environment setup. By managing my system configuration entirely through Nix expressions, I ensure that my machine state can be reliably reproduced on any hardware, minimizing the risk associated with manual changes and drift over time.
- Declarative Management: Every aspect of the system—from desktop environment packages (e.g., Wayland compositors, window managers) to service settings (e.g., SSH keys, firewalls)—is defined in code (
.nixfiles). - Reproducibility: Running
nixos-rebuildwith this configuration ensures that the entire system state is reproducible and consistent across rebuilds. - Version Control: Changes are tracked via Git, allowing for easy rollback to previous stable states and meticulous auditing of system modifications.
- Multi Hardware Support: One central configuration, which supports multiple computers and notebooks.
To deploy this configuration onto a NixOS machine, follow these general steps:
-
Create User Configuration Folder
mkdir ~/.config/nixos -
Clone the Repository
- Enter a nix-shell with git:
nix-shell -p git
- Inside the nix-shell switch to the configuration folder and clone the repository:
cd ~/.config/nixos git clone https://github.com/elmurato/nixos-cfg.git .
-
Adapt User Name
- Search for
elmuratoinconfiguration.nixandhome-manager.nixand replace it with your own username.
- Search for
-
Remove Default Configuration and Create Symlink
⚠️ Warning: This permanently deletes/etc/nixos. If you have existing configuration files you want to keep, back them up first:cp -r /etc/nixos ~/nixos-backupsudo rm -r /etc/nixos sudo ln -s ~/.config/nixos /etc/nixos -
Select Hardware, Rebuild and Apply
- On first rebuild, pass the hostname of the target hardware. Example ThinkPad P14s Gen2i:
sudo nixos-rebuild switch --flake /etc/nixos#thinkpad-p14s-gen2i
- Once the hostname is set, rebuild as usual from that point on:
sudo nixos-rebuild switch --flake /etc/nixos
nixos-cfg/
├── configuration.nix
├── flake.nix
├── flake.lock
├── home-manager.nix
└── hosts/
├── thinkpad-p14s-gen2i/
│ ├── default.nix
│ └── hardware-configuration.nix
└── nixos-vm/
├── default.nix
└── hardware-configuration.nix
| File / Directory | Description |
|---|---|
configuration.nix |
Primary system configuration. Defines global OS settings: networking, user accounts, installed packages, kernel options, and services. Main entry point for nixos-rebuild. |
flake.nix |
Flakes entry point. Declares all external inputs (e.g., nixpkgs, home-manager) and exposes the NixOS configurations for each host as outputs. Replaces the traditional nix-channel approach. |
flake.lock |
Auto-generated lock file that pins every flake input to an exact git revision, guaranteeing fully reproducible builds across machines and time. Do not edit manually. |
home-manager.nix |
User-specific configuration. Manages shell settings (Oh My Zsh, aliases), user-scoped applications, desktop customizations (GTK themes, terminal emulator), and dotfiles. |
hosts/thinkpad-p14s-gen2i/default.nix |
Hardware-specific customizations for the ThinkPad P14s Gen2i. |
hosts/thinkpad-p14s-gen2i/hardware-configuration.nix |
Auto-generated hardware configuration for the ThinkPad P14s Gen2i. |
hosts/nixos-vm/default.nix |
Hardware-specific customizations for the VM. |
hosts/nixos-vm/hardware-configuration.nix |
Auto-generated hardware configuration for the VM. |