Skip to content

Commit db71e6b

Browse files
committed
Merge branch 'master' into bitTooLate
2 parents e534a85 + 671d3c5 commit db71e6b

31 files changed

+732
-663
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eval "$(lorri direnv)"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
dist
2+
dist-newstyle
3+
.ghc.environment*

default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
in {
1111
haskellPackages =
1212
pkgs.haskellPackages.override overrideHaskellPackages;
13+
haskell844Packages =
14+
pkgs.haskell.packages.ghc844.override overrideHaskellPackages;
1315
inherit pkgs;
1416
}

hnix-store-core/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eval "$(lorri direnv)"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: hnix-store-core
2+
version: 0.2.0.0
3+
synopsis: Core effects for interacting with the Nix store.
4+
description:
5+
This package contains types and functions needed to describe
6+
interactions with the Nix store abstracted away from
7+
specific effectful context.
8+
homepage: https://github.com/haskell-nix/hnix-store
9+
license: Apache-2.0
10+
license-file: LICENSE
11+
author: Shea Levy
12+
maintainer: [email protected]
13+
copyright: 2018 Shea Levy
14+
category: System
15+
build-type: Simple
16+
extra-source-files: ChangeLog.md, README.md
17+
cabal-version: >=1.10
18+
19+
library
20+
exposed-modules: System.Nix.Base32
21+
, System.Nix.Build
22+
, System.Nix.Hash
23+
, System.Nix.Internal.Hash
24+
, System.Nix.Internal.Signature
25+
, System.Nix.Internal.StorePath
26+
, System.Nix.Nar
27+
, System.Nix.ReadonlyStore
28+
, System.Nix.Signature
29+
, System.Nix.StorePath
30+
, System.Nix.StorePathMetadata
31+
, System.Nix.Util
32+
, System.Nix.ValidPath
33+
build-depends: base >=4.10 && <5
34+
, base16-bytestring
35+
, bytestring
36+
, binary
37+
, bytestring
38+
, containers
39+
, cryptohash-md5
40+
, cryptohash-sha1
41+
, cryptohash-sha256
42+
, directory
43+
, filepath
44+
, hashable
45+
, mtl
46+
, regex-base
47+
, regex-tdfa-text
48+
, saltine
49+
, time
50+
, text
51+
, unix
52+
, unordered-containers
53+
, vector
54+
hs-source-dirs: src
55+
default-language: Haskell2010
56+
57+
Flag bounded_memory
58+
description: Run tests of constant memory use (requires +RTS -T)
59+
default: False
60+
61+
test-suite format-tests
62+
if flag(bounded_memory)
63+
cpp-options: -DBOUNDED_MEMORY
64+
ghc-options: -rtsopts -fprof-auto
65+
type: exitcode-stdio-1.0
66+
main-is: Driver.hs
67+
other-modules:
68+
NarFormat
69+
Hash
70+
hs-source-dirs:
71+
tests
72+
build-depends:
73+
hnix-store-core
74+
, base
75+
, base64-bytestring
76+
, binary
77+
, bytestring
78+
, containers
79+
, directory
80+
, process
81+
, tasty
82+
, tasty-discover
83+
, tasty-hspec
84+
, tasty-hunit
85+
, tasty-quickcheck
86+
, temporary
87+
, text
88+
default-language: Haskell2010
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{-|
2+
Description: Implementation of Nix's base32 encoding.
3+
-}
4+
module System.Nix.Base32 where
5+
6+
import qualified Data.ByteString as BS
7+
import qualified Data.Text as T
8+
import qualified Data.Vector as V
9+
10+
-- | Encode a 'BS.ByteString' in Nix's base32 encoding
11+
encode :: BS.ByteString -> T.Text
12+
encode c = T.pack $ map char32 [nChar - 1, nChar - 2 .. 0]
13+
where
14+
digits32 = V.fromList "0123456789abcdfghijklmnpqrsvwxyz"
15+
-- Each base32 character gives us 5 bits of information, while
16+
-- each byte gives is 8. Because 'div' rounds down, we need to add
17+
-- one extra character to the result, and because of that extra 1
18+
-- we need to subtract one from the number of bits in the
19+
-- bytestring to cover for the case where the number of bits is
20+
-- already a factor of 5. Thus, the + 1 outside of the 'div' and
21+
-- the - 1 inside of it.
22+
nChar = fromIntegral $ ((BS.length c * 8 - 1) `div` 5) + 1
23+
24+
byte = BS.index c . fromIntegral
25+
26+
-- May need to switch to a more efficient calculation at some
27+
-- point.
28+
bAsInteger :: Integer
29+
bAsInteger = sum [fromIntegral (byte j) * (256 ^ j)
30+
| j <- [0 .. BS.length c - 1]
31+
]
32+
33+
char32 :: Integer -> Char
34+
char32 i = digits32 V.! digitInd
35+
where
36+
digitInd = fromIntegral $
37+
bAsInteger
38+
`div` (32^i)
39+
`mod` 32

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module System.Nix.Build (
1313
import Data.Time (UTCTime)
1414
import Data.Text (Text)
1515
import Data.HashSet (HashSet)
16-
import System.Nix.Path (Path)
1716

1817
-- keep the order of these Enums to match enums from reference implementations
1918
-- src/libstore/store-api.hh

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

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

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

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
{-|
22
Description : Cryptographic hashes for hnix-store.
3-
Maintainer : Shea Levy <[email protected]>; Greg Hale <[email protected]>
43
-}
5-
{-# LANGUAGE DataKinds #-}
6-
{-# LANGUAGE TypeApplications #-}
7-
{-# LANGUAGE ScopedTypeVariables #-}
8-
{-# LANGUAGE FlexibleContexts #-}
9-
{-# LANGUAGE TypeApplications #-}
10-
{-# LANGUAGE TypeFamilies #-}
11-
{-# LANGUAGE TypeOperators #-}
12-
{-# LANGUAGE CPP #-}
134
module System.Nix.Hash (
145
HNix.Digest
156

16-
, HNix.HashAlgorithm
17-
, HNix.HashAlgorithm'(..)
18-
, HNix.AlgoVal(..)
19-
, HNix.HasDigest(..)
7+
, HNix.HashAlgorithm(..)
8+
, HNix.ValidAlgo(..)
9+
, HNix.NamedAlgo(..)
10+
, HNix.SomeNamedDigest(..)
2011
, HNix.hash
2112
, HNix.hashLazy
22-
23-
, HNix.printAsBase16
24-
, HNix.printAsBase32
25-
, HNix.printHashAlgo
13+
, HNix.encodeBase32
14+
, HNix.encodeBase16
2615
) where
2716

2817
import qualified System.Nix.Internal.Hash as HNix
29-

0 commit comments

Comments
 (0)