Welcome to my modular NixOS system configuration.
There are three essential components: hosts, users and modules.
A host expression represents a physical or virtual machine. A host has one or more users and imports their configuration.
User configrations are handled by Home Manager.
Modules are regular NixOS/Home Manager modules used by host and user expressions.
/nix/nixpkgs
- A clone of the nixpkgs repository/nix/current
- The active configuration/nix/channels/nixos
- Local copy of the unstable channel, used as the default Nix expression search path
/etc/nixos/options.json
- JSON file of all available NixOS options/etc/nixos/system-packages
- List of installed packages
-
rebuild.sh
- Wrapper fornixos-rebuild switch
Example
./rebuild.sh xps15@home
-
update.sh
- Updates flake inputs,/nix/nixpkgs
and packages managed by niv -
clean-up.sh
- Removes old generations and collects garbage
Scripts to simplify the work with VSCode extensions.
-
add-vscode-extension.sh
- Add VSCode extension tonix/sources.json
Example
./add-vscode-extension.sh formulahendry.auto-rename-tag
-
update-vscode-extensions.sh
- Updates all extensions to the latest version
Scripts to simplify the work with IntelliJ IDEA plugins.
add-idea-plugin.sh
- Add IDEA plugin tonix/sources.json
_all
- Base expression, imported by all other hostsxps15
- Contains common configuration for Dell XPS15xps15@home
- Specialization of xps15 for home- ...
_all
- Base expression, imported by all other usersmarkus
- My base user configuratonmarkus@home
- Specialization for home- ...
android
- Support for Android devicesavahi
- Configures avahibase-packages
- Collection of essential CLI toolsbtrfs
- Configures btrfsbuild-essentials
- Build essentialscommand-not-found
- Adds simplecommand-not-found
scriptcompatibility
- Addsfhs-shell
, a FHS-compatible shelldesktop
- Essential packages for desktop environmentsdocker
- Adds Docker and utilitiesecryptfs
- Support for eCryptfsemacs
- Adds Emacsfonts
- Adds some fontsgnome
- Configures Gnome desktop environmentgrub-efi
- Configures GRUB for UEFI systemskodi
- Adds Kodikvm
- Support for KVMlibreoffice
- Adds LibreOfficenvidia
- Configures proprietary NVIDIA driversnix
- Nix configuration and additionsopengl
- Configures OpenGLpipewire
- Configures PipeWireresolved
- Configures systemd-resolvedsnapper
- Configures Snapper to create snapshots of/home
on bootsshd
- Configures OpenSSH serversteam
- Configures Steamsway
- Configures sway window managersystemd-boot
- Configures systemd-bootvirtualbox
- Adds VirutalBox and utilitieswaydroid
- Adds Waydroidwayland
- Adds Wayland utilitiesx11
- Configures X11
ansible
- Adds Ansiblebash
- Configures Bash shellborg-backup
- Adds job which runs BorgBackup/borgmaticchromeos
- Use if ChromeOSchromium
- Configures Chromium web browser and extensionscloud-tools
- Kubernetes and cloud related packagesconky
- Configures conkydconf
- Loads dconf configuration from filedisable-bluetooth
- Disables Bluetooth on startdoom-emacs
- Configures Doom Emacsemacs
- Configures Emacsfish
- Configures Fish shellhide-applications
- Hides applications from launcherjava-development
- Java development related packagesnon-nixos
- Use if other Linux OS than NixOSnixos
- NixOS configuration and additionsvscode-profiles
- Adds VSCode with multiple profiles
Contains some custom overlays.
application/networking/browsers/chromium
- Chromium with Wayland supportdesktops/gnome/core/gnome-terminal
- Gnome Terminal with transparency patchdesktops/gnome/core/nautilus
- Change grid icon sizestools/package-management/nix
- Patched to allow downloads from VSCode Marketplace
Contains a bunch of extra packages.
-
credentials
- Local repository with one filedefault.nix
, which is used to store the passwords for users. Must be created manually.Example
{ user.password = "password"; # user.hashedPassword = "..."; # Generated with 'mkpasswd -m sha-512' }
These repositories are added as Git submodules.
emacs.d
- My Emacs configurationdotfiles
- My dotfiles
Demonstrates how to build a Docker image from Nix expressions.
nix build --impure
docker load < result
docker run --rm -ti hello-docker:latest
Shows how to create development shells with Nix expressions.
nix develop
- Download minimal ISO: https://nixos.org/download.html
- Create virtual machine and boot ISO
-
Create partitions
parted /dev/sda -- mklabel gpt parted /dev/sda -- mkpart ESP fat32 1MiB 512MiB parted /dev/sda -- set 1 esp on parted /dev/sda -- mkpart primary 512MiB 100%
-
Set up LUKS
cryptsetup luksFormat /dev/sda2 cryptsetup luksOpen /dev/sda2 crypt
-
Create filesystems
mkfs.btrfs -L nixos /dev/mapper/crypt mount /dev/disk/by-label/nixos /mnt/ btrfs subvolume create /mnt/root btrfs subvolume create /mnt/nix btrfs subvolume create /mnt/var btrfs subvolume create /mnt/home btrfs subvolume create /mnt/home/.snapshots btrfs subvolume create /mnt/data umount /mnt mkfs.fat -F 32 -n boot /dev/sda1
-
Mount volumes
mount /dev/disk/by-label/nixos -o subvol=root,noatime,compress=zstd:1 /mnt mkdir -p /mnt/{boot,data,home,nix,var} mount /dev/disk/by-label/boot /mnt/boot/ mount /dev/disk/by-label/nixos -o subvol=data,noatime,compress=zstd:1 /mnt/data mount /dev/disk/by-label/nixos -o subvol=home,noatime,compress=zstd:1 /mnt/home mount /dev/disk/by-label/nixos -o subvol=nix,noatime,compress=zstd:1 /mnt/nix mount /dev/disk/by-label/nixos -o subvol=var,noatime,compress=zstd:1 /mnt/var
-
Create swap file
truncate -s 0 /mnt/.swapfile chattr +C /mnt/.swapfile btrfs property set /mnt/.swapfile compression none fallocate -l 4G /mnt/.swapfile chmod 600 /mnt/.swapfile
-
Activate swap
mkswap /mnt/.swapfile swapon /mnt/.swapfile
-
Enter Nix shell
nix-shell -p git nixUnstable
-
Clone repository
cd /mnt/data git clone https://github.com/mrkuz/nixos.git cd nixos
-
Change
dotfiles.url
inflake.nix
to point to the GitHub repository, not local directory.{ dotfiles = { url = "github:mrkuz/dotfiles"; flake = false; }; }
-
Create credentials repository
mkdir repos/credentials cd repos/credentials git config --global user.name "User" git config --global user.email "user@localhost" git init
-
Create
repos/credentials/default.nix
and set password for the useruser
.{ user.password = "..."; # user.hashedPassword = "..."; # Generated with 'mkpasswd -m sha-512'sha-512' }
git add default.nix git commit -m "Add credentials"
-
Update
credentials.url
inflake.nix
. Must be an absolute path. -
Update inputs
export NIX_CONFIG="experimental-features = nix-command flakes" ./update.sh
-
Install
nixos-install --root /mnt --flake /mnt/data/nixos#virtualbox
-
Reboot
-
Move configuration to final location
mkdir -p ~/etc/ sudo mv /data/nixos ~/etc sudo chown user:user -R ~/etc/nixos cd ~/etc/nixos
-
Initialize submodules
git submodule init git submodule update
-
Replace
dotfiles.url
andcredentials.url
inflake.nix
with absolute paths.{ dotfiles = { url = "/home/user/etc/nixos/repos/dotfiles"; flake = false; }; credentials = { url = "/home/user/etc/nixos/repos/credentials"; flake = false; }; }
-
Clone nixpkgs (optional)
sudo git clone https://github.com/NixOS/nixpkgs.git /nix/nixpkgs cd /nix/nixpkgs sudo git checkout nixos-unstable
-
Update and rebuild system
./update.sh ./rebuild.sh virtualbox
-
Install nix
sh <(curl -L https://nixos.org/nix/install) --daemon
-
Add yourself as trusted user to
/etc/nix/nix.conf
trusted-users = root user
-
Clone nixpkgs (optional)
sudo git clone https://github.com/NixOS/nixpkgs.git /nix/nixpkgs cd /nix/nixpkgs sudo git checkout nixos-unstable
-
Clone repository
mkdir ~/etc cd ~/etc git clone https://github.com/mrkuz/nixos.git cd nixos
-
Initialize submodules
git submodule init git submodule update
-
Create credentials repository with empty default.nix
mkdir repos/credentials cd repos/credentials git init touch default.nix git add default.nix git commit -m "Add credentials" cd ../..
-
Replace
dotfiles.url
andcredentials.url
inflake.nix
with absolute paths.{ dotfiles = { url = "/home/user/etc/nixos/repos/dotfiles"; flake = false; }; credentials = { url = "/home/user/etc/nixos/repos/credentials"; flake = false; }; }
-
Update inputs and install
export NIX_CONFIG="experimental-features = nix-command flakes" ./update.sh nix build .#user@ubuntu ./result/activate
nix build .#docker
docker import result/tarball/nixos-system-x86_64-linux.tar.xz nixos
docker run --rm -t --name nixos --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro nixos /init
# Other terminal
docker exec -ti nixos /run/current-system/sw/bin/bash
- Imports
- Modules
- Boot
- Networking
- Filesystems
- Hardware
- systemd
- Services
- Security
- Virtualization
- Environment
- Activation
- Packages
- Fonts
- Users
Same as hosts
- Packages
- Services
- Activation
- Imports
- Modules
- Files
- Services
- Activation
- Packages