nixos基础安装 和带桌面安装

本文不再更新,建议查看 https://dev.leiyanhui.com/nixos/start/

硬盘

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
echo -e "mklabel gpt \nmkpart ESP fat32 1MiB 512MiB \nset 1 esp on \nmkpart primary 512MiB 100% \nquit" | parted  /dev/nvme0n1
mkfs.fat -F 32 /dev/nvme0n1p1
#dosfslabel /dev/nvme0n1p1 EFI
mkfs.btrfs -L NIXOS /dev/nvme0n1p2
mount /dev/nvme0n1p2 /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/nvme0n1p2  /mnt  # 启用透明压缩参数挂载 root 子卷
mkdir /mnt/{home,nix,boot}  # 创建 home,nix,boot 目录
mount -o compress=zstd,subvol=home /dev/nvme0n1p2 /mnt/home  # 启用透明压缩参数挂载 home 子卷
mount -o compress=zstd,noatime,subvol=nix /dev/nvme0n1p2 /mnt/nix  # 启用透明压缩并不记录时间戳参数挂载 nix 子卷
mount /dev/nvme0n1p1 /mnt/boot  # 挂载 boot
nixos-generate-config --root /mnt 
cd /mnt/etc/nixos/
sed -i 's/ \[ "subvol=root" \]/ \[ "subvol=nix" "compress=zstd" \]/g' hardware-configuration.nix
sed -i 's/ \[ "subvol=home" \]/ \[ "subvol=nix" "compress=zstd" \]/g' hardware-configuration.nix
sed -i 's/ \[ "subvol=nix" \]/ \[ "subvol=nix" "compress=zstd" "noatime" \]/g' hardware-configuration.nix

configuration.nix base with zsh

 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
{ config, lib, pkgs, ... }:

