NixOS(KDE)安装及配置指南

我的配置仓库

进入NixOS的LiveCD, 连接网络

可以使用手机网络共享然后无线连接

配置代理

1
2
3
nix-env -i v2ray v2raya
v2ray run
sudo v2raya

然后进入127.0.0.1:2017导入代理配置

使用cfdisk进行系统分区

1
2
3
sudo -i # 注意:以下操作全部在root用户下进行
lsblk
cfdisk /dev/sda
1
2
3
4
mkfs.xfs -L nixos /dev/sda2
mkfs.vfat /dev/sda1
mount /dev/sda2 /mnt
mount --mkdir /dev/sda1 /mnt/boot

这些步骤跟安装archlinux完全一样, 并使用GUID分区表和UEFI启动方式

安装系统

1
2
nixos-generate-config --root /mnt
kate /mnt/etc/nixos/configuration.nix

用户名以yoimiya为例, 主机名默认即可

示例配置:

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
{
config,
lib,
pkgs,
...
}:
{
imports = [
# Include the results of the hardware scan.
./hardware-configuration.nix
];

# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

networking.hostName = "nixos"; # Define your hostname.
# Pick only one of the below networking options.
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
networking.networkmanager.enable = true; # Easiest to use and most distros use this by default.

# Set your time zone.
time.timeZone = "Asia/Shanghai";

services.xserver.videoDrivers = [ "modesetting" ];

# Select internationalisation properties.
i18n.defaultLocale = "en_US.UTF-8";

# Enable the X11 windowing system.
services.xserver.enable = true;

nixpkgs.config = {
allowUnfree = true;
};

# Enable the KDE Desktop Environment.
services.displayManager.sddm.enable = true;
services.displayManager.sddm.wayland.enable = true;
services.desktopManager.plasma6.enable = true;

# Configure keymap in X11
services.xserver.xkb.layout = "us";
# services.xserver.xkb.options = "eurosign:e,caps:escape";

# Enable CUPS to print documents.
services.printing.enable = true;

# Enable sound.
# hardware.pulseaudio.enable = true;

# Enable touchpad support (enabled default in most desktopManager).
services.libinput.enable = true;

programs.firefox.enable = true;

# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.yoimiya = {
isNormalUser = true;
createHome = true;
home = "/home/yoimiya";
extraGroups = [
"wheel"
"networkmanager"
]; # Enable ‘sudo’ for the user.
packages = with pkgs; [
tree
];
};

environment.systemPackages = with pkgs; [
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
v2ray
v2raya
];

system.stateVersion = "24.11"; # Did you read the comment?
}

保存退出后安装系统

1
nixos-install

安装完成后会要求设置root密码,然后使用

1
nixos-enter --root /mnt -c 'passwd yoimiya'

设置用户密码。设置完成后重启电脑,进入新系统

开始配置

在使用这些的配置之前,确保你理解了配置文件的每一句话,并根据实际情况作了修改

重新配置代理

1
2
v2ray run
sudo v2raya

克隆配置仓库

1
nix-shell -p git --command "git clone https://github.com/Rukkhadevata123/nixos-config"

安装Windows字体

1
2
3
mkdir ~/.local/share/fonts
cp /path/to/windows/fonts ~/.local/share/fonts/
fc-cache -fv

安装主配置文件(根据实际情况修改,请仔细阅读配置的每一行)

1
2
3
4
cd ~/nixos-config
sudo cp configuration.nix /etc/nixos/configuration.nix && sudo cp home.nix /etc/nixos/home.nix
sudo cp flake.nix /etc/nixos/flake.nix
sudo cp -r grubtheme /etc/nixos/grubtheme

更新系统配置, 换成Unstable通道(flake不需要)

1
2
sudo nix-channel --add https://channels.nixos.org/nixos-unstable nixos
sudo nixos-rebuild switch --upgrade

如果出错, 可以尝试sudo systemctl stop nixos-rebuild-switch-to-configuration.service

重启到新系统, 清理垃圾

1
2
sudo nix-collect-garbage -d
bleachbit # 可选

配置新系统

在设置配置KDE桌面环境

补充说明

  • 可以安装linux-zen内核

  • 关于Pycharm无法使用的问题, 手动导入环境变量, 先在终端运行, 然后把完整文本路径导入Pycharm对应位置(不是直接把下面的命令导入Pycharm):

    1
    export LD_LIBRARY_PATH=$(find /nix/store -type d -name '*steam-run-fhs*' -exec echo -n {}'/usr/lib32:'{}'/usr/lib64:' \;)

    IDEA也是一样。如果要使用JavaFx则导入LD_LIBRARY_PATH=/home/yoimiya/javafx-sdk-21.0.5/lib:/nix/store/haci0d018njygwdga95bsbx8ww2iswy7-zlib-1.3.1/lib:/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib:/nix/store/qqfyfd3zq9jqyk9cibz72ir2ws9znl5a-steam-run-fhs/usr/lib32:/nix/store/qqfyfd3zq9jqyk9cibz72ir2ws9znl5a-steam-run-fhs/usr/lib64
    对于虚拟机选项,导入--module-path "/home/yoimiya/javafx-sdk-21.0.5/lib" --add-modules javafx.controls,javafx.fxml

  • Gnome的新终端Console可以用命令kgx --tab打开

  • nix-shell -p ncurses5 flex bison elfutils openssl此配置可以用于内核编译

  • nix-shell -p gtk4 gtk3 pkg-config此配置用于rust-gtk开发

  • 获取软件包列表 nix-env -qaP --description > pkglist.txt

  • 其他补充说明请查看仓库中的配置文件


NixOS(KDE)安装及配置指南
https://rukkhadevata123.github.io/2024/10/25/nixos/
作者
Dawn Chirps
发布于
2024年10月25日
许可协议