Skip to content

Commit 4734067

Browse files
authored
Merge pull request #230 from sorki/srk/safety
newtypes, Arbitrary instances, chores
2 parents 3b44930 + 863852d commit 4734067

File tree

21 files changed

+377
-385
lines changed

21 files changed

+377
-385
lines changed

hnix-store-core/CHANGELOG.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Next
2+
3+
* Changes:
4+
* Constructors of `StorePathName` and `StorePathHashPart` are no longer
5+
exported. Use respective `mkStorePath..` functions. [#230](https://github.com/haskell-nix/hnix-store/pull/230)
6+
* `StorePathSet` type alias is no more, use `HashSet StorePath` [#230](https://github.com/haskell-nix/hnix-store/pull/230)
7+
8+
* Additions:
9+
* Added `Arbitrary` instances for (exported by default) [#230](https://github.com/haskell-nix/hnix-store/pull/230)
10+
* `StorePath`
11+
* `StorePathName`
12+
* `StorePathHashPart`
13+
* `StoreDir`
14+
15+
# [0.7.0.0](https://github.com/haskell-nix/hnix-store/compare/core-0.6.1.0...core-0.7.0.0) 2023-11-15
16+
17+
* Changes:
18+
* `StorePath` no longer carries `storePathRoot` field and we
19+
have a stand-alone `StoreDir` type instead to be used instead of `FilePath`
20+
when store root directory is needed as a context [#216](https://github.com/haskell-nix/hnix-store/pull/216)
21+
22+
* Fixes:
23+
* NAR encoding and decoding now supports case-insensitive filesystems [#218](https://github.com/haskell-nix/hnix-store/pull/218)
24+
* The "case hack" replicates the behavior of the `use-case-hack` option in Nix, which adds a suffix to conflicting filenames.
25+
This feature is enabled by default on macOS (darwin).
26+
27+
* Additions:
28+
* `data NarOptions` has been added to configure NAR encoding and decoding. The `optUseCaseHack` field can be used to enable or disable the case hack [#218](https://github.com/haskell-nix/hnix-store/pull/218)
29+
* New `streamNarIOWithOptions` and `runParserWithOptions` functions have been added to `System.Nix.Nar` to support the new configurable options [#218](https://github.com/haskell-nix/hnix-store/pull/218)
30+
31+
# [0.6.1.0](https://github.com/haskell-nix/hnix-store/compare/core-0.6.0.0...core-0.6.1.0) 2023-01-02
32+
33+
* Fixes:
34+
35+
* NAR serialization compatibility (symlinks, directory symlinks, UTF-8 handling) [#201](https://github.com/haskell-nix/hnix-store/pull/201) [#203](https://github.com/haskell-nix/hnix-store/pull/203)
36+
37+
# [0.6.0.0](https://github.com/haskell-nix/hnix-store/compare/core-0.5.0.0...core-0.6.0.0) 2022-06-06
38+
39+
* Breaking:
40+
41+
* `streamNarIO` changes type and returns `NarSource m` [#177](https://github.com/haskell-nix/hnix-store/pull/177)
42+
* `FilePath` can turn to `NarSource m` using `dumpPath`
43+
* `ByteString` can turn to `NarSource m` using `dumpString`
44+
45+
# [0.5.0.0](https://github.com/haskell-nix/hnix-store/compare/0.4.3.0...core-0.5.0.0) 2021-06-10
46+
47+
* Breaking:
48+
49+
* `System.Nix.Hash`:
50+
* Migration from packages `cryptohash-` -> `cryptonite` [#157](https://github.com/haskell-nix/hnix-store/pull/157/commits/97146b41cc87327625e02b81971aeb2fd7d66a3f)
51+
* rm `newtype Digest` in favour of `cryptonite: newtype Digest`
52+
* rm `data HashAlgorithm` in favour of `cryptonite: class HashAlgorithm`
53+
* rm `class ValidAlgo` in favour of `cryptonite: class HashAlgorithm`.
54+
* `class NamedAlgo` removed `hashSize` in favour of `cryptonite: class HashAlgorithm: hashDigestSize`. Former became a subclass of the latter.
55+
* rm `hash` in favour of `cryptonite: hash`
56+
* rm `hashLazy` in favour of `cryptonite: hashlazy`
57+
* Base encoding/decoding function for hashes (digests) changed (due to changes in type system & separation of specially truncated Nix Store hasing) [#157](https://github.com/haskell-nix/hnix-store/pull/157/commits/2af74986de8aef1a13dbfc955886f9935ca246a3)
58+
* `encode(InBase -> DigestWith)`
59+
* `decode(Base -> DigestWith)`
60+
* `System.Nix.StorePath` [#157](https://github.com/haskell-nix/hnix-store/pull/157/commits/2af74986de8aef1a13dbfc955886f9935ca246a3)
61+
* rm `type StorePathHashAlgo = 'Truncated 20 'SHA256` in favour of `StorePathHashPart` & `mkStorePathHashPart`.
62+
* rm `unStorePathName`, please use `GHC: coerce` for `StorePathName <-> Text`, `StorePathName` data constructor is provided.
63+
* `Internal` modules now have export lists, if something, please contact.
64+
65+
* Additional:
66+
67+
* Support of GHC 9.0 [#157](https://github.com/haskell-nix/hnix-store/pull/157/commits/97146b41cc87327625e02b81971aeb2fd7d66a3f)
68+
* `System.Nix.StorePath` [#157](https://github.com/haskell-nix/hnix-store/pull/157/commits/2af74986de8aef1a13dbfc955886f9935ca246a3)
69+
* exposed `StorePathName` data constructor to API.
70+
* added `newtype StorePathHashPart = StorePathHashPart ByteString`.
71+
* added builder `mkStorePathHashPart :: ByteString -> StorePathHashPart`
72+
* `System.Nix.Hash` [#157](https://github.com/haskell-nix/hnix-store/pull/157/commits/2af74986de8aef1a13dbfc955886f9935ca246a3)
73+
* Nix store (which are specially truncated) hashes are now handled separately from other hashes:
74+
* add `mkStorePathHash` - a function to create a content into Nix storepath-style hash:
75+
`mkStorePathHash :: HashAlgorithm a => ByteString -> ByteString`
76+
but recommend to at once use `mkStorePathHashPart`.
77+
78+
# [0.4.3.0](https://github.com/haskell-nix/hnix-store/compare/0.4.2.0...0.4.3.0) 2021-05-30
79+
80+
* Additional:
81+
* `System.Nix.ReadonlyStore`: add a readonly `computeStorePathForPath` [b85f7c8](https://github.com/haskell-nix/hnix-store/commit/b85f7c875fe6b0bca939ffbcd8b9bd0ab1598aa0)
82+
* `System.Nix.ReadonlyStore`: `computeStorePathForPath`: force SHA256 as it's the only valid choice [db71ece](https://github.com/haskell-nix/hnix-store/commit/db71ecea3109c0ba270fa98a9041a8556e35217f)
83+
* `makeTextPath`: order the references [5fddf3c](https://github.com/haskell-nix/hnix-store/commit/5fddf3c66ba1bcabb72c4d6b6e09fb41a7acd62c)
84+
85+
# [0.4.2.0](https://github.com/haskell-nix/hnix-store/compare/0.4.1.0...0.4.2.0) 2021-03-12
86+
87+
* Additional:
88+
* Cabal now properly states `tasty-discover` as `build-tool-depends` [5d03ffc](https://github.com/haskell-nix/hnix-store/commit/5d03ffc4cde9448df05e84838ece70cc83b1b6c)
89+
* Added explicit `hie.yml` cradle description for `cabal` to help Haskell Language Server to work with monorepo [5bad385](https://github.com/haskell-nix/hnix-store/commit/b5ad38573d27e0732d0fadfebd98de1f753b4f07)
90+
* Removed vacuous `Setup.hs`, it was throwing-off HLS, and anyway file is vacuous and gets deprecated by Cabal itself [a5b7a61](https://github.com/haskell-nix/hnix-store/commit/a5b7a614c0e0e11147a93b9a197c2a443afa3244)
91+
* Nix dev env: removed GHC 8.6.5 support, afaik it is not even in Nixpkgs anymore [cf04083](https://github.com/haskell-nix/hnix-store/commit/cf04083aba98ad40d183d1e26251101816cc07ae)
92+
* Test suite: fixed nar test for the envs without `/proc` (test suite now works on `macOS`) [2a897ab](https://github.com/haskell-nix/hnix-store/commit/2a897ab581c0501587ce04da6d6e3a6f543b1d72)
93+
94+
95+
# [0.4.1.0](https://github.com/haskell-nix/hnix-store/compare/0.4.0.0...0.4.1.0) 2021-01-16
96+
97+
* Big clean-up of dependencies.
98+
99+
# [0.4.0.0](https://github.com/haskell-nix/hnix-store/compare/0.3.0.0...0.4.0.0) 2020-12-30
100+
101+
* `System.Nix.Hash` no longer exports `encodeBase16, decodeBase16` and their `Base32` counterparts.
102+
These were replaced by `encodeInBase` and `decodeBase` functions
103+
accepting `BaseEncoding` data type [#87](https://github.com/haskell-nix/hnix-store/pull/87)
104+
* Support `base16-bytestring >= 1` [#86](https://github.com/haskell-nix/hnix-store/pull/86) [#100](https://github.com/haskell-nix/hnix-store/pull/100)
105+
106+
# 0.3.0.0 -- 2020-11-29
107+
108+
* `System.Nix.Nar` changes API to support NAR format streaming:
109+
* `buildNarIO :: FilePath -> Handle -> IO ()` - Create a NAR from a regular filesystem object, stream it out on the Handle
110+
* `unpackNarIO :: Handle -> FilePath -> IO ()` - Recreate filesystem object from a NAR file accessed by the Handle
111+
* `StorePath` type changed to simple variant without type level
112+
symbolic store path root.
113+
* Added `makeFixedOutputPath` to `System.Nix.ReadonlyStore`
114+
* Added `decodeBase16` and `decodeBase32` to `System.Nix.Hash`
115+
* `System.Nix.StorePath` module now provides
116+
* `storePathToFilePath` and `storePathToText` helpers
117+
* `storePathToNarInfo` for converting paths to `narinfo` URLs
118+
* `parsePath` function
119+
* `pathParser` Attoparsec parser
120+
* Added `System.Nix.Build` module
121+
* Added `System.Nix.Derivation` module
122+
* Removed `System.Nix.Util` module, moved to `hnix-store-remote`
123+
* Added base64 and SHA512 hash support
124+
125+
# 0.2.0.0 -- 2020-03-12
126+
127+
Removed `System.Nix.Store`. We may reintroduce it later when multiple backends
128+
exist and we can tell what common effects they should share.
129+
130+
# 0.1.0.0 -- 2019-03-18
131+
132+
* First version.

hnix-store-core/ChangeLog.md

Lines changed: 0 additions & 125 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ copyright: 2018 Shea Levy
1515
category: Nix
1616
build-type: Simple
1717
extra-source-files:
18-
ChangeLog.md
18+
CHANGELOG.md
1919
, README.md
2020
, tests/samples/example0.drv
2121
, tests/samples/example1.drv
@@ -70,6 +70,7 @@ library
7070
, monad-control
7171
, mtl
7272
, nix-derivation >= 1.1.1 && <2
73+
, QuickCheck
7374
, saltine
7475
, time
7576
, text
@@ -114,7 +115,6 @@ test-suite format-tests
114115
type: exitcode-stdio-1.0
115116
main-is: Driver.hs
116117
other-modules:
117-
Arbitrary
118118
Derivation
119119
NarFormat
120120
Hash

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ module System.Nix.Internal.StorePath
1313
StoreDir(..)
1414
, StorePath(..)
1515
, StorePathName(..)
16-
, StorePathSet
17-
, mkStorePathHashPart
1816
, StorePathHashPart(..)
17+
, mkStorePathHashPart
1918
, ContentAddressableAddress(..)
2019
, NarHashMode(..)
2120
, -- * Manipulating 'StorePathName'
@@ -47,8 +46,11 @@ import qualified Data.Attoparsec.Text.Lazy as Parser.Text.Lazy
4746
import qualified System.FilePath as FilePath
4847
import Crypto.Hash ( SHA256
4948
, Digest
49+
, HashAlgorithm
5050
)
5151

52+
import Test.QuickCheck
53+
5254
-- | A path in a Nix store.
5355
--
5456
-- From the Nix thesis: A store path is the full path of a store
@@ -72,6 +74,12 @@ instance Hashable StorePath where
7274
hashWithSalt s StorePath{..} =
7375
s `hashWithSalt` storePathHash `hashWithSalt` storePathName
7476

77+
instance Arbitrary StorePath where
78+
arbitrary =
79+
liftA2 StorePath
80+
arbitrary
81+
arbitrary
82+
7583
-- | The name portion of a Nix path.
7684
--
7785
-- 'unStorePathName' must only contain a-zA-Z0-9+._?=-, can't start
@@ -82,15 +90,29 @@ newtype StorePathName = StorePathName
8290
unStorePathName :: Text
8391
} deriving (Eq, Hashable, Ord, Show)
8492

93+
instance Arbitrary StorePathName where
94+
arbitrary = StorePathName . toText <$> ((:) <$> s1 <*> listOf sn)
95+
where
96+
alphanum = ['a' .. 'z'] <> ['A' .. 'Z'] <> ['0' .. '9']
97+
s1 = elements $ alphanum <> "+-_?="
98+
sn = elements $ alphanum <> "+-._?="
99+
85100
-- | The hash algorithm used for store path hashes.
86-
newtype StorePathHashPart = StorePathHashPart ByteString
101+
newtype StorePathHashPart = StorePathHashPart
102+
{ -- | Extract the contents of the hash.
103+
unStorePathHashPart :: ByteString
104+
}
87105
deriving (Eq, Hashable, Ord, Show)
88106

89-
mkStorePathHashPart :: ByteString -> StorePathHashPart
90-
mkStorePathHashPart = coerce . mkStorePathHash @SHA256
107+
instance Arbitrary StorePathHashPart where
108+
arbitrary = mkStorePathHashPart @SHA256 . Bytes.Char8.pack <$> arbitrary
91109

92-
-- | A set of 'StorePath's.
93-
type StorePathSet = HashSet StorePath
110+
mkStorePathHashPart
111+
:: forall hashAlgo
112+
. HashAlgorithm hashAlgo
113+
=> ByteString
114+
-> StorePathHashPart
115+
mkStorePathHashPart = coerce . mkStorePathHash @hashAlgo
94116

95117
-- | An address for a content-addressable store path, i.e. one whose
96118
-- store path hash is purely a function of its contents (as opposed to
@@ -163,6 +185,9 @@ newtype StoreDir = StoreDir {
163185
unStoreDir :: RawFilePath
164186
} deriving (Eq, Hashable, Ord, Show)
165187

188+
instance Arbitrary StoreDir where
189+
arbitrary = StoreDir . ("/" <>) . Bytes.Char8.pack <$> arbitrary
190+
166191
-- | Render a 'StorePath' as a 'RawFilePath'.
167192
storePathToRawFilePath :: StoreDir -> StorePath -> RawFilePath
168193
storePathToRawFilePath storeDir StorePath{..} =

0 commit comments

Comments
 (0)