Home Explore Blog Models CI



nixpkgs

1st chunk of `nixos/doc/manual/configuration/customizing-packages.section.md`
5856d5c7f2ed746bcafa2cf4833112f5733b0b0c87f351120000000100000891
# Customising Packages {#sec-customising-packages}

The Nixpkgs configuration for a NixOS system is set by the {option}`nixpkgs.config` option.

::::{.example}
# Globally allow unfree packages

```nix
{
  nixpkgs.config = {
    allowUnfree = true;
  };
}
```

:::{.note}
This only allows unfree software in the given NixOS configuration.
For users invoking Nix commands such as [`nix-build`](https://nixos.org/manual/nix/stable/command-ref/nix-build), Nixpkgs is configured independently.
See the [Nixpkgs manual section on global configuration](https://nixos.org/manual/nixpkgs/unstable/#chap-packageconfig) for details.
:::
::::

<!-- TODO(@fricklerhandwerk)
all of the following should go to the Nixpkgs manual, it has nothing to do with NixOS
-->

Some packages in Nixpkgs have options to enable or disable optional functionality, or change other aspects of the package.

::: {.warning}
Unfortunately, Nixpkgs currently lacks a way to query available package configuration options.
:::

::: {.note}
For example, many packages come with extensions one might add.
Examples include:
- [`passExtensions.pass-otp`](https://search.nixos.org/packages?query=passExtensions.pass-otp)
- [`python312Packages.requests`](https://search.nixos.org/packages?query=python312Packages.requests)

You can use them like this:
```nix
{
  environment.systemPackages = with pkgs; [
    sl
    (pass.withExtensions (
      subpkgs: with subpkgs; [
        pass-audit
        pass-otp
        pass-genphrase
      ]
    ))
    (python3.withPackages (subpkgs: with subpkgs; [ requests ]))
    cowsay
  ];
}
```
:::

Apart from high-level options, it's possible to tweak a package in
almost arbitrary ways, such as changing or disabling dependencies of a
package. For instance, the Emacs package in Nixpkgs by default has a
dependency on GTK 2. If you want to build it against GTK 3, you can
specify that as follows:

```nix
{ environment.systemPackages = [ (pkgs.emacs.override { gtk = pkgs.gtk3; }) ]; }
```

The function `override` performs the call to the Nix function that
produces Emacs, with the original arguments amended by the set of
arguments specified by you. So here the function argument `gtk` gets the

Title: Customizing Nixpkgs Packages in NixOS
Summary
This section explains how to customize Nixpkgs packages within a NixOS system. The global configuration for Nixpkgs is set via the `nixpkgs.config` option, allowing adjustments such as enabling unfree packages. It's noted that this configuration applies only to the NixOS system, not to direct user Nix commands. The document also highlights that packages can have options for enabling or disabling features, or adding extensions (e.g., `pass` with `pass-otp`, `python3` with `requests`). Additionally, it demonstrates how to use the `override` function to modify package dependencies, such as building Emacs against GTK 3 instead of GTK 2.