Skip to content

lib.extendMkDerivation: add argument excludeFunctionArgNames and improve argument documentation#459124

Merged
philiptaron merged 4 commits intoNixOS:masterfrom
ShamrockLee:lib-extendMkDerivation-exclude-function-args
Nov 6, 2025
Merged

lib.extendMkDerivation: add argument excludeFunctionArgNames and improve argument documentation#459124
philiptaron merged 4 commits intoNixOS:masterfrom
ShamrockLee:lib-extendMkDerivation-exclude-function-args

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Nov 6, 2025

  • Add an optional excludeFunctionArgNames argument to lib.customisation.extendMkDerivation to remove deprecated/does-not-mean-to-be-specified build helper arguments from __functionArgs.
    • For projects supporting multiple Nixpkgs channels, lib.functionArgs can be used as a way to check whether an argument is supported by a function. For example, nixpkgs-review uses lib.functionArgs to detect if pkgs.buildEnv supports argument ignoreSingleFileOutputs for Nixpkgs revision under review (see PR nix/review_shell.nix: use ignoreSingleFileOutputs whenever available Mic92/nixpkgs-review#427).
    • Deprecated arguments usually need to stay usable for some period of time for backward compatibility purposes, but we want tooling to know early that the support is already dropped. excludeFunctionArgNames provides such mechanism.
  • Improve documentation about the default value of each argument of lib.extendMkDerivation.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 6.topic: lib The Nixpkgs function library labels Nov 6, 2025
@ShamrockLee
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review-gha

Command: nixpkgs-review pr 459124
Commit: bff91748acff531d407a4a69394180bacac54f5e (subsequent changes)
Merge: 5ddc37393b39a48d2a2d71fc9785ad9a4dfd472e

Logs: https://github.com/ShamrockLee/nixpkgs-review-gha/actions/runs/19135188631


x86_64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 3 packages built:
  • extra-container
  • nixos-container
  • nixpkgs-manual

aarch64-linux

⏩ 2 packages blacklisted:
  • nixos-install-tools
  • tests.nixos-functions.nixos-test
✅ 3 packages built:
  • extra-container
  • nixos-container
  • nixpkgs-manual

x86_64-darwin (sandbox = relaxed)

✅ 1 package built:
  • nixpkgs-manual

aarch64-darwin (sandbox = relaxed)

✅ 1 package built:
  • nixpkgs-manual

@MattSturgeon
Copy link
Contributor

I'm curious when this will be useful.

In most cases, we should be able to remove the deprecated arg from the destructured args and instead use { ... }@args: together with args ? deprecated or args.deprecated or "default".

@ShamrockLee
Copy link
Contributor Author

In most cases, we should be able to remove the deprecated arg from the destructured args and instead use { ... }@args: together with args ? deprecated or args.deprecated or \"default\".

Trivial build helpers, fetchers, and special build helpers typically avoid ellipses. The deprecated argument still needs to be present in the set pattern before hard removal.

Without dedicated functionArgs filtering on the lib.extendMkDerivation side, one would need to decorate extendDrvArgs manually, which changes the indentation and creates unnecessarily large diff.

Copy link
Contributor

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some feedback on the doc comment, but most of it predates this PR and can be addressed separately if preferred.

The typo should be addressed, but otherwise the actual changes LGTM.

@philiptaron
Copy link
Contributor

I feel really queasy about backporting this change. Could you make a strong argument for changing/extending the function semantics two months before the branch goes quiescent?

@ShamrockLee
Copy link
Contributor Author

I feel really queasy about backporting this change. Could you make a strong argument for changing/extending the function semantics two months before the branch goes quiescent?

I only thought about build helper backporting when I added the label. I found no "strong arguments" supporting its backport. Let's drop the backporting label.

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % Matt's suggestions about the documentation.

Comment on lines +856 to +861
removeAttrs (
# Inherit the __functionArgs from the base build helper
optionalAttrs inheritFunctionArgs (removeAttrs (functionArgs constructDrv) excludeDrvArgNames)
# Recover the __functionArgs from the derived build helper
// functionArgs (extendDrvArgs { })
) excludeFunctionArgNames
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics here, as I understand them:

  1. If inheritFunctionArgs is set to true (the default)
    a. Whatever the arguments are to constructDrv will be used
    b. Except for those listed in excludeDrvArgNames, which will be excluded.
  2. The arguments for the derived build helper will override that.
    So if constructDrv had an argument without a default, but the derived build helper had a default, the result would have a default.
  3. Finally, no matter where it came from, if an argument is mentioned in the excludeFunctionArgNames list, it will be removed from the function arguments list.

I like those semantics.

@MattSturgeon
Copy link
Contributor

I feel really queasy about backporting this change. Could you make a strong argument for changing/extending the function semantics two months before the branch goes quiescent?

I thought about adding the label myself (before I noticed it was already added).

My argument being that core build helpers should (usually) have a consistent interface across supported releases, so that packages that use them can backport changes relying on said interfaces if needed. This is a semantically trivial change, so I'm comfortable with it being backported.

However, on the flip side, future deprecations that use the new excludeDrvArgNames argument are unlikely to themselves be backported to a nearly-end-of-life release, so I guess we shouldn't need to backport this interface.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 6, 2025
@ShamrockLee ShamrockLee force-pushed the lib-extendMkDerivation-exclude-function-args branch from bff9174 to ab49401 Compare November 6, 2025 15:40
@ShamrockLee ShamrockLee force-pushed the lib-extendMkDerivation-exclude-function-args branch from ab49401 to 3026703 Compare November 6, 2025 15:42
@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Nov 6, 2025
@philiptaron philiptaron added this pull request to the merge queue Nov 6, 2025
Merged via the queue into NixOS:master with commit 9a678d7 Nov 6, 2025
29 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: lib The Nixpkgs function library 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants