config: exclude DeprecatedWarnSetting names from GlobalConfig::toKeyValue()#15820
Open
NorfairKing wants to merge 1 commit into
Open
config: exclude DeprecatedWarnSetting names from GlobalConfig::toKeyValue()#15820NorfairKing wants to merge 1 commit into
NorfairKing wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15819.
Since nix 2.34 (commit
5184f844b), everynixcommand run inside a post-build-hook emits a spurious deprecation warning:even when the user never set
warn-short-path-literals. The cause:DeprecatedWarnSettingregisters the deprecated name viaaddSetting()withisAlias = false, making it a primary setting.Config::getSettings()skips aliases but includes primary settings.GlobalConfig::toKeyValue()callsgetSettings()and serialises the result intoNIX_CONFIG. The daemon injects this into every post-build-hook subprocess environment (derivation-goal.cc) and intonix replsubprocesses (repl.cc). Anynixcommand in the hook readsNIX_CONFIG, hitsDeprecatedWarnSetting::assign(), and fires the warning.Fix: add an
excludeFromKeyValueflag toConfig::SettingData. When set,getSettings()skips the setting, removing it fromGlobalConfig::toKeyValue()/NIX_CONFIG. A newConfig::excludeSettingFromKeyValue()method (which asserts the name exists, to catch misuse) sets the flag.DeprecatedWarnSettingcalls it immediately afteraddSetting().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-literalsCLI flags sinceconvertToArgs()skips aliases. WithexcludeFromKeyValue, reading the setting fromnix.conf/NIX_CONFIGstill 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.shbuilds a derivation with a post-build-hook that captures$NIX_CONFIGand assertswarn-short-path-literalsis absent.