Loading... sudo -i # 切换root, 后续就不用sudo了 nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixpkgs-unstable nixpkgs # 订阅镜像仓库频道 nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixos-23.05 nixos # 请注意系统版本 nix-channel --list # 列出频道,这一步是确认修改没有出错 nix-channel --update # 更新并解包频道 lsblk # 查看要分区的设备 parted /dev/(sda, nvme0n) mklabel gpt mkpart ESP fat32 1MiB 256MiB # 在 1 MiB - 256 MiB 的位置创建引导分区 p # 打印当前分区表 set 1 esp on # 将序号为 1 的分区标识为可启动 mkpart primary 256MiB -16GiB # 在自 256MiB 至分区尾前 8GiB 的位置创建主分区 mkpart primary linux-swap -16GiB 100% # 余下的 8GiB 用于创建交换分区 p # 确认当前分区情况 quit # 退出 mkfs.fat -F 32 /dev/nvme0n2p1 # 格式化引导分区为 FAT32 格式 mkfs.btrfs -L nixos /dev/nvme0n2p2 # 格式化根分区为 Btrfs 格式 mkswap -L swap /dev/nvme0n2p3 # 设置交换分区 mount /dev/nvme0n2p2 /mnt # 将根分区挂载到 /mnt 下 btrfs subvolume create /mnt/root # 创建 root 子卷 btrfs subvolume create /mnt/home # 创建 home 子卷 btrfs subvolume create /mnt/nix # 创建 nix 子卷 umount /mnt # 取消挂载 mount -o compress=zstd,subvol=root /dev/nvme0n2p2 /mnt # 启用透明压缩参数挂载 root 子卷 mkdir /mnt/{home,nix,boot} # 创建 home,nix,boot 目录 mount -o compress=zstd,subvol=home /dev/nvme0n2p2 /mnt/home # 启用透明压缩参数挂载 home 子卷 mount -o compress=zstd,noatime,subvol=nix /dev/nvme0n2p2 /mnt/nix # 启用透明压缩并不记录时间戳参数挂载 nix 子卷 swapon /dev/nvme0n2p3 # 启用交换分区 nixos-generate-config --root /mnt # 生成配置 lsblk -f ``` fileSystems."/" = { device = "/dev/disk/bu-uuid/a3c4d78a-4e74-4c0a-9ecc-680d5f69f042"; fsType = "btrfs"; }; fileSystems."/efi" = { device = "/dev/disk/bu-uuid/a3c4d78a-4e74-4c0a-9ecc-680d5f69f042"; fsType = "vfat"; }; ``` vim /mnt/etc/nixos/configuration.nix # 修改配置 ``` # boot.loader.systemd-boot.enable = true; boot.loader = { efi = { canTouchEfiVariables = true; }; grub = { enable = true; device = "nodev"; efiSupport = true; extraEntries = '' menuentry "Windows" { search --file --no-floppy --set=root /EFI/Microsoft/Boot/bootmgfw.efi chainloader (''${root})/EFI/Microsoft/Boot/bootmgfw.efi } ''; }; }; users.users.fycy = { isNormalUser = true; hashedPassword = "$y$j9T$Fxu0el2kI7FBeSVoL42Sd.$CiW4W73N3dGKdUldBWKuD0zV4fnWLI2n6nbkIMV7GK."; extraGroups = [ "wheel" "users"]; }; networking = { hostName = "nixos"; networkmanager.enable = true; }; time.timeZone = "Asia/Shanghai"; i18n.defaultLocale = "en_US.UTF-8"; services.xserver = { enable = true; displayManager.sddm.enable = true; desktopManager.plasma5.enable = true; }; environment.systemPackages = with pkgs; [ vim alacritty ]; hardware.pulseaudio.enable = true; nix.settings.substituters = [ "https://mirrors.cernet.edu.cn/nix-channels/store" ]; ``` vim /mnt/etc/nixos/hardware-configuration.nix # 编辑硬件配置, 修改一些参数 ``` fileSystem = { "/" = { device = "/dev/disk/bu-uuid/a3c4d78a-4e74-4c0a-9ecc-680d5f69f042"; fsType = "btrfs"; options = [ "subvol=root" "compress=zstd" ]; }; "/home" = { device = "/dev/disk/bu-uuid/a3c4d78a-4e74-4c0a-9ecc-680d5f69f042"; fsType = "btrfs"; options = [ "subvol=home" "compress=zstd" ]; }; "/nix" = { device = "/dev/disk/bu-uuid/a3c4d78a-4e74-4c0a-9ecc-680d5f69f042"; fsType = "btrfs"; options = [ "subvol=nix" "noatime" "compress=zstd" ]; }; "/boot" = { device = "/dev/disk/by-uuid/9DCC-7A56"; fsType = "vfat"; }; }; ``` sudo nixos-install --option extra-substituters "https://mirror.ustc.edu.cn/nix-channels/store" 最后修改:2025 年 01 月 08 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