这篇文章还在持续更新中。有的部分已经写了一些,但还没有写完。我的最终目的是为看到这篇文章的访客提供完整可用的配置文件(dotfiles)与详细的踩坑记录

Nixos 是什么?

Nixos是一个基于 Nix 的 Linux 发行版,它最大的特点是系统通过 Nix 语言编写的中心化的配置文件进行管理,几乎一切都是可声明的。这也意味着你可以很轻松地迁移或复现某一状态——只需要确保配置文件相同再sudo nixos-rebuild switch即可。Nixos 在安装或升级一个软件包不会破坏其他软件包,同时也在启动时提供了回滚机制,从而确保了系统可靠性

前置条件

本次安装将使用ASUS Zenbook 14,搭载AMD Ryzen AI 7 H 350。同时我还将使用一块致态 Ti600 500GB PCle4.0的 m2 硬盘,出于可移动性考虑将安置在一个使用 RTL9210 主控的 ITGZ 硬盘盒内(实测在使用雷电 4 接口时传输速率可达 700MB/S),作为随身Linux使用(参考NixOS Manual)

安装 iso 镜像来自NixOS 官网,由于使用图形化安装时提供了KDE Plasma选项,其中部分组件恰好是我需要的,故不使用最小化安装,同时避免了繁琐的分区等操作。本次将安装的版本为25.11

安装 NixOS

首先格式化硬盘,使用 balenaEtcher 刷入iso镜像,随后进入UEFI设置面板关闭安全启动,在CSM设置中将USB设备启动优先级提至最前,或在Boot menu选择硬盘并引导

启动图形化安装界面后,选择Plasma桌面+Linux LTS,安装时需要连接电源并连接网络。在网卡正常的情况下(联发科网卡小概率驱动异常)可以直接连接WiFi,或使用USB共享网络。值得一提的是,由于KDE一开始会启用KDE Wallet的Secret Service,你可能需要关掉这个服务甚至整个subsystem,并选择Store password for all users才能正常连接无线网

连接后就可以正常访问互联网了。选择自己想要的配置,依据引导完成安装。我在初次安装时选择了使用整块硬盘,如果你打算安装Win+Linux双系统,也可以指定想安装的空闲分区,注意不要破坏Windows Boot Manager

重启电脑,利用Kate编辑器修改初步的/etc/nixos/configuration.nix如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{ config, pkgs, ... }:

{
imports =
[
./hardware-configuration.nix
];

boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

networking.hostName = "nixos";
networking.networkmanager.enable = true;

time.timeZone = "Asia/Shanghai";

i18n.defaultLocale = "zh_CN.UTF-8";

i18n.inputMethod = {
enable = true;
type = "fcitx5";
fcitx5 = {
waylandFrontend = true;
addons = with pkgs; [
qt6Packages.fcitx5-chinese-addons
fcitx5-rime
qt6Packages.fcitx5-configtool
];
};
};

fonts.packages = with pkgs; [
noto-fonts-cjk-sans
noto-fonts-cjk-serif
sarasa-gothic
];

i18n.extraLocaleSettings = {
LC_ADDRESS = "zh_CN.UTF-8";
LC_IDENTIFICATION = "zh_CN.UTF-8";
LC_MEASUREMENT = "zh_CN.UTF-8";
LC_MONETARY = "zh_CN.UTF-8";
LC_NAME = "zh_CN.UTF-8";
LC_NUMERIC = "zh_CN.UTF-8";
LC_PAPER = "zh_CN.UTF-8";
LC_TELEPHONE = "zh_CN.UTF-8";
LC_TIME = "zh_CN.UTF-8";
};

programs.hyprland = {
enable = true;
withUWSM = true;
xwayland.enable = true;
};

services.xserver.enable = true;
services.displayManager.sddm = {
enable = true;
wayland.enable = true;
theme = "breeze";
};

services.greetd = {
enable = true;
settings = {
default_session = {
command = "uwsm app -- hyprland";
user = "himekawa";
};
};
};

console.keyMap = "us";

services.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};

