Skip to content

Commit 21040fb

Browse files
authored
Merge pull request #276 from haskell-nix/srk/daemon
Some more server
2 parents 11da925 + 619687b commit 21040fb

File tree

21 files changed

+911
-732
lines changed

21 files changed

+911
-732
lines changed

docs/01-Contributors.org

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ in order of appearance:
3131
+ Ryan Trinkle @ryantrinkle
3232
+ Travis Whitaker @TravisWhitaker
3333
+ Andrea Bedini @andreabedini
34+
+ Dan Bornside @danbornside

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ import qualified System.Nix.StorePath
2525

2626
data OutputsSpec =
2727
OutputsSpec_All
28+
-- ^ Wildcard spec (^*) meaning all outputs
2829
| OutputsSpec_Names (Set OutputName)
30+
-- ^ Set of specific outputs
2931
deriving (Eq, Generic, Ord, Show)
3032

3133
data DerivedPath =
3234
DerivedPath_Opaque StorePath
35+
-- ^ Fully evaluated store path that can't be built
36+
-- but can be fetched
3337
| DerivedPath_Built StorePath OutputsSpec
38+
-- ^ Derivation path and the outputs built from it
3439
deriving (Eq, Generic, Ord, Show)
3540

3641
data ParseOutputsError =

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module System.Nix.Realisation (
88
, derivationOutputBuilder
99
, derivationOutputParser
1010
, Realisation(..)
11+
, RealisationWithId(..)
1112
) where
1213

1314
import Crypto.Hash (Digest)
@@ -80,8 +81,7 @@ derivationOutputBuilder outputName DerivationOutput{..} =
8081
--
8182
-- realisationId is ommited since it is a key
8283
-- of type @DerivationOutput OutputName@ so
83-
-- we will use a tuple like @(DerivationOutput OutputName, Realisation)@
84-
-- instead.
84+
-- we will use @RealisationWithId@ newtype
8585
data Realisation = Realisation
8686
{ realisationOutPath :: StorePath
8787
-- ^ Output path
@@ -90,3 +90,14 @@ data Realisation = Realisation
9090
, realisationDependencies :: Map (DerivationOutput OutputName) StorePath
9191
-- ^ Dependent realisations required for this one to be valid
9292
} deriving (Eq, Generic, Ord, Show)
93+
94+
-- | For wire protocol
95+
--
96+
-- We store this normalized in @Build.buildResultBuiltOutputs@
97+
-- as @Map (DerivationOutput OutputName) Realisation@
98+
-- but wire protocol needs it de-normalized so we
99+
-- need a special (From|To)JSON instances for it
100+
newtype RealisationWithId = RealisationWithId
101+
{ unRealisationWithId :: (DerivationOutput OutputName, Realisation)
102+
}
103+
deriving (Eq, Generic, Ord, Show)

hnix-store-json/src/System/Nix/JSON.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Data.Aeson
1313
import Deriving.Aeson
1414
import System.Nix.Base (BaseEncoding(NixBase32))
1515
import System.Nix.OutputName (OutputName)
16-
import System.Nix.Realisation (DerivationOutput, Realisation)
16+
import System.Nix.Realisation (DerivationOutput, Realisation, RealisationWithId(..))
1717
import System.Nix.Signature (Signature)
1818
import System.Nix.StorePath (StoreDir(..), StorePath, StorePathName, StorePathHashPart)
1919

@@ -159,18 +159,18 @@ deriving
159159
instance FromJSON Realisation
160160

