Skip to content

Improve lazy trees backward compatibility - #56

Merged
grahamc merged 8 commits into
detsys-mainfrom
references-without-context
May 8, 2025
Merged

grahamc merged 8 commits into
detsys-mainfrom
references-without-context

Conversation

@edolstra

@edolstra edolstra commented May 7, 2025 •

Copy link
Copy Markdown
Collaborator

Motivation

When you apply builtins.toString to a path value representing a path in the Nix store (as is the case with flake inputs), historically you got a string without context (e.g. /nix/store/...-source). This is broken, since it allows you to pass a store path to a derivation/toFile without a proper store reference. This is especially a problem with lazy trees, since the store path is a virtual path that doesn't exist and can be different every time.

For backwards compatibility, and to warn users about this unsafe use of toString, we now keep track of such strings as a special type of context.

(The original lazy trees branch had something similar, but there the context was keeping track of SourcePaths rather than virtual StorePaths.)

This makes Nix with --lazy-trees pass the entire flake-regressions test suite.

Context

edolstra added 2 commits May 7, 2025 18:24
When you apply `builtins.toString` to a path value representing a path
in the Nix store (as is the case with flake inputs), historically you
got a string without context (e.g. `/nix/store/...-source`). This is
broken, since it allows you to pass a store path to a
derivation/toFile without a proper store reference. This is especially
a problem with lazy trees, since the store path is a virtual path that
doesn't exist and can be different every time.

For backwards compatibility, and to warn users about this unsafe use
of `toString`, we now keep track of such strings as a special type of
context.
@github-actions

github-actions Bot commented May 7, 2025 •

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request May 7, 2025 17:09 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request May 7, 2025 17:42 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request May 7, 2025 19:08 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request May 8, 2025 07:27 Inactive
This is already done by consumers of builtins.toJSON (like
builtins.toFile or builtins.derivation), so we can delay this until
it's actually needed.
@github-actions
github-actions Bot temporarily deployed to pull request May 8, 2025 13:44 Inactive
@edolstra
edolstra marked this pull request as ready for review May 8, 2025 13:54
Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
@edolstra edolstra added the flake-regression-test Run the flake regressions test suite on this PR label May 8, 2025
@github-actions
github-actions Bot temporarily deployed to pull request May 8, 2025 16:50 Inactive
@grahamc
grahamc enabled auto-merge May 8, 2025 16:54
@grahamc
grahamc added this pull request to the merge queue May 8, 2025
Merged via the queue into detsys-main with commit 7c47777 May 8, 2025
@grahamc
grahamc deleted the references-without-context branch May 8, 2025 17:28
@MattSturgeon

MattSturgeon commented Feb 4, 2026 •

Copy link
Copy Markdown

For backwards compatibility, and to warn users about this unsafe use of toString, we now keep track of such strings as a special type of context.

The warning added seems to also trigger when intentionally removing context using builtins.unsafeDiscardStringContext. We're seeing this in nixpkgs and home-manager,* as we intentionally remove any accidentally added string context from the documentation's options.json

* and anywhere else the usual NixOS options-doc pattern is used

@Malix-Labs

Copy link
Copy Markdown

@grahamc @edolstra please see the comment above, related to nix-community/home-manager#7935 and NixOS/nixpkgs#482766

This branch was previously deployed

1 inactive deployment
pull request — 8eee061e Deployed May 8, 2025 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flake-regression-test Run the flake regressions test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants