I want to override a package in nixpkgs, and ship this override to other developers or users.
How?
- Provide package changes
- “Overlayed” onto an existing package source (e.g.
nixpkgs
) - Allow for local, or organisation-wide overrides
- Implemented as a function
self: super: {
htop = self.callPackage ./patches/htop { inherit (super) htop; };
}
file:imgs/overlays1.png
(enjoy some drawings from my eInk tablet)
file:imgs/overlays2.png
file:imgs/overlays3.png
file:imgs/overlays4.png
self
is sometimes also calledfinal
super
is sometimes also calledprev
self: super: {
htop = builtins.trace "Overriding the htop package" super.htop;
}
Useful for personal or organisation-wide packages.
self: super: {
my-hello = self.writeShellScript "my-hello" ''
${self.bash}/bin/bash
${self.hello}/bin/hello | ${self.cowsay}/bin/cowsay
'';
}
❤ (theia) s/overlays> tree patches
patches/
└── htop
├── 0001-htop-untruncated-username.patch
└── default.nix
self: super: {
htop = self.callPackage ./patches/htop { inherit (super) htop; };
}
Quiz: why do we inherit from super
to pass htop
?
- Don’t define a new package, override parts of the existing one
- Include as many other depedencies as you need
- Then include patches, or change build steps
{ htop }:
htop.overrideAtts ({ patches ? [], ... }: {
patches = patches ++ [ ./0001-htop-untruncated-username.patch ];
})
- Required to make
nix-shell
use the overlay - Means the overlay needs to stick around at runtime
- and things break if you move/ delete it!
export NIX_PATH="$NIX_PATH:nixpkgs-overlays=/path/to/overlay"
- When loading
<nixpkgs>
you can provide various parameters - One of them is the
overlays
key, which accepts a list - Alternatively: define
load-nixpkgs.nix
, and load that instead
# load-nixpkgs.nix
{ overlays ? [], ... } @ args:
import <nixpkgs> (args // {
overlays = overlays ++ [ (import ./overlay) ];
});
❤ (theia) ~> nix build -f load-nixpkgs.nix htop
... build the patched htop ...
Create an in-line overlay to override a certain package
import <nixpkgs> ({
overlays = [
(self: super: {
htop = builtins.trace "htop in the overlay" super.htop;
})
];
})