NixOS使用笔记
官方源:https://channels.nixos.org/
清华源:https://mirrors.tuna.tsinghua.edu.cn/nix-channels
本文使用清华源。
升级系统
官方文档:https://nixos.org/manual/nixos/stable/#sec-upgrading
一般情况下升级软件版本:
sudo nixos-rebuild switch --upgrade
如果要升级系统版本号,比如升级到24.11:
# sudo nix-channel --add https://channels.nixos.org/nixos-24.11 nixos
sudo nix-channel --add https://mirrors.tuna.tsinghua.edu.cn/nix-channels/nixos-24.11 nixos
sudo nixos-rebuild switch --upgrade
每次nixos-rebuild
会产生一个generation,便于以后回滚。这些generation引用了老版本软件,所以会阻止它们被GC掉。所以如果不需要回滚的话可以把老的generation删掉。
列出所有generation:
nixos-rebuild list-generations
只保留最新的generation,并且删除旧版本软件:
sudo nix-collect-garbage -d
configuration.nix
{ config, pkgs, ... }:
{
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
];
boot.loader.efi.efiSysMountPoint = "/boot/efi";
nix.settings.substituters = [ "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" ];
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.searchstar = {
isNormalUser = true;
extraGroups = [
"wheel" # Enable ‘sudo’ for the user.
"networkmanager"
];
};
# Use the systemd-boot EFI boot loader.
boot.loader.efi.canTouchEfiVariables = true;
boot.loader.grub = {
enable = true;
device = "nodev";
efiSupport = true;
useOSProber = true;
};
# Set your time zone.
time.timeZone = "Asia/Shanghai";
networking.networkmanager.enable = true;
environment.systemPackages = with pkgs; [
python3
vim # The Nano editor is also installed by default.
git
openssl
trash-cli
]
# Enable the X11 windowing system.
services.xserver.enable = true;
# Enable touchpad support (enabled default in most desktopManager).
services.libinput.enable = true;
# Enable CUPS to print documents.
services.printing.enable = true;
}
修改之后要rebuild才能生效:
sudo nixos-rebuild switch
KDE
# Enable the X11 windowing system.
services.xserver.enable = true;
services.displayManager.sddm.enable = true;
services.desktopManager.plasma6.enable = true;
GNOME
#environment.systemPackages = with pkgs; [
# Need enable in "Extensions" of GNOME
gnomeExtensions.tray-icons-reloaded
#];
# Enable the GNOME Desktop Environment.
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;
中文输入法
官方文档:https://nixos.wiki/wiki/Fcitx5
i18n.inputMethod = {
enable = true;
type = "fcitx5";
fcitx5.addons = with pkgs; [
rime-data
fcitx5-rime
];
};
flatpak
xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-kde ];
xdg.portal.enable = true;
services.flatpak.enable = true;
代理
# Configure network proxy if necessary
networking.proxy.default = "http://127.0.0.1:端口/";
networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
中文字体
#environment.systemPackages = with pkgs; [
# sans表示sans serif,即无衬线字体。粗体使用的就是无衬线字体
noto-fonts-cjk-sans
#];
注销再重新登录之后才生效。
允许安装非自由软件
nixpkgs.config.allowUnfree = true;
然后把要安装的包名写在environment.systemPackages = with pkgs; [
里面。常用的包:
wechat-uos
要用命令行wechat-uos
启动。。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理