mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2024-12-30 18:48:50 +01:00
feat: Adding Custom Cache Mirrors
This commit is contained in:
parent
46c78137b9
commit
d24cb2a50c
@ -267,4 +267,26 @@ To customize the cache source, we must add the related configuration in `flake.n
|
||||
}
|
||||
```
|
||||
|
||||
After making the modifications, run `sudo nixos-rebuild switch` to apply the updates.
|
||||
After adding the new substituters, it still won't take effect. In this case, when directly deploying the configuration, you'll encounter the following error:
|
||||
|
||||
```
|
||||
...
|
||||
warning: ignoring untrusted substituter 'https://mirrors.ustc.edu.cn/nix-channels/store', you are not a trusted user.
|
||||
...
|
||||
```
|
||||
|
||||
This is a security limitation of Nix, where only trusted users can properly use the set substituters. Therefore, we need to add our own user to the trusted list. Add the following configuration to any NixOS module:
|
||||
|
||||
```nix{3-4}
|
||||
{
|
||||
# ... (other configurations omitted)
|
||||
|
||||
nix.trustedUsers = [ "ryan" ]; # Add your own username to the trusted list
|
||||
|
||||
# ... (other configurations omitted)
|
||||
}
|
||||
```
|
||||
|
||||
Now, to apply the configuration and make it effective, use `sudo nixos-rebuild switch`.
|
||||
Nix will prioritize searching for cached packages from the domestic mirror source after the switch.
|
||||
|
||||
|
@ -249,7 +249,26 @@ Nix 为了加快包构建速度,提供了 <https://cache.nixos.org> 提前缓
|
||||
# 省略若干配置...
|
||||
};
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
改完后使用 `sudo nixos-rebuild switch` 应用配置即可生效,后续所有的包都会优先从国内镜像源查找缓存。
|
||||
添加完新 substituters 后,它仍然不会失效,这时直接部署配置,会这个报错:
|
||||
|
||||
```
|
||||
...
|
||||
warning: ignoring untrusted substituter 'https://mirrors.ustc.edu.cn/nix-channels/store', you are not a trusted user.
|
||||
...
|
||||
```
|
||||
|
||||
这是 Nix 的安全限制,只有可信用户才能正常使用这里设置好的 substituters,所以我们还需要将自己的用户添加到可信列表中。在任一 NixOS Module 中添加如下配置:
|
||||
|
||||
```nix{3-4}
|
||||
{
|
||||
# 省略若干配置...
|
||||
|
||||
nix.trustedUsers = [ "ryan" ]; # 将自己的用户名添加到可信列表中
|
||||
|
||||
# 省略若干配置...
|
||||
}
|
||||
```
|
||||
|
||||
现在再使用 `sudo nixos-rebuild switch` 应用配置即可生效,后续所有的包都会优先从国内镜像源查找缓存。
|
||||
|
Loading…
Reference in New Issue
Block a user