nix-config

MatthiasBenaets活跃维护

一套用 Nix Flake 管理的个人系统配置,统一维护 NixOS、macOS(Nix-Darwin)和 Home Manager 的 dotfiles,适合想照搬或参考声明式配置方案的人。

My Personal Nix, NixOS and Nix-Darwin System Configuration Flake

暂无版本743star65fork同步于 2026-11-07 07:32 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/matthiasbenaets/nix-config ~/.setup
cd ~/.setup
sudo nixos-rebuild switch --flake .#beelink
硬件要求按 README 说明

README 未说明硬件要求;仅列出各主机平台,如 x86_64-linux、x86_64-darwin、aarch64-darwin。

支持 Apple Silicon
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

个人 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

容易踩的坑

需先安装 Nix 并开启 nix-command 与 flakes 实验特性;macOS 首次构建时 darwin-rebuild 还不在 PATH,需先 nix build 再执行 result/sw/bin/darwin-rebuild;在普通 Linux 上首次用 home-manager 可能需手动运行 non-nixos-gpu-setup 链接 GPU。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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

    HostWM / DEShellTerminalNotes
    beelinkHyprlandNoctaliaKittyDesktop
    workHyprlandNoctaliaKittyLaptop
    vmNoneNoneNonveNone

    Nix-Darwin

    HostWMShellSystemNotes
    intelNoneZshx86_64-darwinMacBook Intel
    m1AeroSpaceZshaarch64-darwinMacBook Air M1
    workAeroSpaceZshaarch64-darwinMacBook Air M3

    Standalone Home Manager

    HostSystemNotes
    pacmanx86_64-linuxAny Linux distro with Nix installed

    All hosts

    ShellEditorsTerminal
    Zsh + p10kNeovim (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):

    1. Create a Host Directory: Create a new directory for your host under modules/hosts/nixos/. Let's call it my-new-host:

      mkdir modules/hosts/nixos/my-new-host
      
    2. Create a default.nix: Inside the new directory, create a default.nix file. This is where you'll define your host's configuration. You can use an existing host as a template.

    3. Define the Host Configuration: In modules/hosts/nixos/my-new-host/default.nix, define the nixosConfiguration for 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
            ];
          };
        };
      }
      
    4. 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.

    PackageDescription
    neovimNeovim 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.

    ShellTools
    defaultvim, git
    neovimConfigured neovim + git
    pythonPython tooling
    nodejsnodejs, 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 run and nix shell are 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