NixOS(Gnome)安装及配置指南

笔者配置仓库

这篇文章已过时

进入NixOS的LiveCD, 连接网络

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

配置代理

1
2
3
nix-env -iA 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
5
6
mkfs.ext4 /dev/sda3
mkfs.vfat /dev/sda1
mkswap /dev/sda2
swapon /dev/sda2
mount /dev/sda3 /mnt
mount --mkdir /dev/sda1 /mnt/boot

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

安装系统

1
2
nixos-generate-config --root /mnt
gnome-text-editor /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
80
81
{
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 GNOME Desktop Environment.
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.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;
programs.firefox.wrapperConfig = {
pipewireSupport = 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.05"; # Did you read the comment?
}

保存退出后安装系统

1
nixos-install

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

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

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

情况一、QEMU/KVM虚拟机的配置

1
2
v2ray run
sudo v2raya

从此处获得示例虚拟机配置, 编辑/etc/nixos/configuration.nix,
然后输入sudo nixos-rebuild switch一键配置更新系统,重启后输入sudo nix-collect-garbage -d清理旧镜像

情况二、NVIDIA显卡实体机配置

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

克隆配置仓库

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

安装Windows字体

1
2
3
4
cd ~/nixos-config
mkdir ~/.local/share/fonts
cp fonts/*.ttf ~/.local/share/fonts/
fc-cache -fv

安装农历依赖

1
2
3
4
5
cd ~/nixos-config
nix-shell -p unzip --command "unzip ChineseCalendar.zip"
cd ChineseCalendar
chmod +x install.sh
./install.sh

配置zsh

1
2
cd ~/nixos-config
cp zshrc ~/.zshrc

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

1
2
cd ~/nixos-config
sudo cp configuration_nvidia.nix /etc/nixos/configuration.nix && cp home.nix /etc/nixos/home.nix

更新系统配置, 换成Unstable通道

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

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

重启到新系统, 清理垃圾

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

配置新系统

关于Gnome桌面环境的配置此处省略, 可看Manjaro那篇文章

补充说明

  • 实体机安装的是linux-zen内核

  • 下列配置使用nix-shell可以使用clang工具链, 以及Qt应用程序开发:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    with import <nixpkgs> {
    config = {
    allowUnfree = true;
    };
    };
    let
    gccForLibs = stdenv.cc.cc;
    in
    stdenv.mkDerivation {
    name = "llvm-env";
    buildInputs = [
    # clang
    ];

    CPLUS_INCLUDE_PATH = "${gccForLibs}/include/c++/${gccForLibs.version}:${gccForLibs}/include/c++/${gccForLibs.version}/x86_64-unknown-linux-gnu:${gccForLibs}/lib/gcc/x86_64-unknown-linux-gnu/${gccForLibs.version}/include:${stdenv.cc.libc.dev}/include";
    QT_QPA_PLATFORM_PLUGIN_PATH = "${libsForQt5.qt5.qtbase}/lib/qt-${libsForQt5.qt5.qtbase.version}/plugins/platforms";
    shellHook = ''
    echo ${libsForQt5.qt5.qtbase.version};
    '';
    }
  • 关于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开发


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