整理 NixOS 配置:面向 i7-12700F + RTX 4060 的模块化桌面配置

从当前 /etc/nixos 拆出 common/plasma/中文/应用/打印模块,新增 NVIDIA 独显支持,并去掉原机硬件 UUID。
This commit is contained in:
whc
2026-09-19 15:50:30 +08:00
commit ad9bf8035e
13 changed files with 641 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
# 结果
result
result-*
# Flake / 编辑器
.direnv/
.envrc
*.swp
*~
.DS_Store
# 切勿提交真实机器的 secrets / 密钥
secrets.nix
*.pem
*.key
.env
.env.*
+65
View File
@@ -0,0 +1,65 @@
# whc NixOS(桌面:i7-12700F + RTX 4060)
从当前笔记本配置整理而来,按目标机拆成模块,并加上 NVIDIA 独显支持。
## 结构
```
flake.nix # nixosConfigurations.desktop
hosts/desktop/ # 主机入口 + hardware 占位
modules/
common.nix # 用户 / 网络 / PipeWire / Clash / nix
desktop-plasma.nix # Plasma 6 + SDDM
chinese.nix # 中文 locale / Fcitx5 / 字体
nvidia.nix # RTX 4060(12700F 无核显)
gaming.nix # Steam
printing.nix # CUPS + HP ULD + 中文打印
apps.nix # QQ/微信包装、开发工具等
pkgs/hp-uld-driver.nix
```
## 目标机安装(摘要)
1. 用 NixOS 安装介质启动,按官方流程分区挂载到 `/mnt`。
2. 克隆本仓库:
```bash
sudo git clone https://git.whcself.xyz/WHC/nixos-config.git /mnt/etc/nixos
```
3. **必须**按本机磁盘重新生成硬件配置(覆盖占位 UUID):
```bash
sudo nixos-generate-config --root /mnt
# 把 /mnt/etc/nixos/hardware-configuration.nix
# 覆盖到 hosts/desktop/hardware.nix
# 或改 hosts/desktop/default.nix 去 import 生成的那份
```
4. 安装(flake):
```bash
cd /mnt/etc/nixos
sudo nixos-install --flake .#desktop
```
5. 重启后登录用户 `whc`,设密码(若安装时未设)。
已装系统上更新:
```bash
cd /etc/nixos # 或本仓库路径
sudo nixos-rebuild switch --flake .#desktop
```
## 硬件说明
| 项目 | 配置 |
|------|------|
| CPU | Intel i7-12700F → `kvm-intel`,无核显 |
| GPU | RTX 4060 → `modules/nvidia.nix`(`open = true`) |
| 桌面 | Plasma 6 + SDDM |
| 打印 | HP Laser MFP 13x ULD(不需要可从 `hosts/desktop/default.nix` 去掉 `printing.nix`) |
若 NVIDIA 黑屏:在 `modules/nvidia.nix` 把 `open = true` 改成 `false` 后重建。
## 相对原 `/etc/nixos` 的改动
- 去掉本机(Ultra 9 / Arc / 磁盘 UUID / NPU)相关硬件
- 拆模块,主机名改为 `desktop`
- 新增 RTX 4060 驱动与 `nvtop`
- 保留 QQ/微信源修复、Fcitx 包装、Clash、Steam、开发工具链
+22
View File
@@ -0,0 +1,22 @@
{
description = "whc NixOS — desktop (i7-12700F + RTX 4060)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs =
{ self, nixpkgs, ... }:
let
system = "x86_64-linux";
in
{
nixosConfigurations.desktop = nixpkgs.lib.nixosSystem {
inherit system;
modules = [ ./hosts/desktop ];
};
# 无 flake 时也可:把本仓库拷到 /etc/nixos 后 nixos-rebuild switch
formatter.${system} = nixpkgs.legacyPackages.${system}.nixfmt-rfc-style;
};
}
+21
View File
@@ -0,0 +1,21 @@
{ config, pkgs, ... }:
{
imports = [
./hardware.nix
../../modules/common.nix
../../modules/desktop-plasma.nix
../../modules/chinese.nix
../../modules/nvidia.nix
../../modules/gaming.nix
../../modules/printing.nix
../../modules/apps.nix
];
networking.hostName = "desktop";
# 12700F 桌面机:性能调度即可
powerManagement.cpuFreqGovernor = "performance";
system.stateVersion = "26.05";
}
+53
View File
@@ -0,0 +1,53 @@
# 目标机(i7-12700F + RTX 4060)上必须重新生成本文件,当前为占位骨架。
#
# 安装时在目标机执行:
# sudo nixos-generate-config --root /mnt # 若在 live 安装环境
# # 或已装系统上:
# sudo nixos-generate-config
# 然后把生成的 hardware-configuration.nix 内容覆盖本文件(保留下面 nvidia 相关不要被冲掉的话,
# 显卡驱动在 modules/nvidia.nix,本文件只放磁盘/CPU/固件)。
#
# 切勿带着本仓库里旧机器(Ultra 9 / 另一块盘 UUID)的分区信息开机。
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
boot.initrd.availableKernelModules = [
"xhci_pci"
"ahci"
"nvme"
"usbhid"
"uas"
"sd_mod"
];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
# === 必须按目标机实际分区改 UUID / 挂载点 ===
# fileSystems."/" = { device = "/dev/disk/by-uuid/REPLACE-ROOT"; fsType = "ext4"; };
# fileSystems."/boot" = { device = "/dev/disk/by-uuid/REPLACE-ESP"; fsType = "vfat"; options = [ "fmask=0077" "dmask=0077" ]; };
# swapDevices = [ { device = "/dev/disk/by-uuid/REPLACE-SWAP"; } ];
fileSystems."/" = lib.mkDefault {
device = "/dev/disk/by-uuid/REPLACE-ME-ROOT-UUID";
fsType = "ext4";
};
fileSystems."/boot" = lib.mkDefault {
device = "/dev/disk/by-uuid/REPLACE-ME-BOOT-UUID";
fsType = "vfat";
options = [
"fmask=0077"
"dmask=0077"
];
};
swapDevices = lib.mkDefault [ ];
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
hardware.enableRedistributableFirmware = true;
}
+144
View File
@@ -0,0 +1,144 @@
{ pkgs, ... }:
let
# nixpkgs 里的 QQ 官方链接已 404,改用 GitHub 镜像
qq-fixed = pkgs.qq.overrideAttrs (old: {
version = "3.2.28-2026-04-29";
src = pkgs.fetchurl {
url = "https://github.com/libzonda/Linux-QQ-release/releases/download/3.2.28/QQ_3.2.28_260429_amd64_01.deb";
hash = "sha256-aOeddKzcDFpw76jqHYtkELUaIZBoQ3dNOC8y4OOh8Nc=";
};
});
# nixpkgs 走 archive.org 易失败,改用腾讯官方 AppImage
wechat-fixed = pkgs.callPackage "${pkgs.path}/pkgs/by-name/we/wechat/linux.nix" {
pname = "wechat";
version = "4.1.1";
src = pkgs.fetchurl {
url = "https://dldir1v6.qq.com/weixin/Universal/Linux/WeChatLinux_x86_64.AppImage";
hash = "sha256-RX26ArkbAxzdRBLu4HT7v/udnQax5Q/Bgi00hw4RSZA=";
};
meta = pkgs.wechat.meta;
};
# 微信/QQ 在 Wayland 下原生 IME 不稳定,强制 X11 + fcitx IM 模块
fcitxGtkPath = "${pkgs.fcitx5-gtk}/lib/gtk-3.0";
fcitxQt5Path = "${pkgs.libsForQt5.fcitx5-qt}/lib/qt-5.15/plugins";
fcitxQt6Path = "${pkgs.kdePackages.fcitx5-qt}/lib/qt-6/plugins";
wechat-ime = pkgs.writeShellScriptBin "wechat" ''
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export SDL_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export QT_QPA_PLATFORM=xcb
export GTK_PATH="${fcitxGtkPath}''${GTK_PATH:+:$GTK_PATH}"
export QT_PLUGIN_PATH="${fcitxQt5Path}:${fcitxQt6Path}''${QT_PLUGIN_PATH:+:$QT_PLUGIN_PATH}"
exec ${wechat-fixed}/bin/wechat "$@"
'';
qq-ime = pkgs.stdenvNoCC.mkDerivation {
pname = "qq-ime";
version = qq-fixed.version;
dontUnpack = true;
nativeBuildInputs = [
pkgs.makeWrapper
pkgs.copyDesktopItems
];
desktopItems = [
(pkgs.makeDesktopItem {
name = "qq";
desktopName = "QQ";
genericName = "QQ";
comment = "Tencent QQ";
exec = "qq %U";
icon = "qq";
categories = [
"Network"
"InstantMessaging"
];
startupWMClass = "QQ";
terminal = false;
})
];
installPhase = ''
mkdir -p $out/bin $out/share
makeWrapper ${qq-fixed}/bin/qq $out/bin/qq \
--set GTK_IM_MODULE fcitx \
--set QT_IM_MODULE fcitx \
--set SDL_IM_MODULE fcitx \
--set XMODIFIERS @im=fcitx \
--prefix GTK_PATH : ${fcitxGtkPath} \
--unset NIXOS_OZONE_WL \
--add-flags "--ozone-platform=x11"
if [ -d ${qq-fixed}/share/icons ]; then
cp -a ${qq-fixed}/share/icons $out/share/
fi
runHook postInstall
'';
meta = qq-fixed.meta;
};
in
{
environment.systemPackages = with pkgs; [
wget
curl
google-chrome
wechat-ime
qq-ime
wpsoffice-cn
git
gcc
gnumake
binutils
gdb
cmake
pkg-config
autoconf
automake
libtool
ninja
meson
clang
clang-tools
lld
lldb
ccache
bear
valgrind
cppcheck
python3
python3Packages.pip
openssl
zlib
file
unzip
zip
which
tree
htop
ripgrep
fd
smartmontools
lm_sensors
pciutils
usbutils
lshw
bluez
vulkan-tools
libva-utils
mesa-demos
ffmpeg
jq
bat
eza
fzf
btop
];
}
+57
View File
@@ -0,0 +1,57 @@
{ pkgs, ... }:
{
i18n.inputMethod = {
enable = true;
type = "fcitx5";
fcitx5 = {
waylandFrontend = true;
addons = with pkgs; [
kdePackages.fcitx5-chinese-addons
fcitx5-rime
fcitx5-table-extra
fcitx5-table-other
fcitx5-lua
fcitx5-pinyin-zhwiki
fcitx5-gtk
kdePackages.fcitx5-qt
kdePackages.fcitx5-configtool
fcitx5-material-color
fcitx5-nord
catppuccin-fcitx5
];
};
};
fonts.fontconfig.defaultFonts = {
serif = [
"Noto Serif CJK SC"
"Source Han Serif SC"
"Noto Serif"
];
sansSerif = [
"Noto Sans CJK SC"
"Source Han Sans SC"
"Noto Sans"
];
monospace = [
"Noto Sans Mono CJK SC"
"Source Han Mono SC"
"Noto Sans Mono"
"Hack"
];
};
fonts.packages = with pkgs; [
arphic-uming
noto-fonts
noto-fonts-cjk-sans
noto-fonts-cjk-serif
noto-fonts-color-emoji
source-han-sans
source-han-serif
source-han-mono
wqy_zenhei
wqy_microhei
];
}
+78
View File
@@ -0,0 +1,78 @@
{ config, pkgs, ... }:
{
boot.loader.systemd-boot.enable = true;
boot.loader.systemd-boot.configurationLimit = 10;
boot.loader.efi.canTouchEfiVariables = true;
networking.networkmanager.enable = true;
time.timeZone = "Asia/Shanghai";
i18n.defaultLocale = "zh_CN.UTF-8";
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";
};
# 蓝牙
hardware.bluetooth.enable = true;
hardware.bluetooth.powerOnBoot = true;
services.blueman.enable = true;
services.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
};
users.users.whc = {
isNormalUser = true;
description = "whc";
extraGroups = [
"networkmanager"
"wheel"
"video"
"audio"
];
};
nixpkgs.config.allowUnfree = true;
nix.settings = {
experimental-features = [
"nix-command"
"flakes"
];
auto-optimise-store = true;
};
nix.gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than 30d";
};
programs.nix-ld.enable = true;
programs.git.enable = true;
# Clash Verge Rev
programs.clash-verge = {
enable = true;
package = pkgs.clash-verge-rev;
autoStart = true;
serviceMode = true;
tunMode = true;
group = "wheel";
};
}
+21
View File
@@ -0,0 +1,21 @@
{ pkgs, ... }:
{
services.xserver.enable = true;
services.displayManager.sddm.enable = true;
services.desktopManager.plasma6.enable = true;
services.xserver.xkb = {
layout = "cn";
variant = "";
};
users.users.whc.packages = with pkgs; [
kdePackages.kate
code-cursor
vlc
kdePackages.kdenlive
gimp
kdePackages.kdevelop
];
}
+12
View File
@@ -0,0 +1,12 @@
{ ... }:
{
programs.steam = {
enable = true;
remotePlay.openFirewall = true;
};
# Steam / 游戏需要的 32 位图形库(nvidia.nix 已开 graphics.enable32Bit)
hardware.graphics.enable = true;
hardware.graphics.enable32Bit = true;
}
+29
View File
@@ -0,0 +1,29 @@
# i7-12700F 无核显,RTX 4060 独显直出
{ config, pkgs, ... }:
{
services.xserver.videoDrivers = [ "nvidia" ];
hardware.graphics = {
enable = true;
enable32Bit = true;
};
hardware.nvidia = {
modesetting.enable = true;
# 桌面机一般关 finegrained;需要休眠再开 powerManagement.enable
powerManagement.enable = false;
powerManagement.finegrained = false;
# Ada (40 系) 推荐开源内核模块;若黑屏可改 open = false
open = true;
nvidiaSettings = true;
package = config.boot.kernelPackages.nvidiaPackages.stable;
};
# Wayland + NVIDIA
boot.kernelParams = [ "nvidia_drm.fbdev=1" ];
environment.systemPackages = with pkgs; [
nvtopPackages.nvidia
];
}
+51
View File
@@ -0,0 +1,51 @@
{ pkgs, ... }:
let
hp-uld = pkgs.callPackage ../pkgs/hp-uld-driver.nix { };
cjkSans = "${pkgs.noto-fonts-cjk-sans}/share/fonts/opentype/noto-cjk/NotoSansCJK-VF.otf.ttc";
gsLib = pkgs.runCommand "gs-cjk-lib" { } ''
mkdir -p $out
cat > $out/cidfmap <<CID
% Ghostscript CJK CID map for missing embedded fonts in PDF/PS
/Adobe-GB1 << /FileType /TrueType /Path (${cjkSans}) /SubfontID 0 /CSI ([Adobe-GB1] 0) >> ;
/Adobe-CNS1 << /FileType /TrueType /Path (${cjkSans}) /SubfontID 1 /CSI ([Adobe-CNS1] 0) >> ;
CID
'';
in
{
services.printing.enable = true;
# HP Laser MFP 13x 需官方 ULD(rastertospl)
services.printing.drivers = [ hp-uld ];
fonts.packages = with pkgs; [ arphic-uming ];
fonts.fontconfig.localConf = ''
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<alias binding="same">
<family>ARPLUmingCN</family>
<prefer>
<family>AR PL UMing CN</family>
<family>Noto Serif CJK SC</family>
</prefer>
</alias>
<alias binding="same">
<family>NotoSansMonoCJKSC</family>
<prefer>
<family>Noto Sans Mono CJK SC</family>
</prefer>
</alias>
</fontconfig>
'';
systemd.services.cups.serviceConfig.Environment = [
"FONTCONFIG_FILE=/etc/fonts/fonts.conf"
"FONTCONFIG_PATH=/etc/fonts"
"GS_LIB=${gsLib}"
];
services.printing.extraFilesConf = ''
SetEnv GS_LIB ${gsLib}
'';
}
+71
View File
@@ -0,0 +1,71 @@
# HP Unified Linux Driver for Laser MFP 13x / Laser 10x series (SPL)
{
lib,
stdenv,
fetchurl,
cups,
patchPpdFilesHook,
}:
let
arch = if stdenv.hostPlatform.system == "x86_64-linux" then "x86_64" else "i386";
libPath = lib.makeLibraryPath [ cups ] + ":$out/lib:${lib.getLib stdenv.cc.cc}/lib";
in
stdenv.mkDerivation {
pname = "hp-uld";
version = "1.00.39.12_00.15";
src = fetchurl {
url = "https://ftp.hp.com/pub/softlib/software13/printers/MFP170/uld-hp_V1.00.39.12_00.15.tar.gz";
sha256 = "sha256-zrube2El50BmNLucKpiwFHfR4R1mx8kEdGad6ZJ7yR0=";
};
sourceRoot = "uld";
nativeBuildInputs = [ patchPpdFilesHook ];
dontPatchELF = true;
dontStrip = true;
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/lib/cups/filter $out/lib $out/share/cups/model/hp
install -Dm755 ${arch}/rastertospl $out/lib/cups/filter/rastertospl
install -Dm755 ${arch}/pstosecps $out/lib/cups/filter/pstosecps
install -Dm755 ${arch}/libscmssc.so $out/lib/libscmssc.so
for exe in $out/lib/cups/filter/*; do
patchelf \
--set-rpath "${libPath}" \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
"$exe"
done
patchelf --set-rpath "${libPath}" $out/lib/libscmssc.so
cp -r noarch/share/ppd/*.ppd $out/share/cups/model/hp/
mkdir -p $out/share/cups/model/hp/cms
cp -r noarch/share/ppd/cms/* $out/share/cups/model/hp/cms/ || true
runHook postInstall
'';
ppdFileCommands = [
"pstosecps"
"rastertospl"
];
meta = {
description = "HP Unified Linux Driver (ULD) for Laser MFP 13x series";
homepage = "https://support.hp.com/";
license = lib.licenses.unfree;
platforms = [
"x86_64-linux"
"i686-linux"
];
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
};
}