Skip to content

Commit

Permalink
Merge pull request haskell-nix#241 from haskell-nix/srk/split
Browse files Browse the repository at this point in the history
Split core into multiple packages
  • Loading branch information
sorki authored Nov 21, 2023
2 parents 9118c30 + 13064a9 commit f1741e8
Show file tree
Hide file tree
Showing 50 changed files with 778 additions and 404 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
dist
dist-newstyle
.ghc.environment*
.ghci
.ghci_history
.direnv
.envrc
cabal.project.local~
cabal.project.local
attic
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ packages:
./hnix-store-core/hnix-store-core.cabal
./hnix-store-db/hnix-store-db.cabal
./hnix-store-remote/hnix-store-remote.cabal
./hnix-store-tests/hnix-store-tests.cabal

-- till https://github.com/obsidiansystems/dependent-sum/pull/80
allow-newer:
Expand Down
3 changes: 3 additions & 0 deletions cabal.project.local.ci
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ package hnix-store-db

package hnix-store-remote
ghc-options: -Wunused-packages -Wall -Werror

package hnix-store-tests
ghc-options: -Wunused-packages -Wall -Werror
3 changes: 2 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ in {
inherit (haskellPackages)
hnix-store-core
hnix-store-db
hnix-store-remote;
hnix-store-remote
hnix-store-tests;
haskellPackages = lib.dontRecurseIntoAttrs haskellPackages;
pkgs = lib.dontRecurseIntoAttrs pkgs;
}
1 change: 0 additions & 1 deletion hnix-store-core/.envrc

This file was deleted.

1 change: 0 additions & 1 deletion hnix-store-core/.ghci

This file was deleted.

14 changes: 3 additions & 11 deletions hnix-store-core/hnix-store-core.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: hnix-store-core
version: 0.7.0.0
version: 0.8.0.0
synopsis: Core effects for interacting with the Nix store.
description:
This package contains types and functions needed to describe
Expand Down Expand Up @@ -38,7 +38,6 @@ common commons
, FlexibleContexts
, FlexibleInstances
, GADTs
, StandaloneDeriving
, ScopedTypeVariables
, StandaloneDeriving
, RecordWildCards
Expand Down Expand Up @@ -80,8 +79,8 @@ library
base >=4.12 && <5
, attoparsec
, algebraic-graphs >= 0.5 && < 0.8
, base16-bytestring
, base64-bytestring
, base16-bytestring >= 1.0
, base64-bytestring >= 1.2.1
, bytestring
, case-insensitive
, cereal
Expand All @@ -90,7 +89,6 @@ library
, data-default-class
, dependent-sum > 0.7
, dependent-sum-template > 0.1.1 && < 0.3
, generic-arbitrary < 1.1
-- Required for cryptonite low-level type convertion
, memory
, cryptonite
Expand All @@ -101,8 +99,6 @@ library
, monad-control
, mtl
, nix-derivation >= 1.1.1 && <2
, QuickCheck
, quickcheck-instances
, saltine >= 0.2 && < 0.3
, some > 1.0.5 && < 2
, time
Expand All @@ -125,11 +121,8 @@ test-suite format-tests
main-is: Driver.hs
other-modules:
Derivation
DerivedPath
ContentAddress
NarFormat
Hash
StorePath
hs-source-dirs:
tests
build-tool-depends:
Expand All @@ -148,7 +141,6 @@ test-suite format-tests
, directory
, filepath
, process
, nix-derivation >= 1.1.1 && <2
, tasty
, tasty-golden
, hspec
Expand Down
1 change: 0 additions & 1 deletion hnix-store-core/shell.nix

This file was deleted.

16 changes: 3 additions & 13 deletions hnix-store-core/src/System/Nix/Base.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# LANGUAGE CPP #-}

