Wallpaper by Mikael Gustafsson.
- Status: Temporarily fixed in
./programs/gaming.nix - Waiting on
- Issue creation
- Pull request creation
- Pull request merge
- Integration into
nixos-unstable-small
- Added
gcolor3to the list of floating windows by default (./desktop/files/niri/window-rules.kdl)
This configuration is entirely NixOS, more specifically, based on the nixos-unstable-small channel. It makes no use of Nix Flakes, Home Manager, or Flatpaks. I have nothing against them, I simply find the idea of a "pure" NixOS configuration rather attractive. This may make some things harder or not possible, but it is (so far) fine with me.
The Display Manager is GDM. Whilst this may seem like an odd choice (it is), it is the one I have found to work the best with Niri, short of typing niri-session from the console.
Niri is the Wayland compositor used. It supports more hardware than Hyprland does (which is what I used to use), runs faster on my systems, and the scrollable-tilling model is too good to live without.
https://github.com/YaLTeR/niri
Noctalia Shell is the desktop shell. Even if not quite as lightweight as I would like, it is very full-featured, and has done an excellent job at replacing every little other components, scripts, and programs I used to use to replicate a fraction of its functionlaities. The trade-off was almost a no-brainer for me: I would much rather have Noctalia Shell than the combination of random stuff I had before.
https://github.com/noctalia-dev/noctalia-shell
This entire desktop experience is crafted by and for myself only. It will likely not fit most other people's needs and desires. However, you may feel free to take inspiration from this configuration; I have uploaded it publicly for this reason as well.
With this out of the way, we can now proceed to the installation instructions. These are the steps I take to install this NixOS configuration onto my devices; They may not be exactly what you want out of such a configuration, so, feel free to adapt them to your needs.
It is assumed, for these installations instructions, that you:
- Are familiar with Linux
- Are familiar with NixOS, or have at least used it once
- Are comfortable working within the command-line
- Are currently using a Linux distribution
- Have a stable power source and networking
- Have your device's firmware set up to boot and install NixOS properly
- Have read and acknowledge untested hardware and use-cases at the bottom of this README
Since this configuration is based on NixOS unstable (small), it is highly recommended to download the latest NixOS unstable ISO image.
- Graphical ISO
- Minimal ISO I use my own graphical ISO; It is not ready for public use yet, but I might upload it here if it ever becomes ready.
The NixOS ISO is too big to fit on a CD or smaller. As such, a DVD or any removable and bootable storage medium with above 4 GB of storage space is necessary. I will be using a USB flash drive here and the instructions will assume as much, and it is also assumed that the current environment is already Linux-based.
To stay as dependency-free as possible, I will use dd to flash the downloaded ISO file to the flash drive, but you may use any other utility. Graphically, I like Fedora's Media Writer, or Linux Mint's mintstick utility.
First, we need to identify which drive we want to write the ISO file onto. We can do so with lsblk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:112 1 28,7G 0 disk
└─sda1 8:113 1 28,7G 0 part
zram0 253:0 0 31,3G 0 disk [SWAP]
nvme0n1 259:0 0 931,5G 0 disk
├─nvme0n1p1 259:1 0 1G 0 part /boot
├─nvme0n1p2 259:2 0 10G 0 part
│ └─swap 254:0 0 10G 0 crypt [SWAP]
└─nvme0n1p3 259:3 0 920,5G 0 part
└─root 254:1 0 920,5G 0 crypt /home
/nix/store
/nix
/
Here, sda is the ~30 GB USB flash drive I want to use. All data on it will be erased once the ISO writing process begins.
We can now write the ISO file to the USB flash drive, with the following command with superuser privileges:
dd bs=4M if=latest-nixos-graphical-x86_64-linux.iso of=/dev/sda conv=fsync oflag=direct status=progress
Notes:
- Replace
latest-nixos-graphical-x86_64-linux.isowith the appropriate path and file name - Replace
/dev/sdawith the appropriate device to write the ISO file to
Insert the installation medium into the target computer, and start it. If your computer does not automatically boot to the installation medium, or do not know which key to press to open the boot menu, refer to your BIOS' settings and your motherboard manufacturer's documentation.
Once you have booted, make sure to configure your keyboard layout and networking if necessary. The default NixOS ISO lets you configure the key map in the TTY with the loadkeys command as a privileged user, and you can connect to a network using nmtui. Graphical environments come with their own utilities for this.
In my installation, I typically use an encrypted, single-drive setup, on an EFI system. You can easily adapt the following steps for a multi-drive setup and a BIOS-only system, though I will not document BIOS installations here until I can install NixOS on a BIOS-only system that is not as slow as my ThinkPad L510…
As before, command-line utilities will be used for maximum compatibility and minimum dependencies, but a lot of these steps can be done using graphical tools.
- Enter a shell as root with
sudo -i. - List the current storage devices with
lsblk, and identify the one you want to use.
In the case of this example, I will select/dev/sda, which is an empty 1 TB hard disk drive. Obviously, any data on it will be lost in the next few steps.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931,6G 0 disk
sdb 8:112 1 28,7G 0 disk
└─sdb1 8:113 1 28,7G 0 part
- Open the desired storage device with fdisk.
fdisk /dev/sdaYou should see an output similar to this:
Welcome to fdisk (util-linux <version>).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
- Create a GPT partition table by typing
gthen pressingEnter. - Create a boot partition by typing
n. - When asked about the partition number, type
1then pressEnter. - When asked about the first sector, it should be left unchanged, simply press
Enter. - When asked about the last sector, type
+1Gthen pressEnter. Note that you can change this size to be smaller or bigger, depending on the number of Linux Kernels you plan on keeping, especially if you keep lots of NixOS generations around.
If the drive was not empty at first, fdisk will warn you before continuing. Typeythen pressEnter. - Set the type of the boot partition by typing
tthen pressEnter. - When asked about the partition type, type
1then pressEnter.
- Create a swap partition by typing
n. - When asked about the partition number, it should be
2. - When asked about the first sector, it should be left unchanged.
- When asked about the last sector, type
+8Gthen pressEnter. Note that you can change this size to be smaller or bigger, depending on if you want to be able to hibernate your system, and other things.
If the drive was not empty at first, fdisk will warn you before continuing. Typeythen pressEnter. - Set the type of the swap partition by typing
tthen pressEnter. - When asked about the partition type, type
19then pressEnter.
- Create a root partition by typing
n. - When asked about the first and the last sector, they should be left unchanged.
If the drive was not empty at first, fdisk will warn you before continuing. Type
ythen pressEnter.
Until you execute a write, no changes are made to the disk, and you can safely exit at any time, so do not worry if you made mistakes. But to verify if you indeed did things properly, you can type p then press Enter to see what the final result will look like.
If something is off, you can type q then press Enter, and restart the process from step 3.
If everything is looking good, you can write the changes to disk (this WILL erase all data on it) by typing w then pressing Enter.
I use LUKS disk encryption. If you do not, you may skip the relevant encryption steps and adapt the steps for your setup.
- Set up LUKS encryption for the swap partition.
cryptsetup --verify-passphrase luksFormat --label swap /dev/sda2Replace sda2 with the swap partition you previously created.
2. Set up LUKS encryption for the root partition.
You may use the same password as the swap partition for convenience and faster boot.
cryptsetup --verify-passphrase luksFormat --label root /dev/sda3Replace sda3 with the root partition you previously created.
3. (Optional) Create backup headers to store somewhere safe.
This is useful in case they ever get corrupted, somehow. Keep them in a safe, external storage device after creating them.
cryptsetup luksHeaderBackup /dev/sda2 -header-backup-file luks-header-backup-swap.bin
cryptsetup luksHeaderBackup /dev/sda3 -header-backup-file luks-header-backup-root.bin- Open the encrypted partitions.
If you use an SSD, add the
--allow-discardscommand-line argument aftercryptsetup open.
cryptsetup open /dev/sda2 swap
cryptsetup open /dev/sda3 root- Format the swap volume.
mkswap -L Swap /dev/mapper/swap- Format the storage volume. I use Btrfs, but you may use whichever filesystem makes you feel superior. If you do not use Btrfs, skip or change the steps related to Btrfs subvolumes and options.
mkfs.btrfs -L Storage /dev/mapper/root- Format the boot partition.
mkfs.fat -F 32 -n BOOT /dev/sda1Replace sda1 with the boot partition you previously created.
- Turn the swap on.
swapon /dev/mapper/swap- Mount the root volume.
mount -v -t btrfs /dev/mapper/root /mnt- Create the Btrfs subvolumes.
Here, they will be
@(root),@home, and@nix.
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@nix- Unmount the root volume.
umount -v /mnt- Mount the root volume with the proper Btrfs subvolume. Additionally, I enable zstd compression.
mount -v -o subvol=@,compress=zstd:3 /dev/mapper/root /mnt- Create the mount points for the boot, home, and nix volumes.
mkdir -v /mnt/boot
mkdir -v /mnt/home
mkdir -v /mnt/nix- Mount the home and nix Btrfs subvolumes.
Additionally, I enable zstd compression, and enable
noatimefor the nix subvolume to avoid unnecessary writes.
mount -v -o subvol=@home,compress=zstd:3 /dev/mapper/root /mnt/home
mount -v -o subvol=@nix,compress=zstd:3,noatime /dev/mapper/root /mnt/nix- Mount the boot partition.
mount -v -o umask=077 /dev/sda1 /mnt/bootNow that the storage device is set up, we can now set up the NixOS configuration and install the final system.
- Generate the default NixOS configuration and automatically-generated hardware configuration file.
nixos-generate-config --root /mnt- Temporarily move the hardware configuration file
rsync -ah --progress /mnt/etc/nixos/hardware-configuration.nix ~/- Remove the default
configuration.nixmodule, since it will not be used.
rm -v /mnt/etc/nixos/configuration.nix- Clone this repository to
/mnt/etc/nixos/.
git clone https://github.com/Atemo-C/NixOS-configuration /mnt/etc/nixos/- Move the hardware configuration file to
/mnt/etc/nixos/computers/your-comutper-name. Replaceyour-computer-namewith the name of your computer.
mkdir -v /mnt/etc/nixos/computers/your-computer-name
rsync -ah --progress ~/hardware-configuration.nix /mnt/etc/nixos/computers/your-computer-name/- Get the UUID of your swap partition.
We will write it to
/mnt/etc/nixos/computers/your-computer-name/settings.nix; It will be at the bottom of the module.
blkid /dev/sda2 >> /mnt/etc/nixos/computers/your-computer-name/settings.nixThe root partition should be configured automatically, which is why only the step for the swap partition remains. However, you might want to also do this with the root partition, if you want to set up additional options, such as discarding for SSDs.
7. Open this module with your preferred text editor.
In this live environment, you can install the text editor of your choice with nix-env -iA nixos.your-text-editor-here.
your-editor-here /mnt/etc/nixos/computers/your-computer-name/settings.nix- In it, the UUIDs for the encrypted swap partition is located on the bottom of the file.
We need to add them to
boot.initrd.luks.devicessince NixOS does not automatically add it, and set up other settings, such as:
- Discard for SSDs using
boot.initrd.luks.devices.<name>.allowDiscards = true;; - Your computer's host name;
- The keyboard layout configuration;
- Filesystem-specific options (Btrfs compression, etc);
- Import modules that you may want to use on certain devices but not others (e.g. host virtualization, gaming, etc);
- Any other device-specific configuration that you may want. In this example, I will be configuring my main computer. If you need any help or inspiration, please have a look at the existing hardware configuration files in this repository, to see how certain things are done.
{ config, lib, pkgs, ... }: {
boot = {
initrd = {
# Enable USB storage support during the boot process.
#kernelModules = [ "usb_storage" ];
# Additional device encryption settings.
#
# [Tip] Here is how to create a dedicated USB flash drive for
# unlocking your LUKS-encrypted system (secure it away!):
# 1. Generate a random key with `dd`, like so:
# • dd if=/dev/random of=disk-key.key bs=4096 count=1
#
# 2. Add the key to your encrypted storage partition(s) that use the same password:
# • run0 cryptsetup luksAddKey /dev/your-encrypted-partition-here ./disk-key.key
# (repeat if you have multiple encrypted partitions)
#
# 3. Write the key file to the USB flash drive (ALL data on it will be erased):
# • run0 dd if=disk-key.key of=/dev/your-usb-flash-drive-here
luks.devices = {
"2tb-swap" = {
# Add the swap LUKS device, as `nixos-generate-config` does not.
device = "/dev/disk/by-uuid/2f1d31cb-8168-43ab-aa78-3e421e0fb89b";
# If on an SSD with discard support, enable it.
allowDiscards = true;
# Hardware key encryption keys, with manual password fallback.
keyFileSize = 4096;
keyFile = "/dev/disk/by-id/usb-Generic_Flash_Disk_94A5D05A-0:0";
keyFileTimeout = 10;
};
"2tb-root" = {
# If on an SSD with discard support, enable it.
allowDiscards = true;
# Hardware key encryption keys, with manual password fallback.
keyFileSize = 4096;
keyFile = "/dev/disk/by-id/usb-Generic_Flash_Disk_94A5D05A-0:0";
keyFileTimeout = 10;
};
};
};
# Whether the installation process is allowed to modify EFI boot variables.
# Once installed and working, if after an update, it fails to "install" again,
# it should be safe to turn this option off, even if not ideal.
loader.efi.canTouchEfiVariables = true;
};
# ZSTD compression and no-access-time configuration for the main volumes.
fileSystems = {
"/".options = [ "compress=zstd:3" ];
"/home".options = [ "compress=zstd:3" ];
"/nix".options = [ "compress=zstd:3" "noatime" ];
};
# Name of the computer over the network.
networking.hostName = "R7-PC";
systemd = {
# Whether to enable Modem Manager, to handle cellular data.
services.ModemManager.enable = false;
};
services = {
# Whether to enable fwupd, a DBus service that allows applicatoins to update firmware.
fwupd.enable = true;
# Whether to enable LACT, a tool for monitoring, configuring, and overclocking GPUs.
lact.enable = true;
# Keyboard layout configuration on this system.
# To see a complete list of layouts, variants, and other settings:
# • https://gist.github.com/jatcwang/ae3b7019f219b8cdc6798329108c9aee
#
# To see why this list cannot easily be seen within NixOS:
# • https://github.com/NixOS/nixpkgs/issues/254523
# • https://github.com/NixOS/nixpkgs/issues/286283
xserver.xkb = {
layout = "us,fr";
variant = "intl,";
};
};
hardware = {
amdgpu = {
# Whether to enable `amdgpu` overdrive mode for overclocking.
overdrive.enable = lib.mkIf config.services.lact.enable true;
# Whether to enable OpenCL support using ROCM runtime library.
opencl.enable = true;
};
# Which main GPU is used.
# This is used to guide which variant of packages should be installed.
activeGpu = "amd";
};
imports = [
# OpenTabletDriver.
../../input/opentabletdriver.nix
# ZSA keyboard support.
../../input/zsa.nix
# Utility to convert a MiDiPLUS SmartPAD into a full macro pad.
../../extra-modules/scripts/midiplus-smartpad-macropad.nix
# Disk mounts.
../../storage/drives/1TB-SSD.nix
../../storage/drives/PS4-HDD.nix
../../storage/drives/160GB-HDD.nix
];
# Use the correct display configuration in Niri.
systemd.user.tmpfiles.users.${config.user.name}.rules =
lib.optional (config.programs.niri.enable)
"L /etc/nixos/desktop/files/niri/output.kdl - - - - /etc/nixos/computers/r7-pc/files/output.kdl";
# • Limit the amount of cores used when building the NixOS configuration
# • Limit the numbers of maximum jobs running when building the NixOS configuration
# This mostly helps me avoid running out of memory.
# Please Sam give me back my RAM :(
#
# As a note, my CPU (Ryzen 7 9850X3D) has 8 cores and 16 threads.
# I currently have 2×16 GB of RAM.
# I thus limit the maximum number of cores per job used to 8,
# and limit the maximum number of jobs to 2.
# This generally limits the RAM usage to just shy-or-above 16 GB,
# and lets my system still feel relatively snappy under load.
nix.settings = {
cores = 8;
max-jobs = 2;
};
}- Add the following lines to your
configuration.nixin theimportslist, making sure other devices are commented out with#:
./computers/your-computer-name/hardware-configuration.nix
./computers/your-computer-name/settings.nix- Modify the rest of the NixOS configuration to fit your needs. This includes things such as:
- The user's name and title;
- Enabling proprietary drivers for Turing and above NVIDIA GPUs;
- Localization settings, spell checking, timezone;
- Various other settings, programs, etc.
- Install NixOS with the following command. You can add the
--no-root-passwordoption if you wish to not be able to log into therootaccount directly.
nixos-install- Once NixOS is installed, set your user's password.
nixos-enter --root /mnt
passwd your-user-here
exit- You can now safely power off the system, remove the installation medium, and boot into the full NixOS installation.
- Single user;
- Personal computing;
- x86_64 desktop and laptops;
- The default user shell is the FISH shell;
- This entire configuration is for me, it may not work well for you.
- Accessibility features
- Touchscreen support
- Remote desktop through RDP or other
- Computers with:
- A non-x86_64 CPU architecture (not tested)
- Hybrid GPU setup (e.g. NVIDIA PRIME) (not tested)
- NVIDIA GPUs (I no longer have an NVIDIA GPU to test things with, so what is in this configuration is a best-effort attempt at making things work)
- Less than 4 GIB of RAM (Swap may be heavily used with less than 8 when building the system, or doing other Nix things… If you have very little RAM, I hope on your soul that you at least have a capable SSD to let the swapping happen; Otherwise, may Xenia the Linux Fox have mercy on your soul)
- Less than 64 GIB of storage (some Nix storage optimizations are already enabled).
Help is available in:
- The configuration.nix(5) man page
- The on-device manual by running
nixos-help - The online manual at https://nixos.org/manual/nixos/unstable/index.html
- The NixOS Wiki at https://wiki.nixos.org
- The Nix.dev documentation for the nix ecosystem at https://nix.dev
A searchable list of available packages can be found here:
• https://search.nixos.org/packages?channel=unstable
A searchable list of available options can be found here:
• https://search.nixos.org/options?channel=unstable
