Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relocated store; lightweight store module #82

Merged
merged 8 commits into from Apr 15, 2024

Conversation

roberth
Copy link
Contributor

@roberth roberth commented Mar 1, 2024

Support relocated store when configured with the NIX_STORE_DIR and NIX_REMOTE environment variables.

This allows nix-diff to be used in the sandbox with instantiations in a store whose physical location is in the build directory rather than the logical storeDir (/nix/store).

This is achieved by changing introducing a newtype StorePath to help distinguish paths that may be logical paths rather than physical ones.
It is not a true abstraction in the sense that Nix's own store concept is, but that's ok. It makes this use case work, while still only relying on the ambient environment, requiring no types and variables for the store itself.

I plan to use this functionality for error reporting in evaluation tests that evaluate Nixpkgs for the purpose of testing Nix itself, in the context of Nixpkgs "passthru" tests and Nix's own CI setup.

... when configured with the NIX_STORE_DIR and NIX_REMOTE
environment variables.
src/Nix/Diff.hs Outdated
let string = path
text <- liftIO (readFileUtf8Lenient string)
case Data.Attoparsec.Text.parse Nix.Derivation.parseDerivation text of
let parser = Nix.Derivation.parseDerivationWith (StorePath <$> filepathParser) Nix.Derivation.textParser
Copy link
Owner

Choose a reason for hiding this comment

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

Minor suggestion: maybe have filepathParser return a StorePath (an rename it to storepathParser

Comment on lines 69 to 76
stripSlash :: FilePath -> FilePath
stripSlash = reverse . dropWhile (== '/') . reverse

replaceStart :: String -> String -> String -> String
replaceStart pattern replacement text =
case L.stripPrefix pattern text of
Just rest -> replacement <> rest
Nothing -> text
Copy link
Owner

Choose a reason for hiding this comment

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

Both of these operations will simpler and more efficient if you convert to Text (and then back to FilePath when you're done).

@Gabriella439 Gabriella439 merged commit f31e0c1 into Gabriella439:main Apr 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants