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.
5
6::: {.warning}
7Unfortunately, Nixpkgs currently lacks a way to query available
8configuration options.
9:::
10
11::: {.note}
12For example, many packages come with extensions one might add.
13Examples include:
14- [`passExtensions.pass-otp`](https://search.nixos.org/packages/query=passExtensions.pass-otp)
15- [`python310Packages.requests`](https://search.nixos.org/packages/query=python310Packages.requests)
16
17You can use them like this:
18```nix
19environment.systemPackages = with pkgs; [
20 sl
21 (pass.withExtensions (subpkgs: with subpkgs; [
22 pass-audit
23 pass-otp
24 pass-genphrase
25 ]))
26 (python3.withPackages (subpkgs: with subpkgs; [
27 requests
28 ]))
29 cowsay
30];
31```
32:::
33
34Apart from high-level options, it's possible to tweak a package in
35almost arbitrary ways, such as changing or disabling dependencies of a
36package. For instance, the Emacs package in Nixpkgs by default has a
37dependency on GTK 2. If you want to build it against GTK 3, you can
38specify that as follows:
39
40```nix
41environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ];
42```
43
44The function `override` performs the call to the Nix function that
45produces Emacs, with the original arguments amended by the set of
46arguments specified by you. So here the function argument `gtk` gets the
47value `pkgs.gtk3`, causing Emacs to depend on GTK 3. (The parentheses
48are necessary because in Nix, function application binds more weakly
49than list construction, so without them,
50[](#opt-environment.systemPackages)
51would be a list with two elements.)
52
53Even greater customisation is possible using the function
54`overrideAttrs`. While the `override` mechanism above overrides the
55arguments of a package function, `overrideAttrs` allows changing the
56*attributes* passed to `mkDerivation`. This permits changing any aspect
57of the package, such as the source code. For instance, if you want to
58override the source code of Emacs, you can say:
59
60```nix
61environment.systemPackages = [
62 (pkgs.emacs.overrideAttrs (oldAttrs: {
63 name = "emacs-25.0-pre";
64 src = /path/to/my/emacs/tree;
65 }))
66];
67```
68
69Here, `overrideAttrs` takes the Nix derivation specified by `pkgs.emacs`
70and produces a new derivation in which the original's `name` and `src`
71attribute have been replaced by the given values by re-calling
72`stdenv.mkDerivation`. The original attributes are accessible via the
73function argument, which is conventionally named `oldAttrs`.
74
75The overrides shown above are not global. They do not affect the
76original package; other packages in Nixpkgs continue to depend on the
77original rather than the customised package. This means that if another
78package in your system depends on the original package, you end up with
79two instances of the package. If you want to have everything depend on
80your customised instance, you can apply a *global* override as follows:
81
82```nix
83nixpkgs.config.packageOverrides = pkgs:
84 { emacs = pkgs.emacs.override { gtk = pkgs.gtk3; };
85 };
86```
87
88The effect of this definition is essentially equivalent to modifying the
89`emacs` attribute in the Nixpkgs source tree. Any package in Nixpkgs
90that depends on `emacs` will be passed your customised instance.
91(However, the value `pkgs.emacs` in `nixpkgs.config.packageOverrides`
92refers to the original rather than overridden instance, to prevent an
93infinite recursion.)