161161
-- For a keyed version of Realisation
162-
-- we use (DerivationOutput OutputName, Realisation)
162+
-- we use RealisationWithId (DerivationOutput OutputName, Realisation)
163163
-- instead of Realisation.id :: (DerivationOutput OutputName)
164164
-- field.
165-
instance {-# OVERLAPPING #-} ToJSON (DerivationOutput OutputName, Realisation) where
166-
toJSON (drvOut, r) =
165+
instance ToJSON RealisationWithId where
166+
toJSON (RealisationWithId (drvOut, r)) =
167167
case toJSON r of
168168
Object o -> Object $ Data.Aeson.KeyMap.insert "id" (toJSON drvOut) o
169169
_ -> error "absurd"
170170

171-
instance {-# OVERLAPPING #-} FromJSON (DerivationOutput OutputName, Realisation) where
171+
instance FromJSON RealisationWithId where
172172
parseJSON v@(Object o) = do
173173
r <- parseJSON @Realisation v
174174
drvOut <- o .: "id"
175-
pure (drvOut, r)
175+
pure (RealisationWithId (drvOut, r))
176176
parseJSON x = fail $ "Expected Object but got " ++ show x

hnix-store-remote/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ via `nix-daemon`.
1414
```haskell
1515
{-# LANGUAGE OverloadedStrings #-}
1616

17-
import Control.Monad (void)
18-
import Control.Monad.IO.Class (liftIO)
1917
import System.Nix.StorePath (mkStorePathName)
2018
import System.Nix.Store.Remote
2119

2220
main :: IO ()
2321
main = do
24-
void $ runStore $ do
22+
runStore $ do
2523
syncWithGC
2624
roots <- findRoots
27-
liftIO $ print roots
2825

2926
res <- case mkStorePathName "hnix-store" of
3027
Left e -> error (show e)
@@ -33,5 +30,7 @@ main = do
3330
(StoreText name "Hello World!")
3431
mempty
3532
RepairMode_DontRepair
36-
liftIO $ print res
33+
34+
pure (roots, res)
35+
>>= print
3736
```

hnix-store-remote/app/BuildDerivation.hs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,23 @@
22
module Main where
33

44
import Data.Default.Class (Default(def))
5-
import Data.Text (Text)
6-
import System.Nix.Derivation (Derivation)
7-
import System.Nix.StorePath (StorePath)
85

96
import qualified Data.Text
10-
import qualified Data.Text.IO
11-
import qualified Data.Attoparsec.Text
127
import qualified System.Environment
138
import qualified System.Nix.Build
14-
import qualified System.Nix.Derivation
159
import qualified System.Nix.StorePath
1610
import qualified System.Nix.Store.Remote
1711

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-
2612
main :: IO ()
2713
main = System.Environment.getArgs >>= \case
2814
[filename] -> do
2915
case System.Nix.StorePath.parsePathFromText def (Data.Text.pack filename) of
3016
Left e -> error $ show e
3117
Right p -> do
32-
d <- parseDerivation filename
3318
out <-
3419
System.Nix.Store.Remote.runStore
3520
$ System.Nix.Store.Remote.buildDerivation
3621
p
37-
d
3822
System.Nix.Build.BuildMode_Normal
3923
print out
4024
_ -> error "No input derivation file"

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ common commons
4646
, ViewPatterns
4747
default-language: Haskell2010
4848

49-
common tests
50-
import: commons
51-
build-tool-depends:
52-
tasty-discover:tasty-discover
53-
5449
flag io-testsuite
5550
default:
5651
False
@@ -119,7 +114,9 @@ library
119114
, data-default-class
120115
, dependent-sum > 0.7
121116
, dependent-sum-template >= 0.2.0.1 && < 0.3
117+
-- , directory
122118
, dlist >= 1.0
119+
, exceptions
123120
, generic-arbitrary < 1.1
124121
, hashable
125122
, text
@@ -139,7 +136,6 @@ executable build-derivation
139136
buildable: False
140137
build-depends:
141138
base >=4.12 && <5
142-
, attoparsec
143139
, hnix-store-core
144140
, hnix-store-remote
145141
, data-default-class
@@ -163,7 +159,7 @@ executable remote-readme
163159
ghc-options: -pgmL markdown-unlit -Wall
164160

165161
test-suite remote
166-
import: tests
162+
import: commons
167163
type: exitcode-stdio-1.0
168164
main-is: Driver.hs
169165
hs-source-dirs: tests
@@ -187,7 +183,7 @@ test-suite remote
187183
, QuickCheck
188184

189185
test-suite remote-io
190-
import: tests
186+
import: commons
191187

192188
if !flag(io-testsuite) || os(darwin)
193189
buildable: False
@@ -206,9 +202,11 @@ test-suite remote-io
206202
, hnix-store-remote
207203
, hnix-store-tests
208204
, bytestring
205+
, concurrency
209206
, containers
210207
, crypton
211208
, directory
209+
, exceptions
212210
, filepath
213211
, hspec
214212
, hspec-expectations-lifted

0 commit comments

Comments
 (0)