A modular, multi-platform Nix flake managing NixOS, Nix-Darwin, and standalone Home Manager configurations using flake-parts and the dendritic pattern.
Check out the vanilla branch for a more "vanilla" Nix Flake setup.
This flake manages system configuration across three platforms:
- NixOS - full system configuration for Linux hosts
- nix-darwin - system configuration for macOS hosts
- Home Manager (standalone) - user environment for non-NixOS Linux hosts
- Dev Shells - reproducible development environments via
nix develop - Packages - standalone applications (e.g. neovim via nixvim) runnable with
nix run
The flake uses flake-parts with import-tree to automatically load all modules from the modules/ directory. Configuration is split into small, composable modules following the dendritic pattern. Modules are organized by feature, not by target OS, and hosts compose exactly what they need.
| Host | WM / DE | Shell | Terminal | Notes |
|---|---|---|---|---|
beelink |
Hyprland | Noctalia | Kitty | Desktop |
work |
Hyprland | Noctalia | Kitty | Laptop |
vm |
None | None | Nonve | None |
| Host | WM | Shell | System | Notes |
|---|---|---|---|---|
intel |
None | Zsh | x86_64-darwin | MacBook Intel |
m1 |
HyprSpace | Zsh | aarch64-darwin | MacBook Air M1 |
work |
HyprSpace | Zsh | aarch64-darwin | MacBook Air M3 |
| Host | System | Notes |
|---|---|---|
pacman |
x86_64-linux | Any Linux distro with Nix installed |
| Shell | Editors | Terminal |
|---|---|---|
| Zsh + p10k | Neovim (nixvim) | Kitty |
# Clone the repo
git clone https://github.com/matthiasbenaets/nix-config ~/.setup
cd ~/.setup
# Switch to a host configuration
sudo nixos-rebuild switch --flake <path/to/flake>#<host>
# Example
sudo nixos-rebuild switch --flake .#beelinkFirst install Nix if not present:
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install)Enable flakes:
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.confFirst build (darwin-rebuild not yet in PATH):
nix-env -iA nixpkgs.git
git clone https://github.com/matthiasbenaets/nix-config ~/.setup
cd ~/.setup
nix build .#darwinConfigurations.<host>.system
./result/sw/bin/darwin-rebuild switch --flake ~/.setup#<host>Subsequent rebuilds:
darwin-rebuild switch --flake ~/.setup#<host>First install Nix and Home Manager (and Flatpak):
sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
nix-shell '<home-manager>' -A install
# Ubuntu for flatpak
echo "kernel.unprivileged_userns_clone=1" | sudo tee /etc/sysctl.d/99-userns.conf \
&& echo "kernel.apparmor_restrict_unprivileged_userns=0" | sudo tee /etc/sysctl.d/99-flatpak.conf \
&& sudo sysctl --systemGet and rebuild:
nix-env -iA nixpkgs.git
git clone https://github.com/matthiasbenaets/nix-config ~/.setup
cd ~/.setup
home-manager switch --extra-experimental-features 'nix-command flakes' --flake ~/.setup#<host>NixGL is no longer required when running home-manager on a generic Linux host.
However on first rebuild, you might need to run the command below to link the GPU using a service.
sudo /nix/store/<sha>-non-nixos-gpu/bin/non-nixos-gpu-setupThanks to the dendritic structure and import-tree, adding a new host is a straightforward process that doesn't require modifying the main flake.nix.
Here's how to add a new NixOS host (the process is similar for nix-darwin and home-manager):
-
Create a Host Directory: Create a new directory for your host under
modules/hosts/nixos/. Let's call itmy-new-host:mkdir modules/hosts/nixos/my-new-host
-
Create a
default.nix: Inside the new directory, create adefault.nixfile. This is where you'll define your host's configuration. You can use an existing host as a template. -
Define the Host Configuration: In
modules/hosts/nixos/my-new-host/default.nix, define thenixosConfigurationfor your host. It should look something like this:{ config, inputs, ... }: let host = { name = "my-new-host"; user.name = "your-username"; state.version = "23.11"; // Or your desired version system = "x86_64-linux"; }; in { flake.nixosConfigurations.my-new-host = inputs.nixpkgs.lib.nixosSystem { modules = with config.flake.modules.nixos; [ # Import the modules you need base my-new-host # a module for host specific configuration # Example modules: audio nixvim gnome ]; }; # Host-specific module flake.modules.nixos.my-new-host = { inherit host; home-manager.users.${host.user.name} = { imports = with config.flake.modules.homeManager; [ # Home-manager modules kitty ]; }; }; }
-
Build Your Host: Once you've created the
default.nix, you can build your new host configuration:sudo nixos-rebuild switch --flake .#my-new-host
This structure allows you to keep your host-specific configurations isolated while re-using the modules defined in the rest of the flake.
Standalone packages can be run directly without installing them system-wide.
| Package | Description |
|---|---|
neovim |
Neovim configured via nixvim |
# Run directly
nix run .#neovim
# Run from anywhere using the flake URL
nix run github:matthiasbenaets/nix-config#neovim
# Add temporarily to PATH
nix shell .#neovimPre-configured development environments with all relevant tools available.
| Shell | Tools |
|---|---|
default |
vim, git |
neovim |
Configured neovim + git |
python |
Python tooling |
nodejs |
nodejs, npm with local prefix configured |
# Enter a shell
nix develop .#<shell>
# Examples
nix develop .#nodejs
nix develop .#python
nix develop # enters default shellNote: Dev shells use
nix develop.nix runandnix shellare for packages, not dev shells.
Nix stores all packages in the /nix/store, and over time this can grow quite large. You can remove unused packages (garbage) to free up space.
To remove all packages that are not referenced by any user profile or configuration:
nix-store --gcTo see what would be deleted without actually deleting it:
nix-store --gc --print-deadYou can also free up more space by optimising the nix store:
nix-store --optimiseIt's also possible to clean for the current user or system wide:
nix-collect-garbage -d
sudo nix-collect-garbage -dUse these commands to check if a configuration evaluates without errors:
nix eval <path/to/flake>#nixosConfigurations.<host>.config.system.build.toplevel --show-trace
nix eval <path/to/flake>#darwinConfigurations.<host>.config.system.build.toplevel --show-trace
nix eval <path/to/flake>#homeConfigurations.<host>.activationPackage --show-trace
nix eval <path/to/flake>#<package> --show-trace
# Update all inputs
nix flake update
# Update a specific input
nix flake update nixpkgs
sudo nix-channel --list
sudo nix-channel --remove <name>
sudo nix-channel --add <channel url> <name>
sudo nix-channel --updatenix flake show