mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-12-13 23:56:37 +03:00
Merge pull request #182 from haskell-nix/srk/test_fixes
Remote testsuite fixes for Nix 2.6
This commit is contained in:
commit
83619f3824
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
@ -49,6 +48,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
|
||||
|
||||
@ -260,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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user