Functions reference
The nixpkgs repository has several utility functions to manipulate Nix expressions.
pkgs.overridePackages
This function inside the nixpkgs expression (pkgs)
can be used to override the set of packages itself.
Warning: this function is expensive and must not be used from within
the nixpkgs repository.
Example usage:
let
pkgs = import <nixpkgs> {};
newpkgs = pkgs.overridePackages (self: super: {
foo = super.foo.override { ... };
};
in ...
The resulting newpkgs will have the new foo
expression, and all other expressions depending on foo will also
use the new foo expression.
The behavior of this function is similar to config.packageOverrides.
The self parameter refers to the final package set with the
applied overrides. Using this parameter may lead to infinite recursion if not
used consciously.
The super parameter refers to the old package set.
It's equivalent to pkgs in the above example.
<pkg>.override
The function override is usually available for all the
derivations in the nixpkgs expression (pkgs).
It is used to override the arguments passed to a function.
Example usages:
pkgs.foo.override { arg1 = val1; arg2 = val2; ... }pkgs.overridePackages (self: super: {
foo = super.foo.override { barSupport = true ; };
})mypkg = pkgs.callPackage ./mypkg.nix {
mydep = pkgs.mydep.override { ... };
})
In the first example, pkgs.foo is the result of a function call
with some default arguments, usually a derivation.
Using pkgs.foo.override will call the same function with
the given new arguments.
<pkg>.overrideDerivation
The function overrideDerivation is usually available for all the
derivations in the nixpkgs expression (pkgs).
It is used to create a new derivation by overriding the attributes of
the original derivation according to the given function.
Example usage:
mySed = pkgs.gnused.overrideDerivation (oldAttrs: {
name = "sed-4.2.2-pre";
src = fetchurl {
url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;
sha256 = "11nq06d131y4wmf3drm0yk502d2xc6n5qy82cg88rb9nqd2lj41k";
};
patches = [];
});
In the above example, the name, src and patches of the derivation
will be overridden, while all other attributes will be retained from the
original derivation.
The argument oldAttrs is used to refer to the attribute set of
the original derivation.
lib.makeOverridable
The function lib.makeOverridable is used make the result
of a function easily customizable. This utility only makes sense for functions
that accept an argument set and return an attribute set.
Example usage:
f = { a, b }: { result = a+b; }
c = lib.makeOverridable f { a = 1; b = 2; }
The variable c is the value of the f function
applied with some default arguments. Hence the value of c.result
is 3, in this example.
The variable c however also has some additional functions, like
c.override which can be used to
override the default arguments. In this example the value of
(c.override { a = 4; }).result is 6.