Skip to content

Commit 4d9d595

Browse files
authored
Merge pull request #247 from haskell-nix/srk/split2
Split part 2
2 parents 6e2c03a + cce2c98 commit 4d9d595

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+942
-137
lines changed

cabal.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
packages:
22
./hnix-store-core/hnix-store-core.cabal
33
./hnix-store-db/hnix-store-db.cabal
4+
./hnix-store-nar/hnix-store-nar.cabal
5+
./hnix-store-readonly/hnix-store-readonly.cabal
46
./hnix-store-remote/hnix-store-remote.cabal
57
./hnix-store-tests/hnix-store-tests.cabal
68

@@ -11,5 +13,8 @@ allow-newer:
1113
package hnix-store-db
1214
flags: +build-readme +build-bench
1315

16+
package hnix-store-nar
17+
flags: +bounded_memory
18+
1419
package hnix-store-remote
1520
flags: +build-readme +io-testsuite

cabal.project.local.ci

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ package hnix-store-core
66
package hnix-store-db
77
ghc-options: -Wunused-packages -Wall -Werror
88

9+
package hnix-store-nar
10+
ghc-options: -Wunused-packages -Wall -Werror
11+
12+
package hnix-store-readonly
13+
ghc-options: -Wunused-packages -Wall -Werror
14+
915
package hnix-store-remote
1016
ghc-options: -Wunused-packages -Wall -Werror
1117