module System.Nix.Base
( BaseEncoding(Base16,NixBase32,Base64)
, encodeWith
Expand All @@ -19,7 +17,8 @@ import qualified System.Nix.Base32 -- Nix has own Base32 encoding
data BaseEncoding
= NixBase32
-- | ^ Nix has a special map of Base32 encoding
-- Placed first, since it determines Haskell optimizations of pattern matches, & NixBase seems be the most widely used in Nix.
-- Placed first, since it determines Haskell optimizations of pattern matches,
-- & NixBase seems be the most widely used in Nix.
| Base16
| Base64

Expand All @@ -35,18 +34,9 @@ encodeWith Base64 =

-- | Take the input & @Base@ encoding witness -> decode into @Text@.
decodeWith :: BaseEncoding -> Text -> Either String ByteString
#if MIN_VERSION_base16_bytestring(1,0,0)
decodeWith Base16 =
Data.ByteString.Base16.decode
Data.ByteString.Base16.decode
. Data.Text.Encoding.encodeUtf8
#else
decodeWith Base16 = lDecode -- this tacit sugar simply makes GHC pleased with number of args
where
lDecode t =
case Data.ByteString.Base16.decode (Data.Text.Encoding.encodeUtf8 t) of
(x, "") -> pure $ x
_ -> Left $ "Unable to decode base16 string" <> toString t
#endif
decodeWith NixBase32 = System.Nix.Base32.decode
decodeWith Base64 =
Data.ByteString.Base64.decode
Expand Down
8 changes: 0 additions & 8 deletions hnix-store-core/src/System/Nix/Build.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-- due to recent generic-arbitrary
{-# OPTIONS_GHC -fconstraint-solver-iterations=0 #-}
{-|
Description : Build related types
Maintainer : srk <[email protected]>
Expand All @@ -14,15 +12,11 @@ module System.Nix.Build
import Data.Time (UTCTime)
import Data.Text (Text)
import GHC.Generics (Generic)
import Test.QuickCheck (Arbitrary(..))
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
import Test.QuickCheck.Instances ()

-- keep the order of these Enums to match enums from reference implementations
-- src/libstore/store-api.hh
data BuildMode = Normal | Repair | Check
deriving (Eq, Generic, Ord, Enum, Show)
deriving Arbitrary via GenericArbitrary BuildMode

data BuildStatus =
Built
Expand All @@ -41,7 +35,6 @@ data BuildStatus =
| ResolvesToAlreadyValid
| NoSubstituters
deriving (Eq, Generic, Ord, Enum, Show)
deriving Arbitrary via GenericArbitrary BuildStatus

-- | Result of the build
data BuildResult = BuildResult
Expand All @@ -59,7 +52,6 @@ data BuildResult = BuildResult
stopTime :: !UTCTime
}
deriving (Eq, Generic, Ord, Show)
deriving Arbitrary via GenericArbitrary BuildResult

buildSuccess :: BuildResult -> Bool
buildSuccess BuildResult {..} =
Expand Down
14 changes: 2 additions & 12 deletions hnix-store-core/src/System/Nix/ContentAddress.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module System.Nix.ContentAddress (
ContentAddress
, ContentAddressMethod
, FileIngestionMethod
, contentAddressBuilder
, contentAddressParser
, buildContentAddress
Expand All @@ -16,9 +18,6 @@ import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder)
import GHC.Generics (Generic)
import System.Nix.Hash (HashAlgo)
import Test.QuickCheck (Arbitrary)
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
import Test.QuickCheck.Instances ()

import qualified Data.Attoparsec.Text
import qualified Data.Text.Lazy
Expand All @@ -30,9 +29,6 @@ data FileIngestionMethod
| FileRecursive
deriving (Eq, Bounded, Generic, Enum, Ord, Show)

deriving via GenericArbitrary FileIngestionMethod
instance Arbitrary FileIngestionMethod

data ContentAddressMethod
= FileIngestionMethod !FileIngestionMethod
-- ^ The path was added to the store via makeFixedOutputPath or
Expand All @@ -44,9 +40,6 @@ data ContentAddressMethod
-- file contents.
deriving (Eq, Generic, Ord, Show)

deriving via GenericArbitrary ContentAddressMethod
instance Arbitrary ContentAddressMethod

-- | An address for a content-addressable store path, i.e. one whose
-- store path hash is purely a function of its contents (as opposed to
-- paths that are derivation outputs, whose hashes are a function of
Expand All @@ -61,9 +54,6 @@ data ContentAddress = ContentAddress
(DSum HashAlgo Digest)
deriving (Eq, Generic, Ord, Show)

deriving via GenericArbitrary ContentAddress
instance Arbitrary ContentAddress

-- | Marshall `ContentAddressableAddress` to `Text`
-- in form suitable for remote protocol usage.
buildContentAddress :: ContentAddress -> Text
Expand Down
16 changes: 4 additions & 12 deletions hnix-store-core/src/System/Nix/Derivation.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
-- due to recent generic-arbitrary
{-# OPTIONS_GHC -Wno-orphans -fconstraint-solver-iterations=0 #-}

module System.Nix.Derivation
( parseDerivation
, buildDerivation
-- Re-exports
, Derivation(..)
, DerivationOutput(..)
) where

import Data.Attoparsec.Text.Lazy (Parser)
import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder)
import Test.QuickCheck (Arbitrary(..))
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
import Test.QuickCheck.Instances ()

import Nix.Derivation (Derivation, DerivationOutput)
import Nix.Derivation (Derivation(..), DerivationOutput(..))
import System.Nix.StorePath (StoreDir, StorePath)

import qualified Data.Attoparsec.Text.Lazy
Expand All @@ -24,11 +21,6 @@ import qualified Data.Text.Lazy.Builder
import qualified Nix.Derivation
import qualified System.Nix.StorePath

deriving via GenericArbitrary (Derivation StorePath Text)
instance Arbitrary (Derivation StorePath Text)
deriving via GenericArbitrary (DerivationOutput StorePath Text)
instance Arbitrary (DerivationOutput StorePath Text)

parseDerivation :: StoreDir -> Parser (Derivation StorePath Text)
parseDerivation expectedRoot =
Nix.Derivation.parseDerivationWith
Expand Down
9 changes: 1 addition & 8 deletions hnix-store-core/src/System/Nix/DerivedPath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module System.Nix.DerivedPath (
OutputsSpec(..)
, DerivedPath(..)
, ParseOutputsError(..)
, parseOutputsSpec
, outputsSpecToText
, parseDerivedPath
Expand All @@ -14,8 +15,6 @@ import GHC.Generics (Generic)
import Data.Set (Set)
import Data.Text (Text)
import System.Nix.StorePath (StoreDir, StorePath, StorePathName, InvalidPathError)
import Test.QuickCheck (Arbitrary)
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))

import qualified Data.Set
import qualified Data.Text
Expand All @@ -26,17 +25,11 @@ data OutputsSpec =
| OutputsSpec_Names (Set StorePathName)
deriving (Eq, Generic, Ord, Show)

deriving via GenericArbitrary OutputsSpec
instance Arbitrary OutputsSpec

data DerivedPath =
DerivedPath_Opaque StorePath
| DerivedPath_Built StorePath OutputsSpec
deriving (Eq, Generic, Ord, Show)

deriving via GenericArbitrary DerivedPath
instance Arbitrary DerivedPath

data ParseOutputsError =
ParseOutputsError_InvalidPath InvalidPathError
| ParseOutputsError_NoNames
Expand Down
24 changes: 0 additions & 24 deletions hnix-store-core/src/System/Nix/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import Data.Some (Some(Some))
import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder)
import System.Nix.Base (BaseEncoding(..))
import Test.QuickCheck (Arbitrary(arbitrary), oneof)
import Test.QuickCheck.Instances ()

import qualified Crypto.Hash
import qualified Data.ByteArray
Expand All @@ -64,20 +62,6 @@ instance NamedAlgo SHA256 where
instance NamedAlgo SHA512 where
algoName = "sha512"

-- * Arbitrary @Digest@s

instance Arbitrary (Digest MD5) where
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary

instance Arbitrary (Digest SHA1) where
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary

instance Arbitrary (Digest SHA256) where
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary

instance Arbitrary (Digest SHA512) where
arbitrary = Crypto.Hash.hash @ByteString <$> arbitrary

data HashAlgo :: Type -> Type where
HashAlgo_MD5 :: HashAlgo MD5
HashAlgo_SHA1 :: HashAlgo SHA1
Expand Down Expand Up @@ -107,14 +91,6 @@ textToAlgo = \case
"sha512" -> Right $ Some HashAlgo_SHA512
name -> Left $ "Unknown hash name: " <> Data.Text.unpack name

instance Arbitrary (DSum HashAlgo Digest) where
arbitrary = oneof
[ (HashAlgo_MD5 :=>) <$> arbitrary
, (HashAlgo_SHA1 :=>) <$> arbitrary
, (HashAlgo_SHA256 :=>) <$> arbitrary
, (HashAlgo_SHA512 :=>) <$> arbitrary
]

-- | Make @DSum HashAlgo Digest@ based on provided SRI hash name
-- and its encoded form
mkNamedDigest
Expand Down
10 changes: 0 additions & 10 deletions hnix-store-core/src/System/Nix/Signature.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-|
Description : Nix-relevant interfaces to NaCl signatures.
-}
Expand All @@ -16,24 +15,15 @@ import GHC.Generics (Generic)
import qualified Data.ByteString
import qualified Data.Coerce

-- 2021-05-30: NOTE: Please, clean-up these overloads in ~2022
#if MIN_VERSION_saltine(0,2,0)
import qualified Crypto.Saltine.Internal.Sign as NaClSizes
#else
import qualified Crypto.Saltine.Internal.ByteSizes as NaClSizes
#endif

-- | A NaCl signature.
newtype Signature = Signature ByteString
deriving (Eq, Generic, Ord, Show)

instance IsEncoding Signature where
decode s
#if MIN_VERSION_saltine(0,2,0)
| Data.ByteString.length s == NaClSizes.sign_bytes = Just $ Signature s
#else
| Data.ByteString.length s == NaClSizes.sign = Just $ Signature s
#endif
| otherwise = Nothing
encode = Data.Coerce.coerce

Expand Down
Loading

0 comments on commit f1741e8

Please sign in to comment.