Unverified Commit fc1f757b authored by github-actions[bot]'s avatar github-actions[bot] Committed by GitHub
Browse files

Merge master into staging-next

parents 3e52e592 99eb0f34
Loading
Loading
Loading
Loading
+5 −39
Original line number Diff line number Diff line
# Multiple-output packages {#chap-multiple-output}

## Introduction {#sec-multiple-outputs-introduction}

The Nix language allows a derivation to produce multiple outputs, which is similar to what is utilized by other Linux distribution packaging systems. The outputs reside in separate Nix store paths, so they can be mostly handled independently of each other, including passing to build inputs, garbage collection or binary substitution. The exception is that building from source always produces all the outputs.

The main motivation is to save disk space by reducing runtime closure sizes; consequently also sizes of substituted binaries get reduced. Splitting can be used to have more granular runtime dependencies, for example the typical reduction is to split away development-only files, as those are typically not needed during runtime. As a result, closure sizes of many packages can get reduced to a half or even much less.
@@ -10,44 +8,12 @@ The main motivation is to save disk space by reducing runtime closure sizes; con
The reduction effects could be instead achieved by building the parts in completely separate derivations. That would often additionally reduce build-time closures, but it tends to be much harder to write such derivations, as build systems typically assume all parts are being built at once. This compromise approach of single source package producing multiple binary packages is also utilized often by rpm and deb.
:::

A number of attributes can be used to work with a derivation with multiple outputs. The attribute `outputs` is a list of strings, which are the names of the outputs. For each of these names, an identically named attribute is created, corresponding to that output. The attribute `meta.outputsToInstall` is used to determine the default set of outputs to install when using the derivation name unqualified.

## Installing a split package {#sec-multiple-outputs-installing}

