Skip to content

Commit 70eb0d3

Browse files
authored
Merge pull request #255 from haskell-nix/srk/daemon
cereal remote, server side integration
2 parents 92b83e8 + 556e0a9 commit 70eb0d3

Some content is hidden

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

42 files changed

+2807
-681
lines changed

.github/workflows/ci.dhall.frozen

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let haskellCi =
22
https://raw.githubusercontent.com/sorki/github-actions-dhall/main/haskell-ci.dhall
3-
sha256:5d7058a7684fd5315467b562853bd1c4a43da691c09293d3715ee739dfa26e08
3+
sha256:a39801f73d93c6e0f91942755ef8ae4c50947e9a9b180b6724957229470f7b8d
44

55
let defSteps = haskellCi.defaultCabalSteps
66

.github/workflows/ci.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ jobs:
5959
- "macos-latest"
6060
name: Haskell CI
6161
'on':
62-
pull_request: {}
6362
push: {}
6463
schedule:
6564
- cron: "4 20 10 * *"

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ package hnix-store-nar
2020
flags: +bounded_memory
2121

2222
package hnix-store-remote
23-
flags: +build-readme +io-testsuite
23+
flags: +build-derivation +build-readme +io-testsuite

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

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module System.Nix.Base
66

77
import Data.ByteString (ByteString)
88
import Data.Text (Text)
9+
import GHC.Generics (Generic)
910

1011
import qualified Data.Text.Encoding
1112
import qualified Data.ByteString.Base16
@@ -21,6 +22,7 @@ data BaseEncoding
2122
-- & NixBase seems be the most widely used in Nix.
2223
| Base16
2324
| Base64
25+
deriving (Bounded, Eq, Enum, Generic, Ord, Show)
2426

2527
-- | Encode @ByteString@ with @Base@ encoding, produce @Text@.
2628
encodeWith :: BaseEncoding -> ByteString -> Text

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

+24-17
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,28 @@ import GHC.Generics (Generic)
1515

1616
-- keep the order of these Enums to match enums from reference implementations
1717
-- src/libstore/store-api.hh
18-
data BuildMode = Normal | Repair | Check
18+
data BuildMode
19+
= BuildMode_Normal
20+
| BuildMode_Repair
21+
| BuildMode_Check
1922
deriving (Eq, Generic, Ord, Enum, Show)
2023

2124
data BuildStatus =
22-
Built
23-
| Substituted
24-
| AlreadyValid
25-
| PermanentFailure
26-
| InputRejected
27-
| OutputRejected
28-
| TransientFailure -- possibly transient
29-
| CachedFailure -- no longer used
30-
| TimedOut
31-
| MiscFailure
32-
| DependencyFailed
33-
| LogLimitExceeded
34-
| NotDeterministic
35-
| ResolvesToAlreadyValid
36-
| NoSubstituters
25+
BuildStatus_Built
26+
| BuildStatus_Substituted
27+
| BuildStatus_AlreadyValid
28+
| BuildStatus_PermanentFailure
29+
| BuildStatus_InputRejected
30+
| BuildStatus_OutputRejected
31+
| BuildStatus_TransientFailure -- possibly transient
32+
| BuildStatus_CachedFailure -- no longer used
33+
| BuildStatus_TimedOut
34+
| BuildStatus_MiscFailure
35+
| BuildStatus_DependencyFailed
36+
| BuildStatus_LogLimitExceeded
37+
| BuildStatus_NotDeterministic
38+
| BuildStatus_ResolvesToAlreadyValid
39+
| BuildStatus_NoSubstituters
3740
deriving (Eq, Generic, Ord, Enum, Show)
3841

3942
-- | Result of the build
@@ -55,4 +58,8 @@ data BuildResult = BuildResult
5558

