diff --git a/nix_actor.nimble b/nix_actor.nimble index 24d40cd..6443b42 100644 --- a/nix_actor.nimble +++ b/nix_actor.nimble @@ -1,4 +1,4 @@ -version = "20230730" +version = "20230824" author = "Emery Hemingway" description = "Syndicated Nix Actor" license = "Unlicense" diff --git a/shell.nix b/shell.nix index 5d68567..00ec36d 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ let - flake = builtins.getFlake "syndicate"; + flake = builtins.getFlake "/home/emery/src/syndicate-flake"; pkgs = import { overlays = [ flake.overlays.default ]; }; -in pkgs.nix_actor +in pkgs.nim2Packages.nix_actor diff --git a/src/nix_actor.nim b/src/nix_actor.nim index faa3591..aada02b 100644 --- a/src/nix_actor.nim +++ b/src/nix_actor.nim @@ -143,36 +143,42 @@ type DaemonSideArgs {.preservesDictionary.} = object `daemon-socket`: string -main.initNix() -libexpr.initGC() +proc runNixActor(nixState: EvalState) = + let erisStore = newMemoryStore() + runActor("nix_actor") do (root: Cap; turn: var Turn): + connectStdio(root, turn) -runActor("main") do (root: Cap; turn: var Turn): - let - erisStore = newMemoryStore() - nixStore = openStore() - nixState = newEvalState(nixStore) - connectStdio(root, turn) + let pat = ?CapArgs + during(turn, root, pat) do (ds: Cap): - during(turn, root, ?CapArgs) do (ds: Cap): - discard publish(turn, ds, - initRecord("nixVersion", toPreserve($nixVersion.c_str))) + discard publish(turn, ds, + initRecord("nixVersion", toPreserve($nixVersion.c_str))) - discard bootNixFacet(turn, ds) + 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 - 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 + let pat = ?Observe(pattern: !Eval) ?? {0: grabLit(), 1: grabDict()} + during(turn, ds, pat) do (e: string, o: Assertion): + var ass = Eval(expr: e) + doAssert fromPreserve(ass.options, unpackLiterals(o)) + # unused options + 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) + during(turn, root, ?ClientSideArgs) do (socketPath: string): + bootClientSide(turn, ds, erisStore, socketPath) - during(turn, root, ?DaemonSideArgs) do (socketPath: string): - bootDaemonSide(turn, ds, erisStore, socketPath) + during(turn, root, ?DaemonSideArgs) do (socketPath: string): + bootDaemonSide(turn, ds, erisStore, socketPath) + +proc main = + initNix() + initGC() + let nixStore = openStore() + runNixActor(newEvalState(nixStore)) + +main() diff --git a/src/nix_actor/libnix/libexpr.nim b/src/nix_actor/libnix/libexpr.nim index 0608dd5..d98e200 100644 --- a/src/nix_actor/libnix/libexpr.nim +++ b/src/nix_actor/libnix/libexpr.nim @@ -83,11 +83,11 @@ type ExprObj {.importcpp: "nix::Expr", header: "nixexpr.hh".} = object discard Expr* = ptr ExprObj - EvalState* {.importcpp: "nix::ref", header: "eval.hh".} = object + EvalState* {.importcpp: "std::shared_ptr", header: "eval.hh".} = object discard proc newEvalState*(store: Store): EvalState {. - importcpp: "nix::newEvalState(@)", header: "seepuspus.hh".} + importcpp: "nix::newEvalState(@)", header: "seepuspus.hh", constructor.} proc parseExprFromString*(state: EvalState; s, basePath: cstring): Expr {. importcpp: "#->parseExprFromString(@)".} diff --git a/src/nix_actor/libnix/seepuspus.hh b/src/nix_actor/libnix/seepuspus.hh index 0fef838..f1ca694 100644 --- a/src/nix_actor/libnix/seepuspus.hh +++ b/src/nix_actor/libnix/seepuspus.hh @@ -3,7 +3,7 @@ namespace nix { - ref newEvalState(ref store) + std::shared_ptr newEvalState(ref store) { auto searchPath = Strings(); auto evalState = @@ -15,7 +15,7 @@ namespace nix { searchPath, store, store) #endif ; - return ref(evalState); + return evalState; } }