Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more server #276

Merged
merged 27 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8078f0f
remote: drop common tests cabal stanza
sorki Dec 8, 2023
2bdd171
wip/remote: add daemon runners, simplify server using StoreReply
sorki Dec 8, 2023
3576273
core,json: wrap (DerivationOutput OutputName, Realisation) tuple into…
sorki Dec 8, 2023
da9b46c
core: add some haddocks to OutputSpec, DerivedPath
sorki Dec 8, 2023
696f9e8
remote: simplify buildDerivation
sorki Dec 8, 2023
5e909db
remote: fix verison/version typo
sorki Dec 9, 2023
4562922
remote: neaten readme
sorki Dec 9, 2023
7b41967
remote: monadic collapse
sorki Dec 8, 2023
656d4dd
remote: TestStoreConfig no longer needed
sorki Dec 9, 2023
1f1d437
remote: align record field naming
sorki Dec 9, 2023
960407b
remote: add StoreConnection, reclaim runStoreSocket, now greetServer
sorki Dec 9, 2023
bb9bc17
server: -funroll-gadt
sorki Dec 10, 2023
8eb0059
remote: neaten NixDaemonSpec, silence nix-store and daemon with grep -v
sorki Dec 10, 2023
30baaf3
remote: NixDaemonSpec pass StoreConnection, StoreDir
sorki Dec 10, 2023
4651980
remote: NixDaemonSpec MITM
sorki Dec 10, 2023
3dc7ab6
remote: add postGreet so we setStoreDir in Server as well
sorki Dec 10, 2023
e2381c8
remote: less chatty server
sorki Dec 10, 2023
3d774b8
remote/server: add proxyNarSource
sorki Dec 10, 2023
4aeee1e
remote/server: tidy
sorki Dec 10, 2023
dea03e0
remote/server: propagate errors from proxy handler
sorki Dec 10, 2023
3eb3466
remote: fix roots test for MITM vs Direct
sorki Dec 10, 2023
29f58f4
remote: fix pretty TODO failing to parse on old GHC
sorki Dec 10, 2023
6840a2d
Add danbornside to contributors
sorki Dec 10, 2023
b754f3a
remote: NixDaemonSpec, shell -> proc for nix-daemon so it gets termin…
sorki Dec 10, 2023
fbc5599
core: fix Wildcard spec haddock
sorki Dec 11, 2023
e374687
remote/server: add note that proxyNarSource is a hack
sorki Dec 11, 2023
619687b
remote: fix flaky collectGarbage for MITM test
sorki Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/01-Contributors.org
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ in order of appearance:
+ Ryan Trinkle @ryantrinkle
+ Travis Whitaker @TravisWhitaker
+ Andrea Bedini @andreabedini
+ Dan Bornside @danbornside
5 changes: 5 additions & 0 deletions hnix-store-core/src/System/Nix/DerivedPath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ import qualified System.Nix.StorePath

data OutputsSpec =
OutputsSpec_All
-- ^ Wildcard spec (^*) meaning all outputs
| OutputsSpec_Names (Set OutputName)
-- ^ Set of specific outputs
deriving (Eq, Generic, Ord, Show)

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

data ParseOutputsError =
Expand Down
15 changes: 13 additions & 2 deletions hnix-store-core/src/System/Nix/Realisation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module System.Nix.Realisation (
, derivationOutputBuilder
, derivationOutputParser
, Realisation(..)
, RealisationWithId(..)
) where

import Crypto.Hash (Digest)
Expand Down Expand Up @@ -80,8 +81,7 @@ derivationOutputBuilder outputName DerivationOutput{..} =
--
-- realisationId is ommited since it is a key
-- of type @DerivationOutput OutputName@ so
-- we will use a tuple like @(DerivationOutput OutputName, Realisation)@
-- instead.
-- we will use @RealisationWithId@ newtype
data Realisation = Realisation
{ realisationOutPath :: StorePath
-- ^ Output path
Expand All @@ -90,3 +90,14 @@ data Realisation = Realisation
, realisationDependencies :: Map (DerivationOutput OutputName) StorePath
-- ^ Dependent realisations required for this one to be valid
} deriving (Eq, Generic, Ord, Show)