users.users.himekawa = {
isNormalUser = true;
description = "Himekawa";
extraGroups = [ "networkmanager" "wheel" "video" "audio" ];
packages = with pkgs; [
kdePackages.kate
kdePackages.konsole
kitty
rofi
waybar
mako
swaybg
brightnessctl
pavucontrol
networkmanagerapplet
xfce.thunar
gvfs
nano
hyprpaper
python314
gdb
gnumake
binutils
glibc.dev
patchelf
file
strace
ltrace
vscode
docker
tty-clock
fastfetch
clipse
netease-cloud-music-gtk
clash-verge-rev
microsoft-edge
obs-studio
# obsidian
];
};

programs.firefox.enable = true;
nixpkgs.config.allowUnfree = true;

environment.sessionVariables = {
GTK_IM_MODULE = "fcitx";
QT_IM_MODULE = "fcitx";
XMODIFIERS = "@im=fcitx";
SDL_IM_MODULE = "fcitx";
XDG_SESSION_TYPE = "wayland";
XDG_SESSION_DESKTOP = "hyprland";
};

environment.systemPackages = with pkgs; [
wget
curl
git
libnotify
grim
slurp
wl-clipboard
noto-fonts
font-awesome
vim
unzip
zip
gcc
];
nix.settings.experimental-features = [
"nix-command"
"flakes"
];

system.stateVersion = "25.11";
}

这里主要做了如下配置:

  1. 配置了中文以及Fcitx5中文输入法
  2. 使用了Hyprland作为桌面环境
  3. 配置了VSCode、Docker、Python、Clash、OBS、网易云等我常用的软件/工具
  4. 启用了nix-commandflakes实验特性

关于Niri

Niri是另一个平铺窗口管理器,窗口可以在无限的水平画布上排成列,新窗口向右延伸,不挤压现有窗口,通过滚动查看。某种意义上来说,它的设计理念比Hyprland更先进,而且似乎很适合带鱼屏。但我最后还是出于生态原因选择了Hyprland

配置Hyprland与对应的生态

NixOS中启用Hyprland只是第一步。想要得到一个不错的桌面体验,需要自行配置一系列生态组件。我使用的大致配置如下

组件 功能
Hyprland Wayland 合成器
Waybar 状态栏
Mako 通知 Daemon
Rofi 应用启动器
Hyprpaper/wpaperd 壁纸管理
nm-applet NetworkManager 托盘
wl-clipboard / clipse 剪贴板

想要配置Hyprland,只需编辑~/.config/hypr/hyprland.conf并保存即可

例如,你可以尝试着修改配置第一行为:

1
monitor=, preferred, auto, 1.6

这一行的含义是:

  • 第一个参数Name,留空,匹配所有显示器
  • 第二个参数Resolutionpreferred,使用原生分辨率
  • 第三个参数Positionauto,自动决定显示器位置
  • 第四个参数Scale1.6,使用160%缩放,对于2.5K显示器观感较佳

快捷键设置

既然使用Hyprland,大部分鼠标操作就可以摒弃了,部分需要的操作也可以由触摸板替代。我设置了如下快捷键,其中很多是自己的习惯与Windows风格,便于Win用户迁移

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
$mainMod = SUPER # SUPER键作为mainMod,例如Win键

bind = $mainMod, Q, killactive # 关闭活动窗口
bind = $mainMod, RETURN, exec, kitty # SUPER+Enter打开终端

bind = $mainMod, R, exec, rofi -show drun # 应用启动器,类似Windows的Win+R
bind = $mainMod, B, exec, firefox # 打开浏览器
bind = $mainMod, E, exec, thunar # 文件管理器thunar
bind = $mainMod, P, exec, grim -g "$(slurp)" - | swappy -f - # 屏幕截图,可选区域截图

bind = $mainMod SHIFT, R, exec, hyprctl reload # 重启hyprland
bind = $mainMod, SPACE, togglefloating
bind = $mainMod, X, exec, pkill rofi # 关闭rofi应用启动器
bind = $mainMod, A, pseudo, # dwindle
bind = $mainMod SHIFT, A, togglesplit, # dwindle

bind= $mainMod, V, exec, cliphist list | rofi -dmenu | cliphist decode | wl-copy # Windows上的复制粘贴体验

# 用 mainMod + arrow keys 移动焦点
bind = $mainMod, left, movefocus, l
bind = $mainMod, right, movefocus, r
bind = $mainMod, up, movefocus, u
bind = $mainMod, down, movefocus, d


bind = ALT,R,submap,resize # ALT+R调节窗口大小,下方参数是一次移动的像素
submap=resize
binde=,h,resizeactive,-20 0
binde=,l,resizeactive,20 0
binde=,k,resizeactive,0 -20
binde=,j,resizeactive,0 20
bind=,escape,submap,reset
submap=reset

# 用 mainMod + [0-9] 切换工作区
bind = $mainMod, 1, workspace, 1
bind = $mainMod, 2, workspace, 2
bind = $mainMod, 3, workspace, 3
bind = $mainMod, 4, workspace, 4
bind = $mainMod, 5, workspace, 5
bind = $mainMod, 6, workspace, 6
bind = $mainMod, 7, workspace, 7
bind = $mainMod, 8, workspace, 8
bind = $mainMod, 9, workspace, 9
bind = $mainMod, 0, workspace, 10

# 用 ALT + SHIFT + [0-9] 将聚焦的容器移动到指定工作区
bind = ALT SHIFT, 1, movetoworkspace, 1
bind = ALT SHIFT, 2, movetoworkspace, 2
bind = ALT SHIFT, 3, movetoworkspace, 3
bind = ALT SHIFT, 4, movetoworkspace, 4
bind = ALT SHIFT, 5, movetoworkspace, 5
bind = ALT SHIFT, 6, movetoworkspace, 6
bind = ALT SHIFT, 7, movetoworkspace, 7
bind = ALT SHIFT, 8, movetoworkspace, 8
bind = ALT SHIFT, 9, movetoworkspace, 9
bind = ALT SHIFT, 0, movetoworkspace, 10

# 用 mainMod + SHIFT + [0-9] 将活动窗口移动到指定工作区
bind = $mainMod SHIFT, 1, movetoworkspacesilent, 1
bind = $mainMod SHIFT, 2, movetoworkspacesilent, 2
bind = $mainMod SHIFT, 3, movetoworkspacesilent, 3
bind = $mainMod SHIFT, 4, movetoworkspacesilent, 4
bind = $mainMod SHIFT, 5, movetoworkspacesilent, 5
bind = $mainMod SHIFT, 6, movetoworkspacesilent, 6
bind = $mainMod SHIFT, 7, movetoworkspacesilent, 7
bind = $mainMod SHIFT, 8, movetoworkspacesilent, 8
bind = $mainMod SHIFT, 9, movetoworkspacesilent, 9
bind = $mainMod SHIFT, 0, movetoworkspacesilent, 10

bind = $mainMod, F, fullscreen, 2 # 全屏
bind = $mainMod SHIFT, F, fullscreenstate, 0 2

bind = ,232,exec,brightnessctl -c backlight set 5%-
bind = ,233,exec,brightnessctl -c backlight set +5%
bind = $mainMod SHIFT, W, exec, killall -9 wpaperd && wpaperd -c ~/.config/wpaperd/config_ypb.toml
bind = $mainMod, W, exec, killall -9 wpaperd && wpaperd -c ~/.config/wpaperd/config.toml

bind = $mainMod SHIFT,up, movewindow, u
bind = $mainMod SHIFT,down, movewindow, d
bind = $mainMod SHIFT,left, movewindow, l
bind = $mainMod SHIFT,right, movewindow, r

进一步美化

使用dotfiles

中文输入法

网络配置

nix的基本使用

常用软件包

配置管理的哲学

疑难杂症Q&A