Repository navigation
Improve lazy trees backward compatibility - #56
Merged
Merged
Conversation
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.
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.
edolstra
marked this pull request as ready for review
May 8, 2025 13:54
grahamc
reviewed
May 8, 2025
grahamc
reviewed
May 8, 2025
Co-authored-by: Graham Christensen <[email protected]>
grahamc
enabled auto-merge
May 8, 2025 16:54
grahamc
approved these changes
May 8, 2025
The warning added seems to also trigger when intentionally removing context using * and anywhere else the usual NixOS options-doc pattern is used |
2 tasks done
|
@grahamc @edolstra please see the comment above, related to nix-community/home-manager#7935 and NixOS/nixpkgs#482766 |
3 of 13 tasks
This branch was previously deployed
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.
Motivation
When you apply
builtins.toStringto 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
SourcePathsrather than virtualStorePaths.)This makes Nix with
--lazy-treespass the entire flake-regressions test suite.Context