Full reproducable config for a mail server, 3D-printer controller, desktop, laptop, router, and a Raspberry Pi 5 server.
Tip
Using the minimal installation media is recommended, as it is smaller and faster to download. However, you cannot use network manager (nmtui
) to setup wireless networking with the minimal image.
Note
If you already have a wired connection, you can skip this step.
sudo systemctl start wpa_supplicant
sudo wpa_cli
> add_network
> set_network 0 ssid "your_ssid_here"
> set_network 0 psk "your_password_here"
> enable_network 0
> save_config
> quit
Caution
This deletes your data, check drive names carefully.
cfdisk /dev/drivename
Now, delete all partitions on the disk and create the new partitions:
- A 525M "EFI System" partition,
- a "Linux Swap" partition,
- and a generic "Linux Filesystem" partition to fill the rest of the disk.
First, format the EFI System partition with FAT:
mkfs.fat -F 32 -n boot /dev/drivename1
Then, format the swap partition, giving it the label of 'swap':
mkswap -L swap /dev/drivename2
And finally, format the main Linux Filesystem partition with ext4, giving it the label of 'nixos':
mkfs.ext4 -L nixos /dev/drivename3
These drive labels are used by the system config in fileSystems.nix to avoid hardcoding drive UUIDs.
To edit the contents of the disk, it needs to be mounted into a folder. First, mount the main Linux Filesystem:
mount /dev/whatever3 /mnt # Mount root filesystem
Then, mount the boot filesystem:
mkdir -p /mnt/boot
mount /dev/whatever1 /mnt/boot # Mount boot partition
Finally, enable the swap:
swapon /dev/whatever2 # Use the swap partition
Generate example configuration as referance.
nixos-generate-config --root ./
Note
Copy unique parts of the autogenerated hardware-configuration.nix
to the hardware.nix
of the system to ensure compatibilty with hardware.
Download this repo. This is stored in a tmpfs, so it will be lost on reboot.
nix-shell -p git
git clone https://github.com/headblockhead/dotfiles.git
Warning
Changes made to this copy of the dotfiles are not saved, so copy changes to the /mnt folder or other means of persistance to avoid pain later.
Build and install. Set a root password, it can be anything as we will disable direct root in a minute.
cd dotfiles
nixos-install --root /mnt --flake .#HOSTNAME
reboot
Use a TTY shell to login as root, then set the user password.
passwd headb
Finally, delete the password for the root user and lock the root account.
sudo passwd -dl root
sudo usermod -L root
Try re-installing the bootloader from installation media. Or move EFI files to generic locations for old BIOSes:
mv /boot/EFI/NixOS-boot /boot/EFI/boot
mv /boot/EFI/boot/grubx64.efi /boot/EFI/boot/bootx64.efi
Try adding nomodeset
to the kernel parameters in GRUB.
Requires: switch-nixos, switch-home-manager
Switch to the new nixos and home-manager configurations.
Deploy the nixos configurations to all machines with deploy-rs.
deploy -s
Switch to the new nixos configuration.
sudo nixos-rebuild switch --flake .# --accept-flake-config
Switch to the new home-manager configuration for the current user.
home-manager switch --flake ".#$USER@`hostname`"
Cleanup unused nix store paths, then print a summary.
nix-collect-garbage --quiet
Deletes all but the current generation of NixOS and cleanup leftovers, then print a summary.
sudo nix-collect-garbage -d --quiet