Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Emery Hemingway | 0f18aa5ff7 |
|
@ -0,0 +1,22 @@
|
|||
# Socket protocol
|
||||
|
||||
The socket protocol is a stream of words where each word is 8 bytes.
|
||||
|
||||
## Handshake
|
||||
- client sends WORKER_MAGIC_1 - 0x000000006e697863
|
||||
- server sends WORKER_MAGIC_2 - 0x000000006478696f
|
||||
- client sends version number 0x0000:MAJOR:MINOR where MAJOR and MINOR are each one byte
|
||||
- server sends version number 0x0000:MAJOR:MINOR
|
||||
- if client minor version is greater than 14
|
||||
- send obsolete CPU affinity value
|
||||
- if client minor version is greater than 11
|
||||
- send obsolete reserveSpace value
|
||||
- if minor version is greater than 33
|
||||
- send version string (MAJOR.MINOR.PATCH)
|
||||
- server sends any pending error messages followed by STDERR_LAST - 0x616c7473
|
||||
|
||||
|
||||
https://alternativebit.fr/posts/nixos/future-of-nix-substitution/
|
||||
https://lists.gnu.org/archive/html/guix-devel/2020-12/msg00258.html
|
||||
https://discourse.nixos.org/t/nix-casync-a-more-efficient-way-to-store-and-substitute-nix-store-paths/16539/4?u=flokli
|
||||
https://github.com/NixOS/nix/issues/8306
|
3
Tupfile
3
Tupfile
|
@ -1,2 +1,3 @@
|
|||
include_rules
|
||||
: lock.json |> !nim_cfg |> | ./<lock>
|
||||
: |> !nim_lk |> {lockfile}
|
||||
: {lockfile} |> !nim_cfg |> | ./<lock>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
NIM = $(DIRENV) $(NIM)
|
||||
|
||||
include ../eris-nim/depends.tup
|
||||
NIM_FLAGS += --path:$(TUP_CWD)/../eris-nim/src
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
let
|
||||
nix' = import ./nix-c-bindings.nix { inherit pkgs; };
|
||||
addNix = final: prev: { buildInputs = prev.buildInputs ++ [ nix' ]; };
|
||||
in (pkgs.buildNimPackage {
|
||||
name = "nix_actor";
|
||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||
buildInputs = [ nix' ];
|
||||
lockFile = ./lock.json;
|
||||
}).overrideAttrs addNix
|
123
lock.json
123
lock.json
|
@ -6,19 +6,28 @@
|
|||
"base32"
|
||||
],
|
||||
"path": "/nix/store/qcnchjsak3hyn4c6r0zd6qvm7j8y1747-source",
|
||||
"ref": "0.1.3",
|
||||
"rev": "f541038fbe49fdb118cc2002d29824b9fc4bfd61",
|
||||
"sha256": "16gh1ifp9hslsg0is0v1ya7rxqfhq5hjqzc3pfdqvcgibp5ybh06",
|
||||
"srcDir": "",
|
||||
"url": "https://github.com/OpenSystemsLab/base32.nim/archive/f541038fbe49fdb118cc2002d29824b9fc4bfd61.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"bigints"
|
||||
],
|
||||
"path": "/nix/store/jvrm392g8adfsgf36prgwkbyd7vh5jsw-source",
|
||||
"rev": "86ea14d31eea9275e1408ca34e6bfe9c99989a96",
|
||||
"sha256": "15pcpmnk1bnw3k8769rjzcpg00nahyrypwbxs88jnwr4aczp99j4",
|
||||
"srcDir": "src",
|
||||
"url": "https://github.com/ehmry/nim-bigints/archive/86ea14d31eea9275e1408ca34e6bfe9c99989a96.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"cbor"
|
||||
],
|
||||
"path": "/nix/store/70cqa9s36dqnmsf179cn9psj77jhqi1l-source",
|
||||
"ref": "20230619",
|
||||
"rev": "a4a1affd45ba90bea24e08733ae2bd02fe058166",
|
||||
"sha256": "005ib6im97x9pdbg6p0fy58zpdwdbkpmilxa8nhrrb1hnpjzz90p",
|
||||
"srcDir": "src",
|
||||
|
@ -30,7 +39,6 @@
|
|||
"coap"
|
||||
],
|
||||
"path": "/nix/store/pqj933cnw7r7hp46jrpjlwh1yr0jvckp-source",
|
||||
"ref": "20230331",
|
||||
"rev": "a134213b51a8d250684f2ba26802ffa97fae4ffb",
|
||||
"sha256": "1wbix6d8l26nj7m3xinh4m2f27n4ma0yzs3x5lpann2ha0y51k8b",
|
||||
"srcDir": "src",
|
||||
|
@ -39,14 +47,13 @@
|
|||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"configparser"
|
||||
"cps"
|
||||
],
|
||||
"path": "/nix/store/4zl5v7i6cj3f9sayvsjcx2h20lqwr9a6-source",
|
||||
"ref": "newSection",
|
||||
"rev": "695f1285d63f1954c25eb1f42798d90fa7bcbe14",
|
||||
"sha256": "0b0pb5i0kir130ia2zf8zcgdz8awms161i6p83ri3nbgibbjnr37",
|
||||
"srcDir": "src",
|
||||
"url": "https://github.com/ehmry/nim-configparser/archive/695f1285d63f1954c25eb1f42798d90fa7bcbe14.tar.gz"
|
||||
"path": "/nix/store/452hfhasrn3gl6vijfmzs69djl099j0j-source",
|
||||
"rev": "b7c179f172e3a256a482a9daee3c0815ea423206",
|
||||
"sha256": "1sn9s7iv83sw1jl5jgi2h7b0xpgsn13f9icp5124jvbp0qkxskx2",
|
||||
"srcDir": "",
|
||||
"url": "https://github.com/nim-works/cps/archive/b7c179f172e3a256a482a9daee3c0815ea423206.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
|
@ -54,11 +61,10 @@
|
|||
"eris"
|
||||
],
|
||||
"path": "/nix/store/lxa6ba8r9hhs06k6f2iyznwjxix1klv1-source",
|
||||
"ref": "20230823",
|
||||
"rev": "49d8117367d3530533dc1d6a9111ddd134b08b1e",
|
||||
"sha256": "0lq9a04cayf04nnhn0gvp5phlij0cis38v7cz7jmgks2xvz1bcbr",
|
||||
"srcDir": "src",
|
||||
"url": "https://codeberg.org/eris/nim-eris/archive/49d8117367d3530533dc1d6a9111ddd134b08b1e.tar.gz"
|
||||
"url": "https://codeberg.org/eris/eris-nim/archive/49d8117367d3530533dc1d6a9111ddd134b08b1e.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
|
@ -66,7 +72,6 @@
|
|||
"freedesktop_org"
|
||||
],
|
||||
"path": "/nix/store/98wncmx58cfnhv3y96lzwm22zvyk9b1h-source",
|
||||
"ref": "20230210",
|
||||
"rev": "fb04d0862aca4be2edcc0eafa94b1840030231c8",
|
||||
"sha256": "0wj5m09x1pr36gv8p5r72p6l3wwl01y8scpnlzx7q0h5ij6jaj6s",
|
||||
"srcDir": "src",
|
||||
|
@ -78,7 +83,6 @@
|
|||
"getdns"
|
||||
],
|
||||
"path": "/nix/store/x9xmn7w4k6jg8nv5bnx148ibhnsfh362-source",
|
||||
"ref": "20221222",
|
||||
"rev": "c73cbe288d9f9480586b8fa87f6d794ffb6a6ce6",
|
||||
"sha256": "1sbgx2x51szr22i72n7c8jglnfmr8m7y7ga0v85d58fwadiv7g6b",
|
||||
"srcDir": "src",
|
||||
|
@ -100,12 +104,11 @@
|
|||
"packages": [
|
||||
"nimcrypto"
|
||||
],
|
||||
"path": "/nix/store/zyr8zwh7vaiycn1s4r8cxwc71f2k5l0h-source",
|
||||
"ref": "traditional-api",
|
||||
"rev": "602c5d20c69c76137201b5d41f788f72afb95aa8",
|
||||
"sha256": "1dmdmgb6b9m5f8dyxk781nnd61dsk3hdxqks7idk9ncnpj9fng65",
|
||||
"path": "/nix/store/jwz8pqbv6rsm8w4fjzdb37r0wzjn5hv0-source",
|
||||
"rev": "d58da671799c69c0b3208b96c154e13c8b1a9e90",
|
||||
"sha256": "12dm0gsy10ppga7zf7hpf4adaqjrd9b740n2w926xyazq1njf6k9",
|
||||
"srcDir": "",
|
||||
"url": "https://github.com/cheatfate/nimcrypto/archive/602c5d20c69c76137201b5d41f788f72afb95aa8.tar.gz"
|
||||
"url": "https://github.com/cheatfate/nimcrypto/archive/d58da671799c69c0b3208b96c154e13c8b1a9e90.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
|
@ -113,7 +116,6 @@
|
|||
"npeg"
|
||||
],
|
||||
"path": "/nix/store/ffkxmjmigfs7zhhiiqm0iw2c34smyciy-source",
|
||||
"ref": "1.2.1",
|
||||
"rev": "26d62fdc40feb84c6533956dc11d5ee9ea9b6c09",
|
||||
"sha256": "0xpzifjkfp49w76qmaylan8q181bs45anmp46l4bwr3lkrr7bpwh",
|
||||
"srcDir": "src",
|
||||
|
@ -124,24 +126,55 @@
|
|||
"packages": [
|
||||
"preserves"
|
||||
],
|
||||
"path": "/nix/store/fmb2yckksz7iv3qdkk5gk1j060kppkq9-source",
|
||||
"ref": "20231102",
|
||||
"rev": "4faeb766dc3945bcfacaa1a836ef6ab29b20ceb0",
|
||||
"sha256": "1a3g5bk1l1h250q3p6sqv6r1lpsplp330qqyp48r0i4a5r0jksq3",
|
||||
"path": "/nix/store/2hy124xgabz134dxj3wji7mp47fdwy3w-source",
|
||||
"rev": "9ae435a83c6d5028405538af5d24a023af625b6e",
|
||||
"sha256": "1k7ywcp1a53x2fpc6wc2b0qzb264dkifash0s1wcp66rw3lx15k2",
|
||||
"srcDir": "src",
|
||||
"url": "https://git.syndicate-lang.org/ehmry/preserves-nim/archive/4faeb766dc3945bcfacaa1a836ef6ab29b20ceb0.tar.gz"
|
||||
"url": "https://git.syndicate-lang.org/ehmry/preserves-nim/archive/9ae435a83c6d5028405538af5d24a023af625b6e.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"stew"
|
||||
],
|
||||
"path": "/nix/store/mqg8qzsbcc8xqabq2yzvlhvcyqypk72c-source",
|
||||
"rev": "3c91b8694e15137a81ec7db37c6c58194ec94a6a",
|
||||
"sha256": "17lfhfxp5nxvld78xa83p258y80ks5jb4n53152cdr57xk86y07w",
|
||||
"srcDir": "",
|
||||
"url": "https://github.com/status-im/nim-stew/archive/3c91b8694e15137a81ec7db37c6c58194ec94a6a.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"syndicate"
|
||||
],
|
||||
"path": "/nix/store/nhpvl223vbzdrlzikw7pgyfxs344w7ma-source",
|
||||
"ref": "20231108",
|
||||
"rev": "095418032180e360ea27ec7fcd63193944b68e2c",
|
||||
"sha256": "09pbml2chzz0v5zpz67fs7raj0mfmg8qrih2vz85xxc51h7ncqvw",
|
||||
"path": "/nix/store/yv8nzv7g3nxkz61ylzshs70h754vjq3d-source",
|
||||
"rev": "b209548f5d15f7391c08fcaec3615ed843f8a410",
|
||||
"sha256": "0pkypbi42cr01lms5adkl55lyqpniqi4sb1mqnlalr79a70b0vf6",
|
||||
"srcDir": "src",
|
||||
"url": "https://git.syndicate-lang.org/ehmry/syndicate-nim/archive/095418032180e360ea27ec7fcd63193944b68e2c.tar.gz"
|
||||
"url": "https://git.syndicate-lang.org/ehmry/syndicate-nim/archive/b209548f5d15f7391c08fcaec3615ed843f8a410.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"sys"
|
||||
],
|
||||
"path": "/nix/store/syhxsjlsdqfap0hk4qp3s6kayk8cqknd-source",
|
||||
"rev": "4ef3b624db86e331ba334e705c1aa235d55b05e1",
|
||||
"sha256": "1q4qgw4an4mmmcbx48l6xk1jig1vc8p9cq9dbx39kpnb0890j32q",
|
||||
"srcDir": "src",
|
||||
"url": "https://github.com/ehmry/nim-sys/archive/4ef3b624db86e331ba334e705c1aa235d55b05e1.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"taps"
|
||||
],
|
||||
"path": "/nix/store/did1li0xk9qih80pvxqhjc4np3ijlfjj-source",
|
||||
"rev": "4f9c9972d74eb39c662b43ed79d761e109bf00f1",
|
||||
"sha256": "12qsizmisr1q0q4x37c5q6gmnqb5mp0bid7s3jlcsjvhc4jw2q57",
|
||||
"srcDir": "src",
|
||||
"url": "https://git.sr.ht/~ehmry/nim_taps/archive/4f9c9972d74eb39c662b43ed79d761e109bf00f1.tar.gz"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
|
@ -149,7 +182,6 @@
|
|||
"taps"
|
||||
],
|
||||
"path": "/nix/store/did1li0xk9qih80pvxqhjc4np3ijlfjj-source",
|
||||
"ref": "20230331",
|
||||
"rev": "4f9c9972d74eb39c662b43ed79d761e109bf00f1",
|
||||
"sha256": "12qsizmisr1q0q4x37c5q6gmnqb5mp0bid7s3jlcsjvhc4jw2q57",
|
||||
"srcDir": "src",
|
||||
|
@ -161,11 +193,38 @@
|
|||
"tkrzw"
|
||||
],
|
||||
"path": "/nix/store/4x9wxyli4dy719svg1zaww0c0b3xckp0-source",
|
||||
"ref": "20220922",
|
||||
"rev": "efd87edb7b063182c1a1fa018006a87b515d589b",
|
||||
"sha256": "1h0sdvai4gkkz48xfh67wa1xz2k8bkkba8q6snnbllmhmywd9apb",
|
||||
"srcDir": "src",
|
||||
"url": "https://git.sr.ht/~ehmry/nim-tkrzw/archive/efd87edb7b063182c1a1fa018006a87b515d589b.tar.gz"
|
||||
},
|
||||
{
|
||||
"date": "2023-01-20T14:19:07-06:00",
|
||||
"deepClone": false,
|
||||
"fetchLFS": false,
|
||||
"fetchSubmodules": true,
|
||||
"hash": "sha256-Z2Qr14pv2RHzQNfEYIKuXKHfHvvIfaEiGCHHCWJZFyw=",
|
||||
"leaveDotGit": false,
|
||||
"method": "git",
|
||||
"packages": [
|
||||
"configparser"
|
||||
],
|
||||
"path": "/nix/store/3563cy6iv7mf39dj8zk7zw31m1xs9wxv-nim-configparser",
|
||||
"rev": "695f1285d63f1954c25eb1f42798d90fa7bcbe14",
|
||||
"sha256": "0b0pb5i0kir130ia2zf8zcgdz8awms161i6p83ri3nbgibbjnr37",
|
||||
"srcDir": "src",
|
||||
"url": "https://github.com/ehmry/nim-configparser.git"
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"packages": [
|
||||
"getdns"
|
||||
],
|
||||
"path": "/nix/store/x9xmn7w4k6jg8nv5bnx148ibhnsfh362-source",
|
||||
"rev": "c73cbe288d9f9480586b8fa87f6d794ffb6a6ce6",
|
||||
"sha256": "1sbgx2x51szr22i72n7c8jglnfmr8m7y7ga0v85d58fwadiv7g6b",
|
||||
"srcDir": "src",
|
||||
"url": "https://git.sr.ht/~ehmry/getdns-nim/archive/c73cbe288d9f9480586b8fa87f6d794ffb6a6ce6.tar.gz"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
pkgs.nix.overrideAttrs (final: prev: {
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "tweag";
|
||||
repo = "nix";
|
||||
rev = "0fd441d0bf6331a1152cdc091724b4648d187f90";
|
||||
hash = "sha256-ndFevohurD6MQCCBnOdHLDmsJ3vfpF5+cKizXvq5vmw=";
|
||||
};
|
||||
buildInputs = prev.buildInputs ++ [ pkgs.libgit2 ];
|
||||
patches = [ ];
|
||||
})
|
|
@ -5,4 +5,4 @@ license = "Unlicense"
|
|||
srcDir = "src"
|
||||
bin = @["nix_actor"]
|
||||
|
||||
requires "nim >= 1.6.10", "syndicate >= 20231005", "eris >= 20230823"
|
||||
requires "syndicate#b209548f5d15f7391c08fcaec3615ed843f8a410", "https://codeberg.org/eris/eris-nim.git >= 20230823"
|
||||
|
|
26
protocol.prs
26
protocol.prs
|
@ -14,21 +14,21 @@ Eval = <eval @expr string @path string @result any> .
|
|||
|
||||
Narinfo = <narinfo @path string @info AttrSet> .
|
||||
|
||||
Field = int / string .
|
||||
Field = @int int / @string string .
|
||||
Fields = [Field ...] .
|
||||
|
||||
ActionStart = <start @id int @level int @type int @text string @fields Fields @parent int> .
|
||||
ActionStop = <stop @id int> .
|
||||
ActionResult = <result @id int @type int @fields Fields> .
|
||||
|
||||
; TODO: why not make target a singleton?
|
||||
# TODO: why not make target a singleton?
|
||||
Missing = <missing @targets StringSeq @willBuild StringSet @willSubstitute StringSet @unknown StringSet @downloadSize int @narSize int> .
|
||||
|
||||
; Path info for the worker protocol version 35.
|
||||
# Path info for the worker protocol version 35.
|
||||
LegacyPathAttrs = {
|
||||
deriver: string
|
||||
narHash: string
|
||||
references: StringSeq ; prefer a set
|
||||
references: StringSeq
|
||||
registrationTime: int
|
||||
narSize: int
|
||||
ultimate: bool
|
||||
|
@ -37,19 +37,19 @@ LegacyPathAttrs = {
|
|||
} .
|
||||
|
||||
AddToStoreClientAttrs = {
|
||||
name: string
|
||||
eris: bytes
|
||||
ca-method: symbol
|
||||
references: StringSeq ; prefer a set
|
||||
} .
|
||||
name: string,
|
||||
eris: bytes,
|
||||
ca-method: symbol,
|
||||
references: StringSeq,
|
||||
}.
|
||||
|
||||
; Intersection of the attributes needed to add a path to a store
|
||||
; and the attributes returned by the daemon after adding the path.
|
||||
# Intersection of the attributes needed to add a path to a store
|
||||
# and the attributes returned by the daemon after adding the path.
|
||||
AddToStoreAttrs = {
|
||||
name: string
|
||||
eris: bytes
|
||||
ca-method: symbol
|
||||
references: StringSeq ; prefer a set
|
||||
references: StringSeq # prefer a set
|
||||
|
||||
deriver: string
|
||||
narHash: string
|
||||
|
@ -60,5 +60,5 @@ AddToStoreAttrs = {
|
|||
ca: string
|
||||
} .
|
||||
|
||||
; Any collection of attributes describing a store path.
|
||||
# Any collection of attributes describing a store path.
|
||||
PathInfo = <path @path string @attrs AttrSet> .
|
||||
|
|
17
shell.nix
17
shell.nix
|
@ -1,17 +0,0 @@
|
|||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
let
|
||||
nix' = pkgs.nix.overrideAttrs (final: prev: {
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "tweag";
|
||||
repo = "nix";
|
||||
rev = "nix-c-bindings";
|
||||
hash = "sha256-xOyU79lsz0THOj1LccfsDS45089n2DhlkWxaJFeKriY=";
|
||||
};
|
||||
});
|
||||
in pkgs.buildNimPackage {
|
||||
name = "dummy";
|
||||
nativeBuildInputs = [ pkgs.pkg-config ];
|
||||
buildInputs = [ pkgs.boost nix' ];
|
||||
lockFile = ./lock.json;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
backend:cpp
|
|
@ -1,46 +1,48 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[os, strutils, tables]
|
||||
import std/tables
|
||||
import preserves, syndicate, syndicate/relays
|
||||
# from syndicate/protocols/dataspace import Observe
|
||||
import ./nix_actor/[nix_api, nix_api_value]
|
||||
import ./nix_actor/protocol
|
||||
|
||||
proc toPreserve(state: State; value: Value; E = void): Preserve[E] {.gcsafe.} =
|
||||
type
|
||||
Value = preserves.Value
|
||||
NixValue = nix_api.Value
|
||||
|
||||
proc toPreserves(state: State; value: NixValue): Value {.gcsafe.} =
|
||||
var ctx: NixContext
|
||||
stderr.writeLine get_type(ctx, value).int
|
||||
case get_type(ctx, value)
|
||||
of NIX_TYPE_THUNK: raiseAssert "cannot preserve thunk"
|
||||
of NIX_TYPE_INT:
|
||||
result = getInt(ctx, value).toPreserve(E)
|
||||
result = getInt(ctx, value).toPreserves
|
||||
of NIX_TYPE_FLOAT:
|
||||
result = getFloat(ctx, value).toPreserve(E)
|
||||
result = getFloat(ctx, value).toPreserves
|
||||
of NIX_TYPE_BOOL:
|
||||
result = getBool(ctx, value).toPreserve(E)
|
||||
result = getBool(ctx, value).toPreserves
|
||||
of NIX_TYPE_STRING:
|
||||
result = ($getString(ctx, value)).toPreserve(E)
|
||||
result = ($getString(ctx, value)).toPreserves
|
||||
of NIX_TYPE_PATH:
|
||||
result = ($getPathString(ctx, value)).toPreserve(E)
|
||||
result = ($getPathString(ctx, value)).toPreserves
|
||||
of NIX_TYPE_NULL:
|
||||
result = initRecord[E]("null")
|
||||
result = initRecord("null")
|
||||
of NIX_TYPE_ATTRS:
|
||||
result = initDictionary(E)
|
||||
result = initDictionary()
|
||||
let n = getAttrsSize(ctx, value)
|
||||
var i: cuint
|
||||
while i < n:
|
||||
var (key, val) = get_attr_byidx(ctx, value, state, i)
|
||||
inc(i)
|
||||
result[toSymbol($key, E)] = toPreserve(state, val, E)
|
||||
stderr.writeLine(result)
|
||||
result[toSymbol($key)] = toPreserves(state, val)
|
||||
# close(val)
|
||||
of NIX_TYPE_LIST:
|
||||
let n = getListSize(ctx, value)
|
||||
result = initSequence(n, E)
|
||||
result = initSequence(n)
|
||||
var i: cuint
|
||||
while i < n:
|
||||
var val = getListByIdx(ctx, value, state, i)
|
||||
result[i] = toPreserve(state, val, E)
|
||||
result[i] = toPreserves(state, val)
|
||||
inc(i)
|
||||
# close(val)
|
||||
of NIX_TYPE_FUNCTION, NIX_TYPE_EXTERNAL:
|
||||
|
@ -53,29 +55,29 @@ type
|
|||
proc main() =
|
||||
initLibexpr()
|
||||
|
||||
runActor("nix_actor") do (root: Cap; turn: var Turn):
|
||||
connectStdio(turn, root)
|
||||
runActor("nix_actor") do (turn: var Turn):
|
||||
resolveEnvironment(turn) do (turn: var Turn; root: Cap):
|
||||
|
||||
during(turn, root, ?BootArgs) do (ds: Cap):
|
||||
let
|
||||
store = openStore()
|
||||
state = newState(store)
|
||||
during(turn, root, ?:BootArgs) do (ds: Cap):
|
||||
let
|
||||
store = openStore()
|
||||
state = newState(store)
|
||||
|
||||
let pat = ?Observe(pattern: !Eval) ?? {0: grabLit(), 1: grabLit()}
|
||||
during(turn, ds, pat) do (expr: string, path: string):
|
||||
var
|
||||
value: Value
|
||||
ass = Eval(expr: expr, path: path)
|
||||
try:
|
||||
value = evalFromString(state, ass.expr, ass.path)
|
||||
force(state, value)
|
||||
ass.result = toPreserve(state, value, void)
|
||||
discard publish(turn, ds, ass)
|
||||
except CatchableError as err:
|
||||
stderr.writeLine "failed to evaluate ", ass.expr, ": ", err.msg
|
||||
close(value)
|
||||
do:
|
||||
close(state)
|
||||
close(store)
|
||||
let pat = ?Observe(pattern: !Eval) ?? {0: grabLit(), 1: grabLit()}
|
||||
during(turn, ds, pat) do (expr: string, path: string):
|
||||
var
|
||||
value: NixValue
|
||||
ass = Eval(expr: expr, path: path)
|
||||
try:
|
||||
value = evalFromString(state, ass.expr, ass.path)
|
||||
force(state, value)
|
||||
ass.result = toPreserves(state, value)
|
||||
discard publish(turn, ds, ass)
|
||||
except CatchableError as err:
|
||||
stderr.writeLine "failed to evaluate ", ass.expr, ": ", err.msg
|
||||
close(value)
|
||||
do:
|
||||
close(state)
|
||||
close(store)
|
||||
|
||||
main()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import ./nix_api_types, ./nix_api_util, ./nix_api_value, ./nix_api_store, ./nix_api_expr
|
||||
import ./nix_api_types, ./nix_api_value, ./nix_api_store, ./nix_api_expr
|
||||
|
||||
export NixContext, Store, State, Value, ValueType,
|
||||
gc_decref, isNil
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
type
|
||||
nix_err* = cint
|
||||
NixException* = object of CatchableError
|
||||
NixContext* {.header: "nix_api_util.h", importc: "nix_c_context".} = distinct pointer
|
||||
State* {.header: "nix_api_expr.h", importc.} = distinct pointer
|
||||
Store* {.header: "nix_api_store.h", importc.} = distinct pointer
|
||||
StorePath* {.header: "nix_api_store.h", importc.} = distinct pointer
|
||||
Value* {.header: "nix_api_value.h", importc.} = distinct pointer
|
||||
ValueType* {.header: "nix_api_value.h", importc.} = enum
|
||||
NIX_TYPE_THUNK,
|
||||
NIX_TYPE_INT,
|
||||
NIX_TYPE_FLOAT,
|
||||
NIX_TYPE_BOOL,
|
||||
NIX_TYPE_STRING,
|
||||
NIX_TYPE_PATH,
|
||||
NIX_TYPE_NULL,
|
||||
NIX_TYPE_ATTRS,
|
||||
NIX_TYPE_LIST,
|
||||
NIX_TYPE_FUNCTION,
|
||||
NIX_TYPE_EXTERNAL
|
||||
|
||||
proc isNil*(p: NixContext): bool {.borrow.}
|
||||
proc isNil*(p: State): bool {.borrow.}
|
||||
proc isNil*(p: Store): bool {.borrow.}
|
||||
proc isNil*(p: Value): bool {.borrow.}
|
|
@ -6,9 +6,9 @@ type
|
|||
Eval* {.preservesRecord: "eval".} = object
|
||||
`expr`*: string
|
||||
`path`*: string
|
||||
`result`*: Preserve[void]
|
||||
`result`*: Value
|
||||
|
||||
AttrSet* = Table[Symbol, Preserve[void]]
|
||||
AttrSet* = Table[Symbol, Value]
|
||||
Realise* {.preservesRecord: "realise".} = object
|
||||
`drv`*: string
|
||||
`outputs`*: StringSeq
|
||||
|
@ -40,7 +40,7 @@ type
|
|||
`Field`* {.preservesOr.} = object
|
||||
case orKind*: FieldKind
|
||||
of FieldKind.`int`:
|
||||
`int`*: int
|
||||
`int`*: BiggestInt
|
||||
|
||||
of FieldKind.`string`:
|
||||
`string`*: string
|
||||
|
@ -48,9 +48,11 @@ type
|
|||
|
||||
StringSet* = HashSet[string]
|
||||
AddToStoreAttrs* {.preservesDictionary.} = object
|
||||
`# prefer a set
|
||||
|
||||
deriver`*: string
|
||||
`ca`*: string
|
||||
`ca-method`*: Symbol
|
||||
`deriver`*: string
|
||||
`eris`*: seq[byte]
|
||||
`name`*: string
|
||||
`narHash`*: string
|
||||
|
@ -72,7 +74,7 @@ type
|
|||
|
||||
Build* {.preservesRecord: "nix-build".} = object
|
||||
`input`*: string
|
||||
`output`*: Preserve[void]
|
||||
`output`*: Value
|
||||
|
||||
Fields* = seq[Field]
|
||||
ActionStart* {.preservesRecord: "start".} = object
|
||||
|
@ -86,7 +88,7 @@ type
|
|||
Instantiate* {.preservesRecord: "instantiate".} = object
|
||||
`expr`*: string
|
||||
`options`*: AttrSet
|
||||
`result`*: Preserve[void]
|
||||
`result`*: Value
|
||||
|
||||
StringSeq* = seq[string]
|
||||
ActionStop* {.preservesRecord: "stop".} = object
|
||||
|
@ -110,7 +112,7 @@ proc `$`*(x: Eval | AttrSet | Realise | LegacyPathAttrs | Missing | Narinfo |
|
|||
StringSeq |
|
||||
ActionStop |
|
||||
ActionResult): string =
|
||||
`$`(toPreserve(x))
|
||||
`$`(toPreserves(x))
|
||||
|
||||
proc encode*(x: Eval | AttrSet | Realise | LegacyPathAttrs | Missing | Narinfo |
|
||||
Field |
|
||||
|
@ -125,4 +127,4 @@ proc encode*(x: Eval | AttrSet | Realise | LegacyPathAttrs | Missing | Narinfo |
|
|||
StringSeq |
|
||||
ActionStop |
|
||||
ActionResult): seq[byte] =
|
||||
encode(toPreserve(x))
|
||||
encode(toPreserves(x))
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
let pkgs = import ../../../cache/src/nixpkgs { }; in
|
||||
pkgs.writeTextFile {
|
||||
name = "test-file";
|
||||
text = ''
|
||||
File generated at ${builtins.toString builtins.currentTime}.
|
||||
'';
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
import std/unittest
|
||||
|
||||
import preserves
|
||||
|
||||
type AddToStoreClientAttrs {.preservesDictionary.} = object
|
||||
## A subset of AddToStoreAttrs
|
||||
`ca-method`: Symbol
|
||||
eris: seq[byte]
|
||||
name: string
|
||||
|
||||
test "fromPreserve":
|
||||
const raw = "{ca: <bind <_>> ca-method: |fixed:r:sha256| deriver: <bind <_>> eris: #[CgA1VVrR0k5gjgU1wKQKVZr1RkANf4zUva3vyc2wmLzhzuL8XqeUL0HE4W3aRpXNwXyFbaLxtXJiLCUWSyLjej+h] name: \"default-builder.sh\" narHash: <bind <_>> narSize: <bind <_>> references: [] registrationTime: <bind <_>> sigs: <bind <_>> ultimate: <bind <_>>}"
|
||||
|
||||
let pr = parsePreserves(raw)
|
||||
var attrs: AddToStoreClientAttrs
|
||||
check fromPreserve(attrs, pr)
|
|
@ -0,0 +1 @@
|
|||
define:tracePreserves
|
Loading…
Reference in New Issue