mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2024-11-24 17:13:12 +01:00
feat: overlays
This commit is contained in:
parent
dab6820887
commit
d9ec7e117d
@ -1,6 +1,6 @@
|
||||
# The Ingenious Uses of Multiple nixpkgs Instances
|
||||
|
||||
In the section [Downgrade or Upgrade Packages](/nixos-with-flakes/downgrade-or-upgrade-packages.md), we have seen how to instantiate multiple distinct nixpkgs instances using the method `import nixpkgs {...}`. There are numerous applications for this technique, some common ones include:
|
||||
In the section [Downgrade or Upgrade Packages](../nixos-with-flakes/downgrade-or-upgrade-packages.md), we have seen how to instantiate multiple distinct nixpkgs instances using the method `import nixpkgs {...}`. There are numerous applications for this technique, some common ones include:
|
||||
|
||||
1. Instantiate nixpkgs instances with different commit IDs to install various versions of software packages. This approach was used in the previous section [Downgrade or Upgrade Packages](/nixos-with-flakes/downgrade-or-upgrade-packages.md).
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
# Overlays
|
||||
|
||||
In the previous section, we learned about overriding derivations using the `override` function.
|
||||
However, this approach will generate a new derivation and doesn't modify the original derivation in `pkgs` instance.
|
||||
To globally modify derivations in the detault `pkgs` instance, Nix provides a feature called "overlays".
|
||||
In the previous section, we learned about overriding derivations by `pkgs.xxx.override { ... }` or `pkgs.xxx.overrideAttrs (finalAttrs: previousAttrs: { ... });`.
|
||||
However, this approach will generate a new derivation and doesn't modify the original derivation in `pkgs` instance.
|
||||
If the derivation you want to override is also used by other Nix packages, they will still use the unmodified derivation.
|
||||
|
||||
To globally modify derivations in the detault nixpkgs instance, Nix provides a feature called "overlays".
|
||||
|
||||
In traditional Nix environments, overlays can be configured globally using the `~/.config/nixpkgs/overlays.nix` or `~/.config/nixpkgs/overlays/*.nix` files.
|
||||
However, with Flakes feature, to ensure system reproducibility, overlays cannot rely on configurations outside of the Git repository.
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Overlays
|
||||
|
||||
前面介绍的 override 函数会生成一个新的 Derivation,因此它不会修改 pkgs 实例中原有的 Derivation,只适合作为局部参数使用。
|
||||
前面介绍的 `pkgs.xxx.override { ... }` 跟 `pkgs.xxx.overrideAttrs (finalAttrs: previousAttrs: { ... });` 都不会修改 pkgs 实例中原有的 Derivation,而是返回一个新的 Derivation,因此它们只适合作为局部参数使用。
|
||||
但如果你需要覆写的 Derivation 还被其他 Nix 包所依赖,那其他 Nix 包使用的仍然会是未被修改的 Derivation.
|
||||
|
||||
为了解决这个问题,Nix 提供了 overlays 这个功能。
|
||||
|
Loading…
Reference in New Issue
Block a user