git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #44104 from erikarvstedt/python-docs

python docs: improve override examples

commit443cbd782c252a12c4bdaa1f8dc35d7bcee8900a authorFrederik Rietdijk <freddyrietdijk@fridh.nl> dateThu 26 Jul 2018, 13:18 (8 years ago) parent8e668dcfa01100
1 file changed+28−16
doc/languages-frameworks/python.section.md+28−16
doc/languages-frameworks/python.section.md+28−16
@@ -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 {
1014− url = "https://github.com/bepasty/bepasty-server";
1015− sha256 = "9ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
1016− rev = "e2516e8cf4f2afb5185337073607eb9e84a61d2d";
1009+ nixpkgs.config.packageOverrides = super: {
1010+ python = super.python.override {
1011+ packageOverrides = python-self: python-super: {
1012+ zerobin = python-super.zerobin.overrideAttrs (oldAttrs: {
1013+ src = super.fetchgit {
1014+ url = "https://github.com/sametmax/0bin";
1015+ rev = "a344dbb18fe7a855d0742b9a1cede7ce423b34ec";
1016+ sha256 = "16d769kmnrpbdr0ph0whyf4yff5df6zi4kmwx7sz1d3r6c8p6xji";
10171017 };
10181018 });
10191019 };
@@ -1021,27 +1021,39 @@ 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+`pythonPackages.zerobin` is now globally overriden. All packages and also the
1025+`zerobin` NixOS service use the new definition.
1026+Note that `python-super` refers to the old package set and `python-self`
1027+to the new, overridden version.
1028+
1029+To modify only a Python package set instead of a whole Python derivation, use this snippet:
1030+
1031+```nix
1032+ myPythonPackages = pythonPackages.override {
1033+ overrides = self: super: {
1034+ zerobin = ...;
1035+ };
1036+ }
1037+```
10251038
10261039### How to override a Python package using overlays?
10271040
1028−To alter a python package using overlays, you would use the following approach:
1041+Use the following overlay template:
10291042
10301043```nix
10311044self: super:
10321045{
10331046 python = super.python.override {
10341047 packageOverrides = python-self: python-super: {
1035− bepasty-server = python-super.bepasty-server.overrideAttrs ( oldAttrs: {
1036− src = self.pkgs.fetchgit {
1037− url = "https://github.com/bepasty/bepasty-server";
1038− sha256 = "9ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
1039− rev = "e2516e8cf4f2afb5185337073607eb9e84a61d2d";
1048+ zerobin = python-super.zerobin.overrideAttrs (oldAttrs: {
1049+ src = super.fetchgit {
1050+ url = "https://github.com/sametmax/0bin";
1051+ rev = "a344dbb18fe7a855d0742b9a1cede7ce423b34ec";
1052+ sha256 = "16d769kmnrpbdr0ph0whyf4yff5df6zi4kmwx7sz1d3r6c8p6xji";
10401053 };
10411054 });
10421055 };
10431056 };
1044− pythonPackages = self.python.pkgs;
10451057}
10461058```
10471059