5659
buildSuccess :: BuildResult -> Bool
5760
buildSuccess BuildResult {..} =
58-
status `elem` [Built, Substituted, AlreadyValid]
61+
status `elem`
62+
[ BuildStatus_Built
63+
, BuildStatus_Substituted
64+
, BuildStatus_AlreadyValid
65+
]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ decodeDigestWith b x =
167167
let
168168
toEither =
169169
maybeToRight
170-
("Cryptonite was not able to convert '(ByteString -> Digest a)' for: '" <> show bs <>"'.")
170+
("Crypton was not able to convert '(ByteString -> Digest a)' for: '" <> show bs <>"'.")
171171
(toEither . Crypto.Hash.digestFromByteString) bs
172172
where
173173
-- To not depend on @extra@

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

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module System.Nix.StorePath
3434
, pathParser
3535
-- * Utilities for tests
3636
, unsafeMakeStorePath
37+
, unsafeMakeStorePathHashPart
3738
) where
3839

3940
import Crypto.Hash (HashAlgorithm)
@@ -307,3 +308,11 @@ unsafeMakeStorePath
307308
-> StorePathName
308309
-> StorePath
309310
unsafeMakeStorePath = StorePath
311+
312+
-- | Path hash parts rarely need to be constructed directly.
313+
-- Prefer @mkStorePathHashPart@
314+
-- Used by remote store in wire protocol
315+
unsafeMakeStorePathHashPart
316+
:: ByteString
317+
-> StorePathHashPart
318+
unsafeMakeStorePathHashPart = StorePathHashPart
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{-# LANGUAGE LambdaCase #-}
2+
module Main where
3+
4+
import Data.Default.Class (Default(def))
5+
import Data.Text (Text)
6+
import System.Nix.Derivation (Derivation)
7+
import System.Nix.StorePath (StorePath)
8+
9+
import qualified Data.Text
10+
import qualified Data.Text.IO
11+
import qualified Data.Attoparsec.Text
12+
import qualified System.Environment
13+
import qualified System.Nix.Build
14+
import qualified System.Nix.Derivation
15+
import qualified System.Nix.StorePath
16+
import qualified System.Nix.Store.Remote
17+
18+
parseDerivation :: FilePath -> IO (Derivation StorePath Text)
19+
parseDerivation source = do
20+
contents <- Data.Text.IO.readFile source
21+
case Data.Attoparsec.Text.parseOnly
22+
(System.Nix.Derivation.parseDerivation def) contents of
23+
Left e -> error e
24+
Right drv -> pure drv
25+
26+
main :: IO ()
27+
main = System.Environment.getArgs >>= \case
28+
[filename] -> do
29+
case System.Nix.StorePath.parsePathFromText def (Data.Text.pack filename) of
30+
Left e -> error $ show e
31+
Right p -> do
32+
d <- parseDerivation filename
33+
out <-
34+
System.Nix.Store.Remote.runStore
35+
$ System.Nix.Store.Remote.buildDerivation
36+
p
37+
d
38+
System.Nix.Build.BuildMode_Normal
39+
print out
40+
_ -> error "No input derivation file"
41+

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

+57-12
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ common commons
2626
, DeriveFoldable
2727
, DeriveTraversable
2828
, DeriveLift
29+
, DerivingVia
2930
, FlexibleContexts
3031
, FlexibleInstances
32+
, GADTs
3133
, RecordWildCards
3234
, ScopedTypeVariables
3335
, StandaloneDeriving
3436
, TypeApplications
3537
, TypeSynonymInstances
3638
, InstanceSigs
39+
, KindSignatures
3740
, MultiParamTypeClasses
3841
, TupleSections
3942
, LambdaCase
@@ -53,6 +56,12 @@ flag io-testsuite
5356
Enable testsuite, which requires external
5457
binaries and Linux namespace support.
5558

59+
flag build-derivation
60+
default:
61+
False
62+
description:
63+
Build build-derivation executable
64+
5665
flag build-readme
5766
default:
5867
False
@@ -62,37 +71,68 @@ flag build-readme
6271
library
6372
import: commons
6473
exposed-modules:
65-
System.Nix.Store.Remote
66-
, System.Nix.Store.Remote.Binary
67-
, System.Nix.Store.Remote.Serialize
68-
, System.Nix.Store.Remote.Serialize.Prim
74+
Data.Serializer
75+
, Data.Serializer.Example
76+
, System.Nix.Store.Remote
77+
, System.Nix.Store.Remote.Arbitrary
6978
, System.Nix.Store.Remote.Logger
79+
, System.Nix.Store.Remote.MonadStore
7080
, System.Nix.Store.Remote.Protocol
81+
, System.Nix.Store.Remote.Serialize
82+
, System.Nix.Store.Remote.Serialize.Prim
83+
, System.Nix.Store.Remote.Serializer
84+
, System.Nix.Store.Remote.Socket
7185
, System.Nix.Store.Remote.Types
72-
, System.Nix.Store.Remote.Util
86+
, System.Nix.Store.Remote.Types.Activity
87+
, System.Nix.Store.Remote.Types.CheckMode
88+
, System.Nix.Store.Remote.Types.GC
89+
, System.Nix.Store.Remote.Types.Logger
90+
, System.Nix.Store.Remote.Types.ProtoVersion
91+
, System.Nix.Store.Remote.Types.StoreConfig
92+
, System.Nix.Store.Remote.Types.SubstituteMode
93+
, System.Nix.Store.Remote.Types.Verbosity
94+
, System.Nix.Store.Remote.Types.WorkerOp
7395

7496
build-depends:
7597
base >=4.12 && <5
7698
, hnix-store-core >= 0.8 && <0.9
7799
, hnix-store-nar >= 0.1
78100
, attoparsec
79-
, binary
80101
, bytestring
81102
, cereal
82103
, containers
83104
, crypton
84105
, data-default-class
85106
, dependent-sum > 0.7 && < 1
107+
, generic-arbitrary < 1.1
108+
, hashable
86109
, text
87110
, time
111+
, transformers
88112
, network
89113
, mtl
114+
, QuickCheck
115+
, quickcheck-instances
90116
, unordered-containers
91-
, transformers
92117
, vector
93118
hs-source-dirs: src
94119
ghc-options: -Wall
95120

121+
executable build-derivation
122+
if !flag(build-derivation)
123+
buildable: False
124+
build-depends:
125+
base >=4.12 && <5
126+
, attoparsec
127+
, hnix-store-core
128+
, hnix-store-remote
129+
, data-default-class
130+
, text
131+
default-language: Haskell2010
132+
main-is: BuildDerivation.hs
133+
hs-source-dirs: app
134+
ghc-options: -Wall -threaded -rtsopts "-with-rtsopts -N"
135+
96136
executable remote-readme
97137
if !flag(build-readme)
98138
buildable: False
@@ -110,8 +150,10 @@ test-suite remote
110150
type: exitcode-stdio-1.0
111151
main-is: Driver.hs
112152
hs-source-dirs: tests
113-
ghc-options: -Wall
153+
ghc-options: -Wall -threaded -rtsopts "-with-rtsopts -N"
114154
other-modules:
155+
Data.SerializerSpec
156+
NixSerializerSpec
115157
SerializeSpec
116158
build-tool-depends:
117159
hspec-discover:hspec-discover
@@ -121,6 +163,9 @@ test-suite remote
121163
, hnix-store-remote
122164
, hnix-store-tests
123165
, cereal
166+
, crypton
167+
, dependent-sum > 0.7 && < 1
168+
, some > 1.0.5 && < 2
124169
, text
125170
, time
126171
, hspec
@@ -153,14 +198,14 @@ test-suite remote-io
153198
, containers
154199
, crypton
155200
, directory
156-
, process
157201
, filepath
202+
, hspec
158203
, hspec-expectations-lifted
159-
, text
204+
, linux-namespaces
205+
, process
160206
, tasty
161-
, hspec
162207
, tasty-hspec
163-
, linux-namespaces
164208
, temporary
209+
, text
165210
, unix
166211
, unordered-containers

0 commit comments

Comments
 (0)