Skip to content

Create lint for absolute path literals#15345

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:no-abs-paths-in-eval-2
Feb 26, 2026
Merged

Create lint for absolute path literals#15345
Ericson2314 merged 1 commit intoNixOS:masterfrom
obsidiansystems:no-abs-paths-in-eval-2

Conversation

@Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Feb 26, 2026

Motivation

Fixes #8738

Context

Besides the direct user benefit of having this lint, this reduces the evaluator's usage of rootFS, which also gets us closer to #9549.

Review with whitespace disabled.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Feb 26, 2026
@Ericson2314 Ericson2314 force-pushed the no-abs-paths-in-eval-2 branch from f12f78f to 60b8a33 Compare February 26, 2026 01:22
@Ericson2314 Ericson2314 requested a review from roberth February 26, 2026 01:26
@Ericson2314 Ericson2314 force-pushed the no-abs-paths-in-eval-2 branch from 60b8a33 to 7c426a7 Compare February 26, 2026 18:01
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Sweet


Absolute path literals can make Nix expressions less portable and reproducible, as they depend on the filesystem layout of the machine evaluating the expression.

Also note that with [pure evaluation mode](@docroot@/command-ref/conf-file.md#conf-pure-eval), accessing files not so easily accessed via relative paths is often prohibited anyways.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Also note that with [pure evaluation mode](@docroot@/command-ref/conf-file.md#conf-pure-eval), accessing files not so easily accessed via relative paths is often prohibited anyways.
Also note that with [pure evaluation mode](@docroot@/command-ref/conf-file.md#conf-pure-eval), accessing files not so easily accessed via relative paths is often prohibited anyway.

Too germanic and too long. Idk, not a linguist.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reworded, and move from release notes to the settings description, where it will be read more on an ongoing basis.

@Ericson2314 Ericson2314 force-pushed the no-abs-paths-in-eval-2 branch from 7c426a7 to ed494f0 Compare February 26, 2026 20:06
@xokdvium
Copy link
Contributor

Does this interact in any way with builtins.storePath. Are there any legitimate use cases for absolute path value usages?

@Ericson2314
Copy link
Member Author

Ericson2314 commented Feb 26, 2026

It does not interact with builtins.storePath --- that one is still fine. I do not know any legitimate use-cases. I once did an investigation of Nixpkgs with @infinisil and we found dodgy stuff with a Nixpkgs Vet version of this.

NIX_CONFIG='lint-absolute-path-literals = warn' nix eval --lint-absolute-path-literals ignore --expr '/tmp/bar' 2>"$TEST_ROOT"/stderr
grepQuietInverse "absolute path literal" "$TEST_ROOT/stderr"

echo "absolute-path-literals test passed!"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really needed?

@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 26, 2026
Merged via the queue into NixOS:master with commit 6561739 Feb 26, 2026
15 checks passed
@Ericson2314 Ericson2314 deleted the no-abs-paths-in-eval-2 branch February 26, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 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.

no-absolute-path-literals experimental feature

3 participants