Skip to content

Strip NIX_REMOTE query part #84

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
export NIX_STATE_DIR=$TEST_ROOT/var/nix
export NIX_REMOTE="$TESTROOT/store"
# Note the trailing question mark. It tests Nix.Diff.Store.stripQuery.
export NIX_REMOTE="$TESTROOT/store?"
export HOME="$TESTROOT/home"
mkdir -p $HOME
echo "Copying pinned Nixpkgs for golden tests to relocated store $NIX_REMOTE"
Expand Down
9 changes: 8 additions & 1 deletion src/Nix/Diff/Store.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ readFileUtf8Lenient sp = do
toPhysicalPath :: StorePath -> IO FilePath
toPhysicalPath (StorePath p) = do
nixStoreDir <- lookupEnv "NIX_STORE_DIR" <&> maybe "/nix/store" stripSlash
nixRemoteMaybe <- lookupEnv "NIX_REMOTE" <&> fmap stripSlash
nixRemoteMaybe <- lookupEnv "NIX_REMOTE" <&> fmap stripQuery <&> fmap stripSlash
case nixRemoteMaybe of
Just nixRemote | nixStoreDir `L.isPrefixOf` p -> do
pure $ nixRemote <> "/" <> L.dropWhile (== '/') p
Expand All @@ -66,6 +66,13 @@ toPhysicalPath (StorePath p) = do
toText :: StorePath -> Text
toText (StorePath p) = T.pack p

-- | `NIX_REMOTE` has a URL-like format, so we need to strip the query part.
-- Exact details to be specified; see https://github.com/NixOS/nix/issues/10582
stripQuery :: FilePath -> FilePath
stripQuery p = case L.elemIndex '?' p of
Just i -> take i p
Nothing -> p

stripSlash :: FilePath -> FilePath
stripSlash s | not ("/" `L.isSuffixOf` s) = s
stripSlash s = doIt s
Expand Down