Skip to content

config: exclude DeprecatedWarnSetting names from GlobalConfig::toKeyValue()#15820

Open
NorfairKing wants to merge 1 commit into
NixOS:masterfrom
NorfairKing:fix-deprecated-warn-setting-in-nix-config
Open

config: exclude DeprecatedWarnSetting names from GlobalConfig::toKeyValue()#15820
NorfairKing wants to merge 1 commit into
NixOS:masterfrom
NorfairKing:fix-deprecated-warn-setting-in-nix-config

Conversation

@NorfairKing
Copy link
Copy Markdown

Fixes #15819.

Since nix 2.34 (commit 5184f844b), every nix command run inside a post-build-hook emits a spurious deprecation warning:

warning: 'warn-short-path-literals' is deprecated, use 'lint-short-path-literals = ignore' instead

even when the user never set warn-short-path-literals. The cause: DeprecatedWarnSetting registers the deprecated name via addSetting() with isAlias = false, making it a primary setting. Config::getSettings() skips aliases but includes primary settings. GlobalConfig::toKeyValue() calls getSettings() and serialises the result into NIX_CONFIG. The daemon injects this into every post-build-hook subprocess environment (derivation-goal.cc) and into nix repl subprocesses (repl.cc). Any nix command in the hook reads NIX_CONFIG, hits DeprecatedWarnSetting::assign(), and fires the warning.

Fix: add an excludeFromKeyValue flag to Config::SettingData. When set, getSettings() skips the setting, removing it from GlobalConfig::toKeyValue() / NIX_CONFIG. A new Config::excludeSettingFromKeyValue() method (which asserts the name exists, to catch misuse) sets the flag. DeprecatedWarnSetting calls it immediately after addSetting().

This is preferable to making the setting a true alias (isAlias = true), which would also drop the --warn-short-path-literals / --no-warn-short-path-literals CLI flags since convertToArgs() skips aliases. With excludeFromKeyValue, reading the setting from nix.conf / NIX_CONFIG still works and still emits the deprecation warning when explicitly set by the user; CLI flags are unaffected.

A regression test in tests/functional/short-path-literals.sh builds a derivation with a post-build-hook that captures $NIX_CONFIG and asserts warn-short-path-literals is absent.

Note: Root cause analysis and fix were produced with the help of an AI assistant (Claude), reviewed and confirmed against the source code by the author.

…alue()

Since nix 2.34 (commit 5184f84, "New diagnostics infra"), every `nix`
command run inside a post-build-hook emits a spurious deprecation warning:

  warning: 'warn-short-path-literals' is deprecated,
           use 'lint-short-path-literals = ignore' instead

even when the user never set `warn-short-path-literals`. The cause:
`DeprecatedWarnSetting` registers the deprecated name via `addSetting()`
with `isAlias = false`, making it a primary setting. `Config::getSettings()`
skips aliases but includes primary settings. `GlobalConfig::toKeyValue()`
calls `getSettings()` and serialises the result into `NIX_CONFIG`. The
daemon injects this into every post-build-hook subprocess environment
(`derivation-goal.cc`) and into `nix repl` subprocesses (`repl.cc`). Any
`nix` command in the hook then reads `NIX_CONFIG`, hits
`DeprecatedWarnSetting::assign()`, and fires the warning.

Fix: add an `excludeFromKeyValue` flag to `Config::SettingData`. When set,
`getSettings()` skips the setting, removing it from `GlobalConfig::toKeyValue()`
/ `NIX_CONFIG`. A new `Config::excludeSettingFromKeyValue()` method (which
asserts the name exists, to catch misuse) sets the flag. `DeprecatedWarnSetting`
calls it immediately after `addSetting()`.

This is preferable to making the setting a true alias (`isAlias = true`),
which would also drop the `--warn-short-path-literals` /
`--no-warn-short-path-literals` CLI flags since `convertToArgs()` skips
aliases. With `excludeFromKeyValue`, reading the setting from `nix.conf` /
`NIX_CONFIG` still works and still emits the deprecation warning when
explicitly set by the user; CLI flags are unaffected.

Add a regression test in `tests/functional/short-path-literals.sh` that
builds a derivation with a post-build-hook capturing `$NIX_CONFIG` and
asserts `warn-short-path-literals` is absent.

Fixes: NixOS#15819
@NorfairKing NorfairKing requested a review from edolstra as a code owner May 9, 2026 10:11
@github-actions github-actions Bot added the with-tests Issues related to testing. PRs with tests have some priority label May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

with-tests Issues related to testing. PRs with tests have some priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

warn-short-path-literals deprecation warning spuriously emitted in post-build-hook subprocesses via NIX_CONFIG

1 participant