Ref renamed to Cap
This commit is contained in:
parent
d51d9b3c34
commit
c06f1fd241
|
@ -1,4 +1,4 @@
|
|||
version = "20230613"
|
||||
version = "20230726"
|
||||
author = "Emery Hemingway"
|
||||
description = "Syndicated Nix Actor"
|
||||
license = "Unlicense"
|
||||
|
|
|
@ -12,7 +12,7 @@ import ./nix_actor/protocol
|
|||
|
||||
type
|
||||
Value = Preserve[void]
|
||||
Observe = dataspace.Observe[Ref]
|
||||
Observe = dataspace.Observe[Cap]
|
||||
|
||||
proc toPreserve(val: libexpr.ValueObj | libExpr.ValuePtr; state: EvalState; E = void): Preserve[E] {.gcsafe.} =
|
||||
## Convert a Nix value to a Preserves value.
|
||||
|
@ -75,7 +75,7 @@ proc parseNarinfo(info: var AttrSet; text: string) =
|
|||
else:
|
||||
info[Symbol key] = val.toPreserve
|
||||
|
||||
proc narinfo(turn: var Turn; ds: Ref; path: string) =
|
||||
proc narinfo(turn: var Turn; ds: Cap; path: string) =
|
||||
let
|
||||
client = newAsyncHttpClient()
|
||||
url = "https://cache.nixos.org/" & path & ".narinfo"
|
||||
|
@ -109,7 +109,7 @@ proc instantiate(instantiate: Instantiate): Value =
|
|||
var execOutput = strip execProcess(cmd, args = args, options = {poUsePath})
|
||||
execOutput.toPreserve
|
||||
|
||||
proc bootNixFacet(turn: var Turn; ds: Ref): Facet =
|
||||
proc bootNixFacet(turn: var Turn; ds: Cap): Facet =
|
||||
# let store = openStore()
|
||||
result = inFacet(turn) do (turn: var Turn):
|
||||
|
||||
|
@ -135,8 +135,8 @@ proc bootNixFacet(turn: var Turn; ds: Ref): Facet =
|
|||
]#
|
||||
|
||||
type
|
||||
RefArgs {.preservesDictionary.} = object
|
||||
dataspace: Ref
|
||||
CapArgs {.preservesDictionary.} = object
|
||||
dataspace: Cap
|
||||
ClientSideArgs {.preservesDictionary.} = object
|
||||
`listen-socket`: string
|
||||
DaemonSideArgs {.preservesDictionary.} = object
|
||||
|
@ -145,22 +145,30 @@ type
|
|||
main.initNix()
|
||||
libexpr.initGC()
|
||||
|
||||
runActor("main") do (root: Ref; turn: var Turn):
|
||||
runActor("main") do (root: Cap; turn: var Turn):
|
||||
let
|
||||
erisStore = newMemoryStore()
|
||||
nixStore = openStore()
|
||||
nixState = newEvalState(nixStore)
|
||||
connectStdio(root, turn)
|
||||
|
||||
during(turn, root, ?RefArgs) do (ds: Ref):
|
||||
during(turn, root, ?CapArgs) do (ds: Cap):
|
||||
discard publish(turn, ds,
|
||||
initRecord("nixVersion", toPreserve($nixVersion.c_str)))
|
||||
|
||||
discard bootNixFacet(turn, ds)
|
||||
|
||||
during(turn, ds, ?Observe(pattern: !Eval) ?? {0: grabLit(), 1: grabDict()}) do (e: string, o: Assertion):
|
||||
var ass = Eval(expr: e)
|
||||
doAssert fromPreserve(ass.options, unpackLiterals(o))
|
||||
# unused options
|
||||
ass.result = eval(nixState, ass.expr)
|
||||
discard publish(turn, ds, ass)
|
||||
try:
|
||||
ass.result = eval(nixState, ass.expr)
|
||||
discard publish(turn, ds, ass)
|
||||
except CatchableError as err:
|
||||
stderr.writeLine "failed to evaluate ", ass.expr, ": ", err.msg
|
||||
except StdException as err:
|
||||
stderr.writeLine "failed to evaluate ", ass.expr, ": ", err.what
|
||||
|
||||
during(turn, root, ?ClientSideArgs) do (socketPath: string):
|
||||
bootClientSide(turn, ds, erisStore, socketPath)
|
||||
|
|
|
@ -43,7 +43,7 @@ proc completeAddToStore(client: Session; path: string; info: LegacyPathAttrs) {.
|
|||
await send(client, path)
|
||||
await send(client, info)
|
||||
|
||||
proc serveClient(facet: Facet; ds: Ref; store: ErisStore; client: Session) {.async.} =
|
||||
proc serveClient(facet: Facet; ds: Cap; store: ErisStore; client: Session) {.async.} =
|
||||
block:
|
||||
let clientMagic = await recvWord(client)
|
||||
if clientMagic != WORKER_MAGIC_1:
|
||||
|
@ -77,10 +77,10 @@ proc serveClient(facet: Facet; ds: Ref; store: ErisStore; client: Session) {.asy
|
|||
let cap = await ingestChunks(client, store)
|
||||
await sendNext(client, $cap & " " & name)
|
||||
let attrsPat = inject(?AddToStoreAttrs, {
|
||||
"name".toSymbol(Ref): ?name,
|
||||
"ca-method".toSymbol(Ref): ?caMethod.toSymbol,
|
||||
"references".toSymbol(Ref): ?storeRefs,
|
||||
"eris".toSymbol(Ref): ?cap.bytes,
|
||||
"name".toSymbol(Cap): ?name,
|
||||
"ca-method".toSymbol(Cap): ?caMethod.toSymbol,
|
||||
"references".toSymbol(Cap): ?storeRefs,
|
||||
"eris".toSymbol(Cap): ?cap.bytes,
|
||||
})
|
||||
# bind AddToStoreAttrs and override with some literal values
|
||||
let pat = PathInfo ? { 0: grab(), 1: attrsPat }
|
||||
|
@ -154,7 +154,7 @@ proc serveClient(facet: Facet; ds: Ref; store: ErisStore; client: Session) {.asy
|
|||
await sendWorkEnd(client)
|
||||
close(client.socket)
|
||||
|
||||
proc serveClientSide(facet: Facet; ds: Ref; store: ErisStore; listener: AsyncSocket) {.async.} =
|
||||
proc serveClientSide(facet: Facet; ds: Cap; store: ErisStore; listener: AsyncSocket) {.async.} =
|
||||
while not listener.isClosed:
|
||||
let
|
||||
client = await accept(listener)
|
||||
|
@ -163,7 +163,7 @@ proc serveClientSide(facet: Facet; ds: Ref; store: ErisStore; listener: AsyncSoc
|
|||
if not client.isClosed:
|
||||
close(client)
|
||||
|
||||
proc bootClientSide*(turn: var Turn; ds: Ref; store: ErisStore; socketPath: string) =
|
||||
proc bootClientSide*(turn: var Turn; ds: Cap; store: ErisStore; socketPath: string) =
|
||||
let listener = newUnixSocket()
|
||||
onStop(turn.facet) do (turn: var Turn):
|
||||
close(listener)
|
||||
|
|
|
@ -11,7 +11,7 @@ import ./protocol, ./sockets
|
|||
|
||||
type
|
||||
Value = Preserve[void]
|
||||
Observe = dataspace.Observe[Ref]
|
||||
Observe = dataspace.Observe[Cap]
|
||||
|
||||
proc recvError(daemon: Session): Future[string] {.async.} =
|
||||
discard #[typ]# await recvString(daemon)
|
||||
|
@ -153,9 +153,9 @@ proc callDaemon(turn: var Turn; path: string; action: proc (daemon: Session; tur
|
|||
action(daemon, turn)
|
||||
return daemon
|
||||
|
||||
proc bootDaemonSide*(turn: var Turn; ds: Ref; store: ErisStore; socketPath: string) =
|
||||
proc bootDaemonSide*(turn: var Turn; ds: Cap; store: ErisStore; socketPath: string) =
|
||||
|
||||
during(turn, ds, ?Observe(pattern: !Missing) ?? {0: grab()}) do (a: Preserve[Ref]):
|
||||
during(turn, ds, ?Observe(pattern: !Missing) ?? {0: grab()}) do (a: Preserve[Cap]):
|
||||
# cannot use `grabLit` here because an array is a compound
|
||||
# TODO: unpack to a `Pattern`
|
||||
let daemon = callDaemon(turn, socketPath) do (daemon: Session; turn: var Turn):
|
||||
|
|
Loading…
Reference in New Issue