How to change a package without having to re-write it yourself?
Overrides!
override
andoverrideAttr
are special functions implemented around derivations- An example from day 1:
pkgs.wine.override { ... }
- What’s their difference?
- Specific to each package
- Acts on the derivation output
with import <nixpkgs> {};
{
my-git = pkgs.git.override {
svnSupport = true;
sendEmailSupport = true;
};
}
❤ (theia) ~> nix-build ./override.nix
this derivation will be built:
/nix/store/rn2qbgzkc4b8h7zsflhdyn9rhsjy0mp1-git-with-svn-2.38.1.drv
building '/nix/store/rn2qbgzkc4b8h7zsflhdyn9rhsjy0mp1-git-with-svn-2.38.1.drv'...
...
- Generic for all* derivations
- Acts on the inputs to
mkDerivation
- It therefore allows much more generic overrides
*any derivation which is wrapped in ‘makeOverridable’
overrideAttrs
takes a function which takes an attribute set and
returns an attribute set. Only changed keys should be returned.
some-package.overrideAttrs { ... }: { /* ... */ }
htop.overrideAttrs ({ patches ? [], nativeBuildInputs ? [], postConfigure ? "", ... }: {
patches = patches ++ [ ./0001-htop-untruncated-username.patch ];
})
stdenv.mkDerivation (finalAttrs: {
pname = "memtest86+";
version = "6.00";
src = fetchFromGitHub {
owner = "memtest86plus";
repo = "memtest86plus";
rev = "v${finalAttrs.version}";
hash = "sha256-m9oGLXTCaE5CgA4o8MGdjQTQSz/j8kC9BJ84RVcBZjs=";
};
# ...
}
- Extremely special function which is very rarely useful
- Override attributes that
mkDerivation
passes toderivation
- You might see this in some places but you probably don’t need/ want to use it!