From dfa55dc8ba2e48838e57cc17038682df0873e58c Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Mon, 7 Mar 2022 12:12:23 +0100 Subject: [PATCH 1/3] remote: set HOME for tests --- hnix-store-remote/tests/NixDaemon.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/hnix-store-remote/tests/NixDaemon.hs b/hnix-store-remote/tests/NixDaemon.hs index 4fe7359..8355619 100644 --- a/hnix-store-remote/tests/NixDaemon.hs +++ b/hnix-store-remote/tests/NixDaemon.hs @@ -49,6 +49,7 @@ mockedEnv mEnvPath fp = (fp ) <<$>> , ("NIX_LOG_DIR" , "var" "log") , ("NIX_STATE_DIR" , "var" "nix") , ("NIX_CONF_DIR" , "etc") + , ("HOME" , "home") -- , ("NIX_REMOTE", "daemon") ] <> foldMap (\x -> [("PATH", x)]) mEnvPath From 082cad8756721a4bb87caaed898467141cc42451 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Mon, 7 Mar 2022 12:42:05 +0100 Subject: [PATCH 2/3] remote: drop derivation test This was a hack to test serialization/protocol but the fake derivation won't pass validation with Nix 2.6. This needs to be tested in combination with hnix with valid derivation. Closes #178 --- hnix-store-remote/hnix-store-remote.cabal | 4 +- hnix-store-remote/tests/Derivation.hs | 75 ----------------------- hnix-store-remote/tests/NixDaemon.hs | 7 --- 3 files changed, 1 insertion(+), 85 deletions(-) delete mode 100644 hnix-store-remote/tests/Derivation.hs diff --git a/hnix-store-remote/hnix-store-remote.cabal b/hnix-store-remote/hnix-store-remote.cabal index c904b6e..ff39813 100644 --- a/hnix-store-remote/hnix-store-remote.cabal +++ b/hnix-store-remote/hnix-store-remote.cabal @@ -90,8 +90,7 @@ test-suite hnix-store-remote-tests type: exitcode-stdio-1.0 main-is: Driver.hs other-modules: - Derivation - , NixDaemon + NixDaemon , Spec , Util hs-source-dirs: tests @@ -114,7 +113,6 @@ test-suite hnix-store-remote-tests , tasty-hspec , tasty-quickcheck , linux-namespaces - , nix-derivation , temporary , text , unix diff --git a/hnix-store-remote/tests/Derivation.hs b/hnix-store-remote/tests/Derivation.hs deleted file mode 100644 index fb95de9..0000000 --- a/hnix-store-remote/tests/Derivation.hs +++ /dev/null @@ -1,75 +0,0 @@ -{-# language DataKinds #-} - -module Derivation where - -import Nix.Derivation ( Derivation(..) - , DerivationOutput(..) - ) -import System.Nix.StorePath ( StorePath - , storePathToText - ) - -import System.Nix.Store.Remote ( MonadStore - , addToStore - , addTextToStore - ) -import qualified Data.Map -import qualified Data.Set -import qualified Data.Text -import qualified Data.Text.Lazy.Builder -import qualified Data.Vector -import qualified System.Nix.Derivation -import qualified System.Nix.StorePath -import qualified System.Directory -import Crypto.Hash ( SHA256 ) - -drvSample :: StorePath -> StorePath -> StorePath -> Derivation StorePath Text -drvSample builder' buildScript out = Derivation - { outputs = Data.Map.fromList [("out", DerivationOutput out "sha256" "test")] - , inputDrvs = Data.Map.fromList [(builder', Data.Set.fromList ["out"])] - , inputSrcs = Data.Set.fromList [buildScript] - , platform = "x86_64-linux" - , builder = storePathToText builder' - , args = Data.Vector.fromList ["-e", storePathToText buildScript] - , env = Data.Map.fromList [("testEnv", "true")] - } - -withBash :: (StorePath -> MonadStore a) -> MonadStore a -withBash action = do - mfp <- liftIO $ System.Directory.findExecutable "bash" - case mfp of - Nothing -> error "No bash executable found" - Just fp -> do - let Right n = System.Nix.StorePath.makeStorePathName "bash" - pth <- addToStore @SHA256 n fp False (pure True) False - action pth - -withBuildScript :: (StorePath -> MonadStore a) -> MonadStore a -withBuildScript action = do - pth <- addTextToStore "buildScript" - (Data.Text.concat ["declare -xp", "export > $out"]) - mempty - False - - action pth - -withDerivation - :: (StorePath -> Derivation StorePath Text -> MonadStore a) -> MonadStore a -withDerivation action = withBuildScript $ \buildScript -> withBash $ \bash -> - do - outputPath <- addTextToStore "wannabe-output" "" mempty False - - let d = drvSample bash buildScript outputPath - - pth <- addTextToStore - "hnix-store-derivation" - ( toText - $ Data.Text.Lazy.Builder.toLazyText - $ System.Nix.Derivation.buildDerivation d - ) - mempty - False - - liftIO $ print d - action pth d - diff --git a/hnix-store-remote/tests/NixDaemon.hs b/hnix-store-remote/tests/NixDaemon.hs index 8355619..3512094 100644 --- a/hnix-store-remote/tests/NixDaemon.hs +++ b/hnix-store-remote/tests/NixDaemon.hs @@ -27,7 +27,6 @@ import System.Nix.StorePath import System.Nix.Store.Remote import System.Nix.Store.Remote.Protocol -import Derivation import Crypto.Hash ( SHA256 ) @@ -261,9 +260,3 @@ spec_protocol = Hspec.around withNixDaemon $ path <- dummy liftIO $ print path isValidPathUncached path `shouldReturn` True - - context "derivation" $ - itRights "build derivation" $ - withDerivation $ \path drv -> do - result <- buildDerivation path drv Normal - result `shouldSatisfy` ((== AlreadyValid) . status) From 2d34df0407fb67a9c6929d67725e500e575768c1 Mon Sep 17 00:00:00 2001 From: Richard Marko Date: Mon, 7 Mar 2022 13:05:43 +0100 Subject: [PATCH 3/3] overlay.nix: use relude 1.0 for hnix-store-remote --- overlay.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlay.nix b/overlay.nix index 9f6028f..819a40d 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,6 +1,6 @@ pkgs: hlib: helf: huper: { hnix-store-remote = - ( helf.callCabal2nixWithOptions "hnix-store-remote" ./hnix-store-remote "-fio-testsuite" {} + ( helf.callCabal2nixWithOptions "hnix-store-remote" ./hnix-store-remote "-fio-testsuite" { relude = helf.relude_1_0_0_1; } ).overrideAttrs (attrs: { buildInputs = attrs.buildInputs ++ [ pkgs.nix