Skip to content

Commit b80ee47

Browse files
committed
Add Default StoreDir instance
1 parent e6740b5 commit b80ee47

File tree

6 files changed

+13
-3
lines changed

6 files changed

+13
-3
lines changed

hnix-store-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* `BuildResult`s `timesBuild` field changes type from `Integer` to `Int` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1010

1111
* Additions:
12+
* `Default StoreDir` instance [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1213
* `System.Nix.StorePath.storePathHashPartToText` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1314
* Added `Generic` and `Show` instances for
1415
`Signature` and `NarSignature` [#231](https://github.com/haskell-nix/hnix-store/pull/231)

hnix-store-core/hnix-store-core.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ library
6060
, case-insensitive
6161
, cereal
6262
, containers
63+
, data-default-class
6364
, generic-arbitrary < 1.1
6465
-- Required for cryptonite low-level type convertion
6566
, memory
@@ -140,6 +141,7 @@ test-suite format-tests
140141
, bytestring
141142
, containers
142143
, cryptonite
144+
, data-default-class
143145
, directory
144146
, filepath
145147
, process

hnix-store-core/src/System/Nix/Internal/StorePath.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module System.Nix.Internal.StorePath
3232
)
3333
where
3434

35+
import Data.Default.Class (Default(def))
3536
import qualified Relude.Unsafe as Unsafe
3637
import System.Nix.Internal.Hash
3738
import System.Nix.Internal.Base
@@ -204,6 +205,9 @@ newtype StoreDir = StoreDir {
204205
instance Arbitrary StoreDir where
205206
arbitrary = StoreDir . ("/" <>) . Bytes.Char8.pack <$> arbitrary
206207

208+
instance Default StoreDir where
209+
def = StoreDir "/nix/store"
210+
207211
-- | Render a 'StorePath' as a 'RawFilePath'.
208212
storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
209213
storePathToRawFilePath storeDir StorePath{..} =

hnix-store-core/tests/Derivation.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import System.Nix.Derivation ( parseDerivation
1313
, buildDerivation
1414
)
1515

16+
import Data.Default.Class (Default(def))
1617
import qualified Data.Attoparsec.Text
1718
import qualified Data.Text.IO
1819
import qualified Data.Text.Lazy
@@ -27,10 +28,10 @@ processDerivation source dest = do
2728
(Data.Text.IO.writeFile dest
2829
. toText
2930
. Data.Text.Lazy.Builder.toLazyText
30-
. buildDerivation (StoreDir "/nix/store")
31+
. buildDerivation def
3132
)
3233
(Data.Attoparsec.Text.parseOnly
33-
(parseDerivation $ StoreDir "/nix/store")
34+
(parseDerivation def)
3435
contents
3536
)
3637

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ library
8585
, cereal
8686
, containers
8787
, cryptonite
88+
, data-default-class
8889
, text
8990
, time
9091
, network

hnix-store-remote/src/System/Nix/Store/Remote/Protocol.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Control.Monad.Except
2222
import Control.Monad.Reader (asks, runReaderT)
2323
import Control.Monad.State.Strict
2424

25+
import Data.Default.Class (Default(def))
2526
import qualified Data.Bool
2627
import Data.Binary.Get
2728
import Data.Binary.Put
@@ -168,7 +169,7 @@ runOpArgsIO op encoder = do
168169
throwError $ Data.ByteString.Char8.unpack msg
169170

170171
runStore :: MonadStore a -> IO (Either String a, [Logger])
171-
runStore = runStoreOpts defaultSockPath $ StoreDir "/nix/store"
172+
runStore = runStoreOpts defaultSockPath def
172173

173174
runStoreOpts
174175
:: FilePath -> StoreDir -> MonadStore a -> IO (Either String a, [Logger])

0 commit comments

Comments
 (0)