{
  imports =
    [ 
      ./hardware-configuration.nix
    ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  nix.settings.substituters = [ "https://mirrors.ustc.edu.cn/nix-channels/store" ];
  nixpkgs.config.allowUnfree = true;
  networking.hostName = "nixos"; # Define your hostname.
  time.timeZone = "Asia/Shanghai";
  virtualisation.vmware.guest.enable = true;

  sound.enable = true;
  users.mutableUsers = false; # 禁止useradd添加用户
  #security.sudo.wheelNeedsPassword = false;
  users.users.yh= { #用户名是yh
      isNormalUser = true;
      hashedPassword = "$y$j9T$I9BXOYYJGTV/Yx5hM7YmJ/$0Mhrve6QTJW4qZtBHRqUG7dJnXWRmdjwkFkNMM0ARA3";
      extraGroups = [
        "wheel"
        "users"
      ];
    };

  environment.systemPackages = with pkgs; [
      wget
      curl
      unzip
      zsh
      wqy_zenhei
    ];

 services.openssh.enable = true;
 users.users.root.openssh.authorizedKeys.keys = [
  "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDwkV1nzSvgoklrfinn8BzxveOPd0UPY1sYwwMMMQrjoAih1PZldT8LcA6zqUsERLXGHf2qy1gSdMFomAAejDEo1aU0PmaGGX4+LWgvlH2xvr3MlbItWLwbXYQdhsfqKu93Qnt7aODJ1Ts2kzp7CP1yR1O4BFUemfnPMVyj07Vj70yg1nDPIXxCPzcMEsJ1OGUduCaDqNA8Ag+TmSSCM+E9rEgMEAcRqpziQYeUEU/RASRYPDeDj5kE81qcDDhseknTFGGa99yZU1R+zuVh4IQEZnr0rZbty0noRFU4AFgMxKaMXwrusjOoX62pEQ0KKU7+pJoKgzVNSFDwt7j50PgOXCue3cqi3Rf4zMpVPkrJP2V+ELR44i/PNHP0GflaNU0RumX8jwScqxMT/NOAdsPs5fRIiUocDXASypjM/2dpJ9wlmmU+ngVFba316Q1kff1LQ0NH5kmKs5DDmL+vbC8wcWuwVuZty2FPJwpdxXK1Oax8GEw4WIM6QjJJ4jqh//k= joyanhui@qq.com"
];

  users.users.yh.openssh.authorizedKeys.keys = [
    "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDwkV1nzSvgoklrfinn8BzxveOPd0UPY1sYwwMMMQrjoAih1PZldT8LcA6zqUsERLXGHf2qy1gSdMFomAAejDEo1aU0PmaGGX4+LWgvlH2xvr3MlbItWLwbXYQdhsfqKu93Qnt7aODJ1Ts2kzp7CP1yR1O4BFUemfnPMVyj07Vj70yg1nDPIXxCPzcMEsJ1OGUduCaDqNA8Ag+TmSSCM+E9rEgMEAcRqpziQYeUEU/RASRYPDeDj5kE81qcDDhseknTFGGa99yZU1R+zuVh4IQEZnr0rZbty0noRFU4AFgMxKaMXwrusjOoX62pEQ0KKU7+pJoKgzVNSFDwt7j50PgOXCue3cqi3Rf4zMpVPkrJP2V+ELR44i/PNHP0GflaNU0RumX8jwScqxMT/NOAdsPs5fRIiUocDXASypjM/2dpJ9wlmmU+ngVFba316Q1kff1LQ0NH5kmKs5DDmL+vbC8wcWuwVuZty2FPJwpdxXK1Oax8GEw4WIM6QjJJ4jqh//k= joyanhui@qq.com"
  ];

users.defaultUserShell = pkgs.zsh;
programs.zsh = {
  enable = true;
  enableCompletion = true;
  autosuggestions.enable = true;
  syntaxHighlighting.enable = true;
  shellAliases = {
  };
  #history.size = 10000;
  #history.path = "${config.xdg.dataHome}/zsh/history";
};

  system.stateVersion = "23.11"; 

}

configuration.nix with kde6 and wayfire

 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
82
83
84
{ config, lib, pkgs, ... }:

{
  imports =
    [ 
      ./hardware-configuration.nix
    ];

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  nix.settings.substituters = [ "https://mirrors.ustc.edu.cn/nix-channels/store" ];
  nixpkgs.config.allowUnfree = true;
  networking.hostName = "nixos"; # Define your hostname.
  time.timeZone = "Asia/Shanghai";
  virtualisation.vmware.guest.enable = true;
  i18n.inputMethod = {
      enabled = "fcitx5";
      fcitx5.addons = with pkgs; [
          fcitx5-chinese-addons
          fcitx5-gtk
      ];
  };

  services.xserver.enable = true;
  services.xserver.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma6.enable = true;  


  sound.enable = true;
  users.mutableUsers = false; # 禁止useradd添加用户
  #security.sudo.wheelNeedsPassword = false;
  users.users.yh= { #用户名是yh
      isNormalUser = true;
      hashedPassword = "$y$j9T$I9BXOYYJGTV/Yx5hM7YmJ/$0Mhrve6QTJW4qZtBHRqUG7dJnXWRmdjwkFkNMM0ARA3";
      extraGroups = [
        "wheel"
        "users"
      ];
    };

  environment.systemPackages = with pkgs; [
      wget
      curl
      unzip
      zsh
      ntfs3g
      wqy_zenhei
      kitty
      microsoft-edge
    ];

 services.openssh.enable = true;
 users.users.root.openssh.authorizedKeys.keys = [
  "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDwkV1nzSvgoklrfinn8BzxveOPd0UPY1sYwwMMMQrjoAih1PZldT8LcA6zqUsERLXGHf2qy1gSdMFomAAejDEo1aU0PmaGGX4+LWgvlH2xvr3MlbItWLwbXYQdhsfqKu93Qnt7aODJ1Ts2kzp7CP1yR1O4BFUemfnPMVyj07Vj70yg1nDPIXxCPzcMEsJ1OGUduCaDqNA8Ag+TmSSCM+E9rEgMEAcRqpziQYeUEU/RASRYPDeDj5kE81qcDDhseknTFGGa99yZU1R+zuVh4IQEZnr0rZbty0noRFU4AFgMxKaMXwrusjOoX62pEQ0KKU7+pJoKgzVNSFDwt7j50PgOXCue3cqi3Rf4zMpVPkrJP2V+ELR44i/PNHP0GflaNU0RumX8jwScqxMT/NOAdsPs5fRIiUocDXASypjM/2dpJ9wlmmU+ngVFba316Q1kff1LQ0NH5kmKs5DDmL+vbC8wcWuwVuZty2FPJwpdxXK1Oax8GEw4WIM6QjJJ4jqh//k= joyanhui@qq.com"
];

  users.users.yh.openssh.authorizedKeys.keys = [
    "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDwkV1nzSvgoklrfinn8BzxveOPd0UPY1sYwwMMMQrjoAih1PZldT8LcA6zqUsERLXGHf2qy1gSdMFomAAejDEo1aU0PmaGGX4+LWgvlH2xvr3MlbItWLwbXYQdhsfqKu93Qnt7aODJ1Ts2kzp7CP1yR1O4BFUemfnPMVyj07Vj70yg1nDPIXxCPzcMEsJ1OGUduCaDqNA8Ag+TmSSCM+E9rEgMEAcRqpziQYeUEU/RASRYPDeDj5kE81qcDDhseknTFGGa99yZU1R+zuVh4IQEZnr0rZbty0noRFU4AFgMxKaMXwrusjOoX62pEQ0KKU7+pJoKgzVNSFDwt7j50PgOXCue3cqi3Rf4zMpVPkrJP2V+ELR44i/PNHP0GflaNU0RumX8jwScqxMT/NOAdsPs5fRIiUocDXASypjM/2dpJ9wlmmU+ngVFba316Q1kff1LQ0NH5kmKs5DDmL+vbC8wcWuwVuZty2FPJwpdxXK1Oax8GEw4WIM6QjJJ4jqh//k= joyanhui@qq.com"
  ];

  programs.wayfire = {
    enable = true;
    plugins = with pkgs.wayfirePlugins; [
      wcm
      wf-shell
      wayfire-plugins-extra
    ];
  };
users.defaultUserShell = pkgs.zsh;
programs.zsh = {
  enable = true;
  enableCompletion = true;
  autosuggestions.enable = true;
  syntaxHighlighting.enable = true;
  shellAliases = {
  };
  #history.size = 10000;
  #history.path = "${config.xdg.dataHome}/zsh/history";
};

  system.stateVersion = "23.11"; 

}

命令

1
2
3
4
5
ix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixpkgs-unstable nixos
nix-channel --update
sudo nixos-rebuild switch --option substituters https://mirrors.ustc.edu.cn/nix-channels/store
cd /mnt
nixos-install --show-trace --option substituters https://mirrors.ustc.edu.cn/nix-channels/store
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计