From ad9bf8035e76d837a988274785fbbcc02f4996fb Mon Sep 17 00:00:00 2001 From: whc Date: Sat, 19 Sep 2026 15:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=20NixOS=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=EF=BC=9A=E9=9D=A2=E5=90=91=20i7-12700F=20+=20RTX=204060=20?= =?UTF-8?q?=E7=9A=84=E6=A8=A1=E5=9D=97=E5=8C=96=E6=A1=8C=E9=9D=A2=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 从当前 /etc/nixos 拆出 common/plasma/中文/应用/打印模块,新增 NVIDIA 独显支持,并去掉原机硬件 UUID。 --- .gitignore | 17 +++++ README.md | 65 +++++++++++++++++ flake.nix | 22 ++++++ hosts/desktop/default.nix | 21 ++++++ hosts/desktop/hardware.nix | 53 ++++++++++++++ modules/apps.nix | 144 +++++++++++++++++++++++++++++++++++++ modules/chinese.nix | 57 +++++++++++++++ modules/common.nix | 78 ++++++++++++++++++++ modules/desktop-plasma.nix | 21 ++++++ modules/gaming.nix | 12 ++++ modules/nvidia.nix | 29 ++++++++ modules/printing.nix | 51 +++++++++++++ pkgs/hp-uld-driver.nix | 71 ++++++++++++++++++ 13 files changed, 641 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 flake.nix create mode 100644 hosts/desktop/default.nix create mode 100644 hosts/desktop/hardware.nix create mode 100644 modules/apps.nix create mode 100644 modules/chinese.nix create mode 100644 modules/common.nix create mode 100644 modules/desktop-plasma.nix create mode 100644 modules/gaming.nix create mode 100644 modules/nvidia.nix create mode 100644 modules/printing.nix create mode 100644 pkgs/hp-uld-driver.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2eaedf1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# 结果 +result +result-* + +# Flake / 编辑器 +.direnv/ +.envrc +*.swp +*~ +.DS_Store + +# 切勿提交真实机器的 secrets / 密钥 +secrets.nix +*.pem +*.key +.env +.env.* diff --git a/README.md b/README.md new file mode 100644 index 0000000..8203eed --- /dev/null +++ b/README.md @@ -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、开发工具链 diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..eb075c5 --- /dev/null +++ b/flake.nix @@ -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; + }; +} diff --git a/hosts/desktop/default.nix b/hosts/desktop/default.nix new file mode 100644 index 0000000..62a6806 --- /dev/null +++ b/hosts/desktop/default.nix @@ -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"; +} diff --git a/hosts/desktop/hardware.nix b/hosts/desktop/hardware.nix new file mode 100644 index 0000000..10e631b --- /dev/null +++ b/hosts/desktop/hardware.nix @@ -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; +} diff --git a/modules/apps.nix b/modules/apps.nix new file mode 100644 index 0000000..3f26b03 --- /dev/null +++ b/modules/apps.nix @@ -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 + ]; +} diff --git a/modules/chinese.nix b/modules/chinese.nix new file mode 100644 index 0000000..a88acb9 --- /dev/null +++ b/modules/chinese.nix @@ -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 + ]; +} diff --git a/modules/common.nix b/modules/common.nix new file mode 100644 index 0000000..94a5863 --- /dev/null +++ b/modules/common.nix @@ -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"; + }; +} diff --git a/modules/desktop-plasma.nix b/modules/desktop-plasma.nix new file mode 100644 index 0000000..510ff70 --- /dev/null +++ b/modules/desktop-plasma.nix @@ -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 + ]; +} diff --git a/modules/gaming.nix b/modules/gaming.nix new file mode 100644 index 0000000..34a1109 --- /dev/null +++ b/modules/gaming.nix @@ -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; +} diff --git a/modules/nvidia.nix b/modules/nvidia.nix new file mode 100644 index 0000000..e01e286 --- /dev/null +++ b/modules/nvidia.nix @@ -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 + ]; +} diff --git a/modules/printing.nix b/modules/printing.nix new file mode 100644 index 0000000..b1443de --- /dev/null +++ b/modules/printing.nix @@ -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 <> ; +/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 = '' + + + + + ARPLUmingCN + + AR PL UMing CN + Noto Serif CJK SC + + + + NotoSansMonoCJKSC + + Noto Sans Mono CJK SC + + + + ''; + + 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} + ''; +} diff --git a/pkgs/hp-uld-driver.nix b/pkgs/hp-uld-driver.nix new file mode 100644 index 0000000..4ffa629 --- /dev/null +++ b/pkgs/hp-uld-driver.nix @@ -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 ]; + }; +}