git.iko.soy/typeable/nixpkgs
on master help sign in
python docs: improve override example

1. Use the same approach like in the overlay example: Override `python` instead of `pythonPackages` so that `python.pkgs` refers to the new package set like `pythonPackages`. This also fixes a bug in the original example where `pkgs.fetchgit` was not in scope. Add an extra example to illustrate how to override just a package set. 2. Fix mix-up between `super` and `self` in the explanation text. Also, simplify the explanation.

commit42e3727aa2bfbac5a13396fef388324fbb3f080c authorErik Arvstedt <erik.arvstedt@gmail.com> dateWed 25 Jul 2018, 21:29 (8 years ago) parenta8f5497
1 file changed+21−9
doc/languages-frameworks/python.section.md+21−9
doc/languages-frameworks/python.section.md+21−9
@@ -1006,14 +1006,14 @@ folder and not downloaded again.
10061006If you need to change a package's attribute(s) from `configuration.nix` you could do:
10071007
10081008```nix
1009− nixpkgs.config.packageOverrides = superP: {
1010− pythonPackages = superP.pythonPackages.override {
1011− overrides = self: super: {
1012− bepasty-server = super.bepasty-server.overrideAttrs ( oldAttrs: {
1013− src = pkgs.fetchgit {
1009+ nixpkgs.config.packageOverrides = super: {
1010+ python = super.python.override {
1011+ packageOverrides = python-self: python-super: {
1012+ bepasty-server = python-super.bepasty-server.overrideAttrs (oldAttrs: {
1013+ src = super.fetchgit {
10141014 url = "https://github.com/bepasty/bepasty-server";
1015− sha256 = "9ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
10161015 rev = "e2516e8cf4f2afb5185337073607eb9e84a61d2d";
1016+ sha256 = "9ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
10171017 };
10181018 });
10191019 };
@@ -1021,11 +1021,23 @@ If you need to change a package's attribute(s) from `configuration.nix` you coul
10211021 };
10221022```
10231023
1024−If you are using the `bepasty-server` package somewhere, for example in `systemPackages` or indirectly from `services.bepasty`, then a `nixos-rebuild switch` will rebuild the system but with the `bepasty-server` package using a different `src` attribute. This way one can modify `python` based software/libraries easily. Using `self` and `super` one can also alter dependencies (`buildInputs`) between the old state (`self`) and new state (`super`).
1024+If you are using the `bepasty-server` package somewhere, for example in `systemPackages` or indirectly from `services.bepasty`, then a `nixos-rebuild switch` will rebuild the system but with the `bepasty-server` package using a different `src` attribute. This way one can modify `python` based software/libraries easily.
1025+Note that `python-super` refers to the old package set and `python-self`
1026+to the new, overridden version.
1027+
1028+To modify only a Python package set instead of a whole Python derivation, use this snippet:
1029+
1030+```nix
1031+ myPythonPackages = pythonPackages.override {
1032+ overrides = self: super: {
1033+ bepasty-server = ...;
1034+ };
1035+ }
1036+```
10251037
10261038### How to override a Python package using overlays?
10271039
1028−To alter a python package using overlays, you would use the following approach:
1040+Use the following overlay template:
10291041
10301042```nix
10311043self: super:
@@ -1035,8 +1047,8 @@ self: super:
10351047 bepasty-server = python-super.bepasty-server.overrideAttrs (oldAttrs: {
10361048 src = self.pkgs.fetchgit {
10371049 url = "https://github.com/bepasty/bepasty-server";
1038− sha256 = "9ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
10391050 rev = "e2516e8cf4f2afb5185337073607eb9e84a61d2d";
1051+ sha256 = "9ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
10401052 };
10411053 });
10421054 };