用于桌面的NixOS

Revision as of 01:05, 11 December 2025 by Moraxyc (talk | contribs) (Created page with "针对应用程序偏好设置、命令行工具以及 dotfiles 等用户级配置的管理,Home Manager 提供了一种便捷的声明式方案。 它允许用户自行定义需要安装的程序及其具体配置方式,而无需将这些设置写入系统级的 [https://nixos.org/manual/nixos/stable/#sec-changing-config configuration.nix] 中。")

NixOS 是一款功能多样的操作系统,适用于各种用例。本文面向希望将 NixOS 作为主要桌面环境(无论是在物理硬件还是虚拟机中)的用户。此外,计划在 云端 环境或专用服务器基础架构上部署 NixOS 的用户,可能会发现从这里介绍的概念和实践开始会很有帮助,因为它们为在更广泛的 Nix 生态系统 中工作奠定了有益的基础。

安装

如果你倾向于阅读, 请从NixOS安装指南开始. 如果你想选择一个精良的视频教程, 请见下一条. 请记住, 为了安装一个桌面, 你需要确定一开始有至少30GiB的可用硬盘空间来容纳桌面环境(比如说, GNOME, KDE, 或者是XFCE), 浏览器(比如Firefox), 以及其他带有图形界面的典型日用软件(如VSCode). 对于相对简陋的配置, 15GiB可能够用.

管理你的配置

你可以使用NixOS官方手册中记录的方式来管理你的所有配置. 然而, 大部分在桌面上使用NixOS的社区成员更喜欢使用Home Manager来管理他们的配置(比如"点文件")(citation needed). Home Manager是一个面向用户的工具, 用于声明你想安装什么, 以及你想如何配置它. 对于大部分设置, 如果你不使用Home Manager的话, 你就要把它们放入configuration.nix, 或者使用nix-env.

关于如何管理配置,请参阅 NixOS 官方手册

系统配置

Main article: NixOS 系统配置

/etc/nixos/configuration.nix是主配置文件,用于定义系统级设置。其中包括启用服务、管理系统用户、配置硬件选项以及指定安装的软件包。 若要使更改生效,请运行:

# nixos-rebuild switch

使用 Home Manager 管理用户配置

针对应用程序偏好设置、命令行工具以及 dotfiles 等用户级配置的管理,Home Manager 提供了一种便捷的声明式方案。

它允许用户自行定义需要安装的程序及其具体配置方式,而无需将这些设置写入系统级的 configuration.nix 中。

Home Manager can be used independently of the system configuration and works with both traditional setups and newer Flakes-based configurations.

通过Flakes

如果你想要可组合性[citation needed]更强的NixOS配置设定, 仍在实验阶段的Flakes特性正在使社区感到十分兴奋. 管理flakes需要对Nix生态有良好的基本理解和一些已有的实践经验.

Refer to NixOS system configuration#Defining NixOS as a flake for details on getting started.

在初始设置之外

在你熟悉了Nix生态并安装了一个功能性的NixOS桌面后, 你可能会想了解定制化和更细化的设置.

Common configuration areas include:

Desktop Environments

Install and configure full-featured environments such as GNOME, KDE Plasma, or Xfce.

See Category:Desktop environment for a full list.

Window Managers

Set up lightweight or tiling window managers like i3, Sway, Hyprland, or xmonad.

See Category:Window managers for a full list.

Display Managers (Login Managers)

Configure graphical session managers such as GDM, SDDM, or LightDM.

Audio Setup

Enable and configure audio systems like PipeWire, PulseAudio, or ALSA.

Network Management

Use tools such as NetworkManager or systemd-networkd for managing network connections.

Bluetooth Support

Set up Bluetooth with blueman or other management tools.

Power Management

Configure laptop battery management, suspend, and hibernation with tools like tlp or systemd services.

Printing and Scanning

Enable Cups for printer support and tools like Sane for scanning devices.

提示和技巧

通过 NixOS 模块机制模块化你的配置

Main article: NixOS system configuration#Modularizing your configuration with modules

另见

对NixOS设置的比较中可查看一个对常见选择进行比较的表格.