From f40d963d2f9c0ad5c4bf5af3eb2f8ebb3300219e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Sun, 21 Apr 2024 16:29:27 +0200 Subject: [PATCH] Strip NIX_REMOTE query part --- flake.nix | 3 ++- src/Nix/Diff/Store.hs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index f131462..5e5eff6 100644 --- a/flake.nix +++ b/flake.nix @@ -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" diff --git a/src/Nix/Diff/Store.hs b/src/Nix/Diff/Store.hs index d785abc..d7441f3 100644 --- a/src/Nix/Diff/Store.hs +++ b/src/Nix/Diff/Store.hs @@ -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 @@ -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