-- | For wire protocol
--
-- We store this normalized in @Build.buildResultBuiltOutputs@
-- as @Map (DerivationOutput OutputName) Realisation@
-- but wire protocol needs it de-normalized so we
-- need a special (From|To)JSON instances for it
newtype RealisationWithId = RealisationWithId
{ unRealisationWithId :: (DerivationOutput OutputName, Realisation)
}
deriving (Eq, Generic, Ord, Show)
12 changes: 6 additions & 6 deletions hnix-store-json/src/System/Nix/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Aeson
import Deriving.Aeson
import System.Nix.Base (BaseEncoding(NixBase32))
import System.Nix.OutputName (OutputName)
import System.Nix.Realisation (DerivationOutput, Realisation)
import System.Nix.Realisation (DerivationOutput, Realisation, RealisationWithId(..))
import System.Nix.Signature (Signature)
import System.Nix.StorePath (StoreDir(..), StorePath, StorePathName, StorePathHashPart)

Expand Down Expand Up @@ -159,18 +159,18 @@ deriving
instance FromJSON Realisation

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

instance {-# OVERLAPPING #-} FromJSON (DerivationOutput OutputName, Realisation) where
instance FromJSON RealisationWithId where
parseJSON v@(Object o) = do
r <- parseJSON @Realisation v
drvOut <- o .: "id"
pure (drvOut, r)
pure (RealisationWithId (drvOut, r))
parseJSON x = fail $ "Expected Object but got " ++ show x
9 changes: 4 additions & 5 deletions hnix-store-remote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@ via `nix-daemon`.
```haskell
{-# LANGUAGE OverloadedStrings #-}

import Control.Monad (void)
import Control.Monad.IO.Class (liftIO)
import System.Nix.StorePath (mkStorePathName)
import System.Nix.Store.Remote

main :: IO ()
main = do
void $ runStore $ do
runStore $ do
syncWithGC
roots <- findRoots
liftIO $ print roots

res <- case mkStorePathName "hnix-store" of
Left e -> error (show e)
Expand All @@ -33,5 +30,7 @@ main = do
(StoreText name "Hello World!")
mempty
RepairMode_DontRepair
liftIO $ print res

pure (roots, res)
>>= print
```
16 changes: 0 additions & 16 deletions hnix-store-remote/app/BuildDerivation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,23 @@
module Main where

import Data.Default.Class (Default(def))
import Data.Text (Text)
import System.Nix.Derivation (Derivation)
import System.Nix.StorePath (StorePath)

import qualified Data.Text
import qualified Data.Text.IO
import qualified Data.Attoparsec.Text
import qualified System.Environment
import qualified System.Nix.Build
import qualified System.Nix.Derivation
import qualified System.Nix.StorePath
import qualified System.Nix.Store.Remote

parseDerivation :: FilePath -> IO (Derivation StorePath Text)
parseDerivation source = do
contents <- Data.Text.IO.readFile source
case Data.Attoparsec.Text.parseOnly
(System.Nix.Derivation.parseDerivation def) contents of
Left e -> error e
Right drv -> pure drv

main :: IO ()
main = System.Environment.getArgs >>= \case
[filename] -> do
case System.Nix.StorePath.parsePathFromText def (Data.Text.pack filename) of
Left e -> error $ show e
Right p -> do
d <- parseDerivation filename
out <-
System.Nix.Store.Remote.runStore
$ System.Nix.Store.Remote.buildDerivation
p
d
System.Nix.Build.BuildMode_Normal
print out
_ -> error "No input derivation file"
Expand Down
14 changes: 6 additions & 8 deletions hnix-store-remote/hnix-store-remote.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ common commons
, ViewPatterns
default-language: Haskell2010

common tests
import: commons
build-tool-depends:
tasty-discover:tasty-discover

flag io-testsuite
default:
False
Expand Down Expand Up @@ -119,7 +114,9 @@ library
, data-default-class
, dependent-sum > 0.7
, dependent-sum-template >= 0.2.0.1 && < 0.3
-- , directory
, dlist >= 1.0
, exceptions
, generic-arbitrary < 1.1
, hashable
, text
Expand All @@ -139,7 +136,6 @@ executable build-derivation
buildable: False
build-depends:
base >=4.12 && <5
, attoparsec
, hnix-store-core
, hnix-store-remote
, data-default-class
Expand All @@ -163,7 +159,7 @@ executable remote-readme
ghc-options: -pgmL markdown-unlit -Wall

test-suite remote
import: tests
import: commons
type: exitcode-stdio-1.0
main-is: Driver.hs
hs-source-dirs: tests
Expand All @@ -187,7 +183,7 @@ test-suite remote
, QuickCheck

test-suite remote-io
import: tests
import: commons

if !flag(io-testsuite) || os(darwin)
buildable: False
Expand All @@ -206,9 +202,11 @@ test-suite remote-io
, hnix-store-remote
, hnix-store-tests
, bytestring
, concurrency
, containers
, crypton
, directory
, exceptions
, filepath
, hspec
, hspec-expectations-lifted
Expand Down
Loading