NixOS & nixpkg包管理器使用体验

2022/8/17 6:23:09

本文主要是介绍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/

 



这篇关于NixOS & nixpkg包管理器使用体验的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程