(入门安装 2 使用 flakes)nixos 从0实现全集 梦中情os

基本按照

在想使用flakes之前你最好对nixos有初步的了解,知道 configuration.nix 的基本配置 基础安装参考

这里只需要修改 configuration.nix 添加一行 nix.settings.experimental-features = [ "nix-command" "flakes" ]; 另外编辑一下或者记录一下 hostname networking.hostName = "vm-nixos"; 因为 flakes可以根据不同的hostname做不同的配置

基本的 flake.nix

创建一个 flake.nix 如果你是按照前文新安装的 那么 路径应该是 /mnt/etc/nixos/flake.nix 否则是 /etc/nixos/flake.nix

1
2
3
4
5
6
7
8
9
{
  outputs = { self, nixpkgs }: {
    # replace 'vm-nixo' with your hostname here.
    nixosConfigurations.vm-nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [ ./configuration.nix ];
    };
  };
}

这里大概的意思 是 再跳转回去 configuration.nix 这样就可以 继续使用原来的 配置。

修改后的configuration.nix

参考

 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
 cat /etc/nixos/configuration.nix 
{ config, lib, pkgs, ... }:

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

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

  nix.settings.substituters = [ "https://mirror.sjtu.edu.cn/nix-channels/store" ];
  nixpkgs.config.allowUnfree = true;
  networking.hostName = "vm-nixos"; # Define your hostname.
  nix.settings.experimental-features = [ "nix-command" "flakes" ];

  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 = "XXXXX";
      extraGroups = [
        "wheel"
        "users"
      ];
    };

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

 services.openssh.enable = true;
 users.users.root.openssh.authorizedKeys.keys = [
  "XXXXX joyanhui@qq.com"
];

  users.users.yh.openssh.authorizedKeys.keys = [
  "XXXXX joyanhui@qq.com"
  ];


  system.stateVersion = "23.11"; 

}

构建

1
sudo nixos-rebuild switch --option substituters https://mirror.sjtu.edu.cn/nix-channels/store

也可以 # 后面是hostname

1
sudo nixos-rebuild switch  --flake '/etc/nixos#vm-nixos'  --option substituters https://mirror.sjtu.edu.cn/nix-channels/store

如果是新安装的 要直接启用flake 一般必须使用 –flake 因为livecd的hostname和你配置文件的不一样的哦

1
nixos-install --show-trace  --flake '/mnt/etc/nixos#vm-nixos' --option substituters https://mirror.sjtu.edu.cn/nix-channels/store

进阶 flake.nix 和 Home Manager

Home Manager

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计