Skip to content

NPV 123

Philip Taron edited this page Feb 16, 2026 · 1 revision

NPV-123: Path expression points outside package directory

Description

Nix files under pkgs/by-name must not contain path expressions that resolve to locations outside the package's own directory. This creates hidden dependencies between internal Nixpkgs paths, making reorganization difficult.

Error message

{relative_package_dir}: File {subpath} at line {line} contains the path expression "{text}" which may point outside the directory of that package.
  This is undesirable because it creates dependencies between internal paths, making it harder to reorganise Nixpkgs in the future.
  Alternatives include:
  - If you are creating a new version of a package with a common file between versions, consider following the recommendation in https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name#recommendation-for-new-packages-with-multiple-versions.
  - If the path being referenced could be considered a stable interface with multiple uses, consider exposing it via a `pkgs` attribute, then taking it as a attribute argument in package.nix.
  - If the path being referenced is internal and has multiple uses, consider passing the file as an explicit `callPackage` argument in `pkgs/top-level/all-packages.nix`.
  - If the path being referenced is internal and will need to be modified independently of the original, consider copying it into the {relative_package_dir} directory.

Example

Given pkgs/by-name/aa/aa/package.nix:

{ someDrv }: someDrv // { escape = ../.; }

The error is:

pkgs/by-name/aa/aa: File package.nix at line 1 contains the path expression "../." which may point outside the directory of that package.
  This is undesirable because it creates dependencies between internal paths, making it harder to reorganise Nixpkgs in the future.
  Alternatives include:
  - If you are creating a new version of a package with a common file between versions, consider following the recommendation in https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name#recommendation-for-new-packages-with-multiple-versions.
  - If the path being referenced could be considered a stable interface with multiple uses, consider exposing it via a `pkgs` attribute, then taking it as a attribute argument in package.nix.
  - If the path being referenced is internal and has multiple uses, consider passing the file as an explicit `callPackage` argument in `pkgs/top-level/all-packages.nix`.
  - If the path being referenced is internal and will need to be modified independently of the original, consider copying it into the pkgs/by-name/aa/aa directory.

How to fix

Follow one of the alternatives listed in the error message:

  1. For multi-version packages, see the pkgs/by-name README recommendation.
  2. Expose shared files as pkgs attributes and take them as package.nix arguments.
  3. Pass the file as an explicit callPackage argument in all-packages.nix.
  4. Copy the file into the package directory if it needs independent modification.

Clone this wiki locally