When installing a package with multiple outputs, the package’s `meta.outputsToInstall` attribute determines which outputs are actually installed. `meta.outputsToInstall` is a list whose [default installs binaries and the associated man pages](https://github.com/NixOS/nixpkgs/blob/f1680774340d5443a1409c3421ced84ac1163ba9/pkgs/stdenv/generic/make-derivation.nix#L310-L320). The following sections describe ways to install different outputs.

### Selecting outputs to install via NixOS {#sec-multiple-outputs-installing-nixos}

NixOS provides two ways to select the outputs to install for packages listed in `environment.systemPackages`:

- The configuration option `environment.extraOutputsToInstall` is appended to each package’s `meta.outputsToInstall` attribute to determine the outputs to install. It can for example be used to install `info` documentation or debug symbols for all packages.

- The outputs can be listed as packages in `environment.systemPackages`. For example, the `"out"` and `"info"` outputs for the `coreutils` package can be installed by including `coreutils` and `coreutils.info` in `environment.systemPackages`.

### Selecting outputs to install via `nix-env` {#sec-multiple-outputs-installing-nix-env}

`nix-env` lacks an easy way to select the outputs to install. When installing a package, `nix-env` always installs the outputs listed in `meta.outputsToInstall`, even when the user explicitly selects an output.
A number of attributes can be used to work with a derivation with multiple outputs.
The attribute `outputs` is a list of strings, which are the names of the outputs.
For each of these names, an identically named attribute is created, corresponding to that output.

::: {.warning}
`nix-env` silently disregards the outputs selected by the user, and instead installs the outputs from `meta.outputsToInstall`. For example,

```ShellSession
$ nix-env -iA nixpkgs.coreutils.info
```

installs the `"out"` output (`coreutils.meta.outputsToInstall` is `[ "out" ]`) instead of the requested `"info"`.
:::

The only recourse to select an output with `nix-env` is to override the package’s `meta.outputsToInstall`, using the functions described in [](#chap-overrides). For example, the following overlay adds the `"info"` output for the `coreutils` package:

```nix
self: super:
{
  coreutils = super.coreutils.overrideAttrs (oldAttrs: {
    meta = oldAttrs.meta // { outputsToInstall = oldAttrs.meta.outputsToInstall or [ "out" ] ++ [ "info" ]; };
  });
}
```
The attribute `meta.outputsToInstall` is used to determine the [default set of outputs to install](https://github.com/NixOS/nixpkgs/blob/08c3198f1c6fd89a09f8f0ea09b425028a34de3e/pkgs/stdenv/generic/check-meta.nix#L411-L426) when using the derivation name unqualified:
`bin`, or `out`, or the first specified output; as well as `man` if that is specified.

## Using a split package {#sec-multiple-outputs-using-split-packages}

+9 −0
Original line number Diff line number Diff line
@@ -2336,6 +2336,15 @@
    github = "blaggacao";
    githubId = 7548295;
  };
  blankparticle = {
    name = "BlankParticle";
    email = "blankparticle@gmail.com";
    github = "BlankParticle";
    githubId = 130567419;
    keys = [{
      fingerprint = "1757 64C3 7065 AA8D 614D  41C9 0ACE 126D 7B35 9261";
    }];
  };
  blanky0230 = {
    email = "blanky0230@gmail.com";
    github = "blanky0230";
+2 −2
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@

- `himalaya` has been updated to `0.8.0`, which drops the native TLS support (in favor of Rustls) and add OAuth 2.0 support. See the [release note](https://github.com/soywod/himalaya/releases/tag/v0.8.0) for more details.

- `nix-prefetch-git` now ignores global and user git config, to improve reproducibility.

- The [services.caddy.acmeCA](#opt-services.caddy.acmeCA) option now defaults to `null` instead of `"https://acme-v02.api.letsencrypt.org/directory"`, to use all of Caddy's default ACME CAs and enable Caddy's automatic issuer fallback feature by default, as recommended by upstream.

- The default priorities of [`services.nextcloud.phpOptions`](#opt-services.nextcloud.phpOptions) have changed. This means that e.g.
@@ -277,8 +279,6 @@ The module update takes care of the new config syntax and the data itself (user

- `services.nginx` gained a `defaultListen` option at server-level with support for PROXY protocol listeners, also `proxyProtocol` is now exposed in `services.nginx.virtualHosts.<name>.listen` option. It is now possible to run PROXY listeners and non-PROXY listeners at a server-level, see [#213510](https://github.com/NixOS/nixpkgs/pull/213510/) for more details.

- `generic-extlinux-compatible` bootloader (and raspberry pi with uboot) supports appending secrets to the initramfs

- `services.restic.backups` now adds wrapper scripts to your system path, which set the same environment variables as the service, so restic operations can easly be run from the command line. This behavior can be disabled by setting `createWrapper` to `false`, per backup configuration.

- `services.prometheus.exporters` has a new exporter to monitor electrical power consumption based on PowercapRAPL sensor called [Scaphandre](https://github.com/hubblo-org/scaphandre), see [#239803](https://github.com/NixOS/nixpkgs/pull/239803) for more details.
+8 −2
Original line number Diff line number Diff line
@@ -116,8 +116,14 @@ in
      extraOutputsToInstall = mkOption {
        type = types.listOf types.str;
        default = [ ];
        example = [ "doc" "info" "devdoc" ];
        description = lib.mdDoc "List of additional package outputs to be symlinked into {file}`/run/current-system/sw`.";
        example = [ "dev" "info" ];
        description = lib.mdDoc ''
          Entries listed here will be appended to the `meta.outputsToInstall` attribute for each package in `environment.systemPackages`, and the files from the corresponding derivation outputs symlinked into {file}`/run/current-system/sw`.

          For example, this can be used to install the `dev` and `info` outputs for all packages in the system environment, if they are available.

          To use specific outputs instead of configuring them globally, select the corresponding attribute on the package derivation, e.g. `libxml2.dev` or `coreutils.info`.
        '';
      };

      extraSetup = mkOption {
+3 −25
Original line number Diff line number Diff line
@@ -70,33 +70,13 @@ copyToKernelsDir() {
addEntry() {
    local path=$(readlink -f "$1")
    local tag="$2" # Generation number or 'default'
    local current="$3" # whether this is the current/latest generation

    if ! test -e $path/kernel -a -e $path/initrd; then
        return
    fi

    if test -e "$path/append-initrd-secrets"; then
        local initrd="$target/nixos/$(basename "$path")-initramfs-with-secrets"
        cp $(readlink -f "$path/initrd") "$initrd"
        chmod 600 "${initrd}"
        chown 0:0 "${initrd}"
        filesCopied[$initrd]=1

        "$path/append-initrd-secrets" "$initrd" || if test "${current}" = "1"; then
            echo "failed to create initrd secrets for the current generation." >&2
            echo "are your \`boot.initrd.secrets\` still in place?" >&2
            exit 1
        else
            echo "warning: failed to create initrd secrets for \"$path\", an older generation" >&2
            echo "note: this is normal after having removed or renamed a file in \`boot.initrd.secrets\`" >&2
        fi
    else
        copyToKernelsDir "$path/initrd"; initrd=$result
    fi

    copyToKernelsDir "$path/kernel"; kernel=$result

    copyToKernelsDir "$path/initrd"; initrd=$result
    dtbDir=$(readlink -m "$path/dtbs")
    if [ -e "$dtbDir" ]; then
        copyToKernelsDir "$dtbDir"; dtbs=$result
@@ -150,20 +130,18 @@ MENU TITLE ------------------------------------------------------------
TIMEOUT $timeout
EOF

addEntry $default default 1 >> $tmpFile
addEntry $default default >> $tmpFile

if [ "$numGenerations" -gt 0 ]; then
    # Add up to $numGenerations generations of the system profile to the menu,
    # in reverse (most recent to least recent) order.
    current=1
    for generation in $(
            (cd /nix/var/nix/profiles && ls -d system-*-link) \
            | sed 's/system-\([0-9]\+\)-link/\1/' \
            | sort -n -r \
            | head -n $numGenerations); do
        link=/nix/var/nix/profiles/system-$generation-link
        addEntry $link $generation $current
        current=0
        addEntry $link $generation
    done >> $tmpFile
fi

Loading