feat: overlays

This commit is contained in:
Ryan Yin 2024-02-12 17:40:36 +08:00
parent dab6820887
commit d9ec7e117d
3 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,6 @@
# The Ingenious Uses of Multiple nixpkgs Instances # 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. 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).

View File

@ -1,8 +1,10 @@
# Overlays # Overlays
In the previous section, we learned about overriding derivations using the `override` function. 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. 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". 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. 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. However, with Flakes feature, to ensure system reproducibility, overlays cannot rely on configurations outside of the Git repository.

View File

@ -1,6 +1,6 @@
# Overlays # Overlays
前面介绍的 override 函数会生成一个新的 Derivation因此它不会修改 pkgs 实例中原有的 Derivation只适合作为局部参数使用。 前面介绍的 `pkgs.xxx.override { ... }``pkgs.xxx.overrideAttrs (finalAttrs: previousAttrs: { ... });`不会修改 pkgs 实例中原有的 Derivation而是返回一个新的 Derivation因此它们只适合作为局部参数使用。
但如果你需要覆写的 Derivation 还被其他 Nix 包所依赖,那其他 Nix 包使用的仍然会是未被修改的 Derivation. 但如果你需要覆写的 Derivation 还被其他 Nix 包所依赖,那其他 Nix 包使用的仍然会是未被修改的 Derivation.
为了解决这个问题Nix 提供了 overlays 这个功能。 为了解决这个问题Nix 提供了 overlays 这个功能。