NixOS & nixpkg包管理器使用体验

更换国内镜像

NixOS

以优先选择镜像,备选源站为例,选择以下配置之一:

  • 单独安装的 Nix:编辑配置文件添加或修改如下项(通常系统配置在 /etc/nix/nix.conf,用户配置在 ~/.config/nix/nix.conf):

      substituters = https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store https://cache.nixos.org/
    
  • NixOS 21.11 及之前的版本在 configuration.nix 中使用如下配置(https://cache.nixos.org 会被自动添加)

      nix.binaryCaches = [ "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" ];
    
  • NixOS 22.05 及之后的版本在 configuration.nix 中使用如下配置(https://cache.nixos.org 会被自动添加):

      nix.settings.substituters = [ "https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store" ];
    

Nixpkgs channel

Channel 的镜像位于 https://mirrors.tuna.tsinghua.edu.cn/nix-channels/ 目录下,使用方式与 https://nixos.org/channels/ 相同。

单独安装的 Nix 替换 nixpkgs-unstable 命令如下:

$ nix-channel --add https://mirrors.tuna.tsinghua.edu.cn/nix-channels/nixpkgs-unstable nixpkgs
$ nix-channel --update

替换 NixOS channel 命令如下(以 root 执行,将 19.09 替换为系统版本):

# nix-channel --add https://mirrors.tuna.tsinghua.edu.cn/nix-channels/nixos-19.09 nixos
# nix-channel --update

升级系统

sudo nixos-rebuild switch --upgrade

安装应用

常规标准方式

使用configuration或者Home Manager来安装

搜索网站地址:https://search.nixos.org/options

  1. Search and use a exists module to install your packages
  2. Search and install a single package

修改/etc/nixos/configuration.nix

在environment.systemPackages属性下增加包名

然后运行

sudo nixos-rebuild switch

临时使用某个包

nix-shell

命令行管理包

nix profile install nixpkgs#<packagename>

尽量不要用nix-env  https://stop-using-nix-env.privatevoid.net/

 

posted @ 2022-08-16 23:46  风吹过的绿洲  阅读(1520)  评论(0编辑  收藏  举报