1# Customising Packages {#sec-customising-packages}
2
3Some packages in Nixpkgs have options to enable or disable optional
4functionality or change other aspects of the package. For instance, the
5Firefox wrapper package (which provides Firefox with a set of plugins
6such as the Adobe Flash player) has an option to enable the Google Talk
7plugin. It can be set in `configuration.nix` as follows:
8`nixpkgs.config.firefox.enableGoogleTalkPlugin = true;`
9
10::: {.warning}
11Unfortunately, Nixpkgs currently lacks a way to query available
12configuration options.
13:::
14
15Apart from high-level options, it's possible to tweak a package in
16almost arbitrary ways, such as changing or disabling dependencies of a
17package. For instance, the Emacs package in Nixpkgs by default has a
18dependency on GTK 2. If you want to build it against GTK 3, you can
19specify that as follows:
20
21```nix
22environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ];
23```
24
25The function `override` performs the call to the Nix function that
26produces Emacs, with the original arguments amended by the set of
27arguments specified by you. So here the function argument `gtk` gets the
28value `pkgs.gtk3`, causing Emacs to depend on GTK 3. (The parentheses
29are necessary because in Nix, function application binds more weakly
30than list construction, so without them,
31[](#opt-environment.systemPackages)
32would be a list with two elements.)
33
34Even greater customisation is possible using the function
35`overrideAttrs`. While the `override` mechanism above overrides the
36arguments of a package function, `overrideAttrs` allows changing the
37*attributes* passed to `mkDerivation`. This permits changing any aspect
38of the package, such as the source code. For instance, if you want to
39override the source code of Emacs, you can say:
40
41```nix
42environment.systemPackages = [
43 (pkgs.emacs.overrideAttrs (oldAttrs: {
44 name = "emacs-25.0-pre";
45 src = /path/to/my/emacs/tree;
46 }))
47];
48```
49
50Here, `overrideAttrs` takes the Nix derivation specified by `pkgs.emacs`
51and produces a new derivation in which the original's `name` and `src`
52attribute have been replaced by the given values by re-calling
53`stdenv.mkDerivation`. The original attributes are accessible via the
54function argument, which is conventionally named `oldAttrs`.
55
56The overrides shown above are not global. They do not affect the
57original package; other packages in Nixpkgs continue to depend on the
58original rather than the customised package. This means that if another
59package in your system depends on the original package, you end up with
60two instances of the package. If you want to have everything depend on
61your customised instance, you can apply a *global* override as follows:
62
63```nix
64nixpkgs.config.packageOverrides = pkgs:
65 { emacs = pkgs.emacs.override { gtk = pkgs.gtk3; };
66 };
67```
68
69The effect of this definition is essentially equivalent to modifying the
70`emacs` attribute in the Nixpkgs source tree. Any package in Nixpkgs
71that depends on `emacs` will be passed your customised instance.
72(However, the value `pkgs.emacs` in `nixpkgs.config.packageOverrides`
73refers to the original rather than overridden instance, to prevent an
74infinite recursion.)