Skip to content

Latest commit

 

History

History
115 lines (78 loc) · 2.54 KB

nix-channels.mdx

File metadata and controls

115 lines (78 loc) · 2.54 KB
title cname
Nix Channels 镜像使用帮助
nix-channels

Nixpkgs binary cache

目前 TUNA/BFSU/USTC 等并未提供 nix-darwin 的 binary cache,请使用官方源或 SJTUG。

持久配置

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

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

    substituters = {{http_protocol}}{{mirror}}/store https://cache.nixos.org/
    
  • NixOS 21.11 及之前的版本在 configuration.nix 中使用如下配置(https://cache.nixos.org 会被自动添加)

    nix.binaryCaches = [ "{{http_protocol}}{{mirror}}/store" ];
  • NixOS 22.05 及之后的版本在 configuration.nix 中使用如下配置(https://cache.nixos.org 会被自动添加):

    nix.settings.substituters = [ "{{http_protocol}}{{mirror}}/store" ];

    如果因为无法访问 https://cache.nixos.org 等原因,希望避免自动添加该默认地址,请在配置中使用lib.mkForce

    # load `lib` into namespace at the file head with `{ config, pkgs, lib, ... }:`
    nix.settings.substituters = lib.mkForce [ "{{http_protocol}}{{mirror}}/store" ];

临时使用

在安装 NixOS 时临时使用:

```shell nixos-install --option substituters "{{http_protocol}}{{mirror}}/store" ```

在 NixOS 切换配置时临时使用:

```shell nixos-rebuild --option substituters "{{http_protocol}}{{mirror}}/store" ```

临时关闭可以通过清空 substituters 实现:

nixos-rebuild --option substituters ""

Nixpkgs channel

注:SJTUG 提供了 binary cache,未提供该镜像。

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

nix-channel --add {{http_protocol}}{{mirror}}/nixpkgs-unstable nixpkgs
nix-channel --update

替换 NixOS channel 命令如下(以 root 执行):

<CodeBlock menus={[ { title: '系统版本', items: [ ['22.11', { version: '22.11' }], ['unstable', { version: 'unstable' }], ['22.05', { version: '22.05' }], ['21.11', { version: '21.11' }], ] } ]}

nix-channel --add {{http_protocol}}{{mirror}}/nixos-{{version}} nixos
nix-channel --update