default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ in {
2222
inherit (haskellPackages)
2323
hnix-store-core
2424
hnix-store-db
25+
hnix-store-nar
26+
hnix-store-readonly
2527
hnix-store-remote
2628
hnix-store-tests;
2729
haskellPackages = lib.dontRecurseIntoAttrs haskellPackages;

hie.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,25 @@ cradle:
44
component: "lib:hnix-store-core"
55

66
- path: "./hnix-store-core/tests"
7-
component: "hnix-store-core:test:format-tests"
7+
component: "hnix-store-core:test:core"
8+
9+
- path: "./hnix-store-db/src"
10+
component: "lib:hnix-store-db"
11+
12+
- path: "./hnix-store-db/tests"
13+
component: "hnix-store-db:test:db"
14+
15+
- path: "./hnix-store-nar/src"
16+
component: "lib:hnix-store-nar"
17+
18+
- path: "./hnix-store-nar/tests"
19+
component: "hnix-store-nar:test:nar"
20+
21+
- path: "./hnix-store-readonly/src"
22+
component: "lib:hnix-store-readonly"
23+
24+
- path: "./hnix-store-readonly/tests"
25+
component: "hnix-store-readonly:test:readonly"
826

927
- path: "./hnix-store-remote/src"
1028
component: "lib:hnix-store-remote"
@@ -14,3 +32,9 @@ cradle:
1432

1533
- path: "./hnix-store-remote/tests-io"
1634
component: "hnix-store-remote:test:remote-io"
35+
36+
- path: "./hnix-store-tests/src"
37+
component: "lib:hnix-store-tests"
38+
39+
- path: "./hnix-store-tests/tests"
40+
component: "hnix-store-tests:test:props"

hnix-store-core/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
# Next
22

33
* Changes:
4+
* `System.Nix.ReadOnlyStore` moved to `hnix-store-readonly` package
5+
and renamed to `System.Nix.Store.ReadOnly` [#247](https://github.com/haskell-nix/hnix-store/pull/247)
6+
* `System.Nix.Nar*` moved to `hnix-store-nar` package [#247](https://github.com/haskell-nix/hnix-store/pull/247)
7+
* `Arbitrary` instances moved to `hnix-store-tests` package [#241](https://github.com/haskell-nix/hnix-store/pull/241)
48
* `System.Nix.Internal` namespaces was removed [#236](https://github.com/haskell-nix/hnix-store/pull/236)
59
* `StorePathMetadata` converted to `Metadata a` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
610
* Moved to `System.Nix.StorePath.Metadata` [#236](https://github.com/haskell-nix/hnix-store/pull/236)
711
* Constructors of `StorePathName` and `StorePathHashPart` are no longer
812
exported. Use respective `mkStorePath..` functions. [#230](https://github.com/haskell-nix/hnix-store/pull/230)
13+
* `StorePath` constructor is no longer exported.
14+
Prefer `parsePath` or `parsePathFromText`.
15+
If needed to construct a path directly, use `unsafeMakeStorePath` [#247](https://github.com/haskell-nix/hnix-store/pull/247)
916
* `StorePathSet` type alias is no more, use `HashSet StorePath` [#230](https://github.com/haskell-nix/hnix-store/pull/230)
1017
* `makeStorePath` and `parsePath` now returns `Either InvalidPathError StorePath` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1118
* `BuildResult`s `timesBuild` field changes type from `Integer` to `Int` [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1219

1320
* Additions:
21+
* `System.Nix.Store.Types` with `FileIngestionMethod`, `PathFilter`, `RepairMode` types [#247](https://github.com/haskell-nix/hnix-store/pull/247)
22+
`FileIngestionMethod` was previously called `NarHashMode`
1423
* `System.Nix.StorePath.parsePathFromText` [#236](https://github.com/haskell-nix/hnix-store/pull/236)
1524
* `Default StoreDir` instance [#231](https://github.com/haskell-nix/hnix-store/pull/231)
1625
* `System.Nix.StorePath.storePathHashPartToText` [#231](https://github.com/haskell-nix/hnix-store/pull/231)

hnix-store-core/README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
# hnix-store-core
22

3-
Core effects for interacting with the Nix store.
3+
Core types and functions for interacting with the Nix store.
44

5-
See `NarEffects` in [System.Nix.Nar.Effects] and the [System.Nix.StorePath] for the available operations
6-
on the store.
7-
8-
[System.Nix.Nar.Effects]: ./src/System/Nix/Nar/Effects.hs
95
[System.Nix.StorePath]: ./src/System/Nix/StorePath.hs
10-
11-
12-
# Tests
13-
14-
- `ghcid --command "cabal repl test-suite:format-tests" --test="Main.main"`

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

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
cabal-version: 2.2
22
name: hnix-store-core
33
version: 0.8.0.0
4-
synopsis: Core effects for interacting with the Nix store.
4+
synopsis: Core types used for interacting with the Nix store.
55
description:
66
This package contains types and functions needed to describe
7-
interactions with the Nix store abstracted away from
8-
specific effectful context.
7+
interactions with the Nix store.
98
homepage: https://github.com/haskell-nix/hnix-store
109
license: Apache-2.0
1110
license-file: LICENSE
1211
author: Shea Levy
13-
maintainer: [email protected]
12+
maintainer: [email protected]
1413
copyright: 2018 Shea Levy
1514
category: Nix
1615
build-type: Simple
@@ -19,7 +18,6 @@ extra-source-files:
1918
, README.md
2019
, tests/samples/example0.drv
2120
, tests/samples/example1.drv
22-
, tests/fixtures/case-conflict.nar
2321

2422
common commons
2523
ghc-options: -Wall
@@ -66,62 +64,41 @@ library
6664
, System.Nix.DerivedPath
6765
, System.Nix.Hash
6866
, System.Nix.Hash.Truncation
69-
, System.Nix.Nar
70-
, System.Nix.Nar.Parser
71-
, System.Nix.Nar.Streamer
72-
, System.Nix.Nar.Effects
73-
, System.Nix.Nar.Options
74-
, System.Nix.ReadonlyStore
7567
, System.Nix.Signature
68+
, System.Nix.Store.Types
7669
, System.Nix.StorePath
7770
, System.Nix.StorePath.Metadata
7871
build-depends:
7972
base >=4.12 && <5
8073
, attoparsec
81-
, algebraic-graphs >= 0.5 && < 0.8
8274
, base16-bytestring >= 1.0
8375
, base64-bytestring >= 1.2.1
8476
, bytestring
85-
, case-insensitive
86-
, cereal
8777
, containers
8878
, constraints-extras
79+
, cryptonite
8980
, data-default-class
9081
, dependent-sum > 0.7
9182
, dependent-sum-template > 0.1.1 && < 0.3
92-
-- Required for cryptonite low-level type convertion
93-
, memory
94-
, cryptonite
95-
, directory
9683
, filepath
9784
, hashable
98-
, lifted-base
99-
, monad-control
100-
, mtl
85+
-- Required for cryptonite low-level type convertion
86+
, memory
10187
, nix-derivation >= 1.1.1 && <2
10288
, saltine >= 0.2 && < 0.3
10389
, some > 1.0.5 && < 2
10490
, time
10591
, text
106-
, unix
10792
, unordered-containers
10893
, vector
10994
hs-source-dirs: src
11095

111-
Flag bounded_memory
112-
description: Run tests of constant memory use (requires +RTS -T)
113-
default: False
114-
115-
test-suite format-tests
96+
test-suite core
11697
import: commons
117-
if flag(bounded_memory)
118-
cpp-options: -DBOUNDED_MEMORY
119-
ghc-options: -rtsopts -fprof-auto
12098
type: exitcode-stdio-1.0
12199
main-is: Driver.hs
122100
other-modules:
123101
Derivation
124-
NarFormat
125102
Hash
126103
hs-source-dirs:
127104
tests
@@ -133,20 +110,11 @@ test-suite format-tests
133110
, base
134111
, base16-bytestring
135112
, base64-bytestring
136-
, binary
137113
, bytestring
138-
, containers
139114
, cryptonite
140115
, data-default-class
141-
, directory
142-
, filepath
143-
, process
116+
, hspec
144117
, tasty
145118
, tasty-golden
146-
, hspec
147119
, tasty-hspec
148-
, tasty-hunit
149-
, tasty-quickcheck
150-
, temporary
151120
, text
152-
, unix

hnix-store-core/src/System/Nix/ContentAddress.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@ import Data.Text (Text)
1818
import Data.Text.Lazy.Builder (Builder)
1919
import GHC.Generics (Generic)
2020
import System.Nix.Hash (HashAlgo)
21+
import System.Nix.Store.Types (FileIngestionMethod(..))
2122

2223
import qualified Data.Attoparsec.Text
2324
import qualified Data.Text.Lazy
2425
import qualified Data.Text.Lazy.Builder
2526
import qualified System.Nix.Hash
2627

27-
data FileIngestionMethod
28-
= Flat
29-
| FileRecursive
30-
deriving (Eq, Bounded, Generic, Enum, Ord, Show)
31-
3228
data ContentAddressMethod
3329
= FileIngestionMethod !FileIngestionMethod
3430
-- ^ The path was added to the store via makeFixedOutputPath or
@@ -74,8 +70,8 @@ contentAddressBuilder (ContentAddress method digest) = case method of
7470

7571
fileIngestionMethodBuilder :: FileIngestionMethod -> Builder
7672
fileIngestionMethodBuilder = \case
77-
Flat -> ""
78-
FileRecursive -> "r:"
73+
FileIngestionMethod_Flat -> ""
74+
FileIngestionMethod_FileRecursive -> "r:"
7975

8076
-- | Parse `ContentAddressableAddress` from `ByteString`
8177
parseContentAddress
@@ -95,7 +91,9 @@ contentAddressParser = do
9591
parseContentAddressMethod :: Parser ContentAddressMethod
9692
parseContentAddressMethod =
9793
TextIngestionMethod <$ "text:"
98-
<|> FileIngestionMethod <$ "fixed:" <*> (FileRecursive <$ "r:" <|> pure Flat)
94+
<|> FileIngestionMethod <$ "fixed:"
95+
<*> (FileIngestionMethod_FileRecursive <$ "r:"
96+
<|> pure FileIngestionMethod_Flat)
9997

10098
parseTypedDigest :: Parser (Either String (DSum HashAlgo Digest))
10199
parseTypedDigest = System.Nix.Hash.mkNamedDigest <$> parseHashType <*> parseHash
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module System.Nix.Store.Types
2+
( FileIngestionMethod(..)
3+
, PathFilter(..)
4+
, RepairMode(..)
5+
) where
6+
7+
import GHC.Generics (Generic)
8+
9+
-- | Add path recursively or not
10+
data FileIngestionMethod
11+
= FileIngestionMethod_Flat
12+
| FileIngestionMethod_FileRecursive
13+
deriving (Bounded, Eq, Generic, Enum, Ord, Show)
14+
15+
-- | Path filtering function
16+
newtype PathFilter = PathFilter
17+
{ pathFilterFunction :: FilePath -> Bool
18+
}
19+
20+
-- | Repair mode
21+
data RepairMode
22+
= RepairMode_DoRepair
23+
| RepairMode_DontRepair
24+
deriving (Bounded, Eq, Generic, Enum, Ord, Show)

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ module System.Nix.StorePath
99
( -- * Basic store path types
1010
StoreDir(..)
1111
, HasStoreDir(..)
12-
, getStoreDir
13-
, StorePath(..)
14-
, StorePathName(..)
15-
, StorePathHashPart(..)
12+
, StorePath
13+
, storePathHash
14+
, storePathName
15+
, StorePathName
16+
, unStorePathName
17+
, StorePathHashPart
1618
, mkStorePathHashPart
19+
, unStorePathHashPart
1720
, -- * Manipulating 'StorePathName'
1821
makeStorePathName
1922
, validStorePathName
@@ -29,9 +32,10 @@ module System.Nix.StorePath
2932
parsePath
3033
, parsePathFromText
3134
, pathParser
35+
-- * Utilities for tests
36+
, unsafeMakeStorePath
3237
) where
3338

34-
import Control.Monad.Reader.Class (MonadReader, asks)
3539
import Crypto.Hash (HashAlgorithm)
3640
import Data.Attoparsec.Text.Lazy (Parser, (<?>))
3741
import Data.ByteString (ByteString)
@@ -70,12 +74,18 @@ data StorePath = StorePath
7074
-- hello-1.2.3).
7175
storePathName :: !StorePathName
7276
}
73-
deriving (Eq, Generic, Ord, Show)
77+
deriving (Eq, Generic, Ord)
7478

7579
instance Hashable StorePath where
7680
hashWithSalt s StorePath{..} =
7781
s `hashWithSalt` storePathHash `hashWithSalt` storePathName
7882

83+
instance Show StorePath where
84+
show s =
85+
"StorePath"
86+
<> " "
87+
<> storePathToFilePath (StoreDir mempty) s
88+
7989
-- | The name portion of a Nix path.
8090
--
8191
-- 'unStorePathName' must only contain a-zA-Z0-9+._?=-, can't start
@@ -166,10 +176,6 @@ instance Default StoreDir where
166176
class HasStoreDir r where
167177
hasStoreDir :: r -> StoreDir
168178

169-
-- | Ask for a @StoreDir@
170-
getStoreDir :: (HasStoreDir r, MonadReader r m) => m StoreDir
171-
getStoreDir = asks hasStoreDir
172-
173179
-- | Render a 'StorePath' as a 'RawFilePath'.
174180
storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
175181
storePathToRawFilePath storeDir StorePath{..} =
@@ -291,3 +297,13 @@ pathParser expectedRoot = do
291297
(fail . show)
292298
pure
293299
(StorePath <$> hashPart <*> name)
300+
301+
-- * Utilities for tests
302+
303+
-- | Paths rarely need to be constructed directly.
304+
-- Prefer @parsePath@ or @parsePathFromText@
305+
unsafeMakeStorePath
306+
:: StorePathHashPart
307+
-> StorePathName
308+
-> StorePath
309+
unsafeMakeStorePath = StorePath

0 commit comments

Comments
 (0)