需先安装 Nix 并开启 nix-command 与 flakes 实验特性;macOS 首次构建时 darwin-rebuild 还不在 PATH,需先 nix build 再执行 result/sw/bin/darwin-rebuild;在普通 Linux 上首次用 home-manager 可能需手动运行 non-nixos-gpu-setup 链接 GPU。
nix-config
MatthiasBenaets活跃维护一套用 Nix Flake 管理的个人系统配置,统一维护 NixOS、macOS(Nix-Darwin)和 Home Manager 的 dotfiles,适合想照搬或参考声明式配置方案的人。
My Personal Nix, NixOS and Nix-Darwin System Configuration Flake
git clone https://github.com/matthiasbenaets/nix-config ~/.setup
cd ~/.setup
sudo nixos-rebuild switch --flake .#beelinkREADME 未说明硬件要求;仅列出各主机平台,如 x86_64-linux、x86_64-darwin、aarch64-darwin。
个人 Nix flake 配置,用模块化方式统一管理 NixOS、nix-darwin 和 Home Manager
一套用 Nix Flake 管理的个人系统配置,统一维护 NixOS、macOS(Nix-Darwin)和 Home Manager 的 dotfiles,适合想照搬或参考声明式配置方案的人。
核心能力
- 用 flake-parts 与 import-tree 自动加载 modules 目录下所有模块
- 按功能而非目标系统拆分模块,各主机按需组合
- 同一 flake 覆盖 NixOS、nix-darwin 与独立 Home Manager 三类配置
- 提供 neovim 等独立包,可用 nix run 直接运行
- 内置 default、neovim、python、nodejs 等开发 shell
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Matthias' Nix Configuration Flake
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.
Overview
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
Architecture
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.
Hosts
NixOS
| Host | WM / DE | Shell | Terminal | Notes |
|---|---|---|---|---|
beelink | Hyprland | Noctalia | Kitty | Desktop |
work | Hyprland | Noctalia | Kitty | Laptop |
vm | None | None | Nonve | None |
Nix-Darwin
| Host | WM | Shell | System | Notes |
|---|---|---|---|---|
intel | None | Zsh | x86_64-darwin | MacBook Intel |
m1 | AeroSpace | Zsh | aarch64-darwin | MacBook Air M1 |
work | AeroSpace | Zsh | aarch64-darwin | MacBook Air M3 |
Standalone Home Manager
| Host | System | Notes |
|---|---|---|
pacman | x86_64-linux | Any Linux distro with Nix installed |
All hosts
| Shell | Editors | Terminal |
|---|---|---|
| Zsh + p10k | Neovim (nixvim) | Kitty |
Installation
NixOS
# 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 .#beelink
Nix-Darwin
First 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.conf
First 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>
Standalone Home Manager
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 --system
Get 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-setup
Adding a New Host
Thanks 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.
Packages
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 .#neovim
Dev Shells
Pre-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 shell
Note: Dev shells use
nix develop.nix runandnix shellare for packages, not dev shells.
Maintenance
Garbage Collection
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 --gc
To see what would be deleted without actually deleting it:
nix-store --gc --print-dead
You can also free up more space by optimising the nix store:
nix-store --optimise
It's also possible to clean for the current user or system wide:
nix-collect-garbage -d
sudo nix-collect-garbage -d
Development Reference
Evaluating Configurations
Use 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
Updating Inputs
# Update all inputs
nix flake update
# Update a specific input
nix flake update nixpkgs
Updating Channels
sudo nix-channel --list
sudo nix-channel --remove <name>
sudo nix-channel --add <channel url> <name>
sudo nix-channel --update
Checking Flake Outputs
nix flake show