Skip to content

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.
@roberth roberth force-pushed the relocated-store-via-env branch from 14fe802 to 41a6ce9 Compare March 1, 2024 12:18
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).

@roberth roberth requested a review from Gabriella439 March 18, 2024 15:58
@Gabriella439 Gabriella439 merged commit f31e0c1 into Gabriella439:main Apr 15, 2024
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.

2 participants