diff --git a/flake.nix b/flake.nix index 401d2346..8b615d46 100644 --- a/flake.nix +++ b/flake.nix @@ -26,11 +26,12 @@ }; build = targets: buildTarget.override { inherit targets; }; in rec { - nim-codex = build ["all"]; - default = nim-codex; + logos-storage-nim = build ["all"]; + libstorage = build ["libstorage"]; + default = logos-storage-nim; }); - nixosModules.nim-codex = { config, lib, pkgs, ... }: import ./nix/service.nix { + nixosModules.logos-storage-nim = { config, lib, pkgs, ... }: import ./nix/service.nix { inherit config lib pkgs self; circomCompatPkg = circom-compat.packages.${pkgs.system}.default; }; @@ -40,7 +41,8 @@ in { default = pkgs.mkShell { inputsFrom = [ - packages.${system}.nim-codex + packages.${system}.logos-storage-nim + packages.${system}.libstorage circom-compat.packages.${system}.default ]; # Not using buildInputs to override fakeGit and fakeCargo. @@ -51,24 +53,24 @@ checks = forAllSystems (system: let pkgs = pkgsFor.${system}; in { - nim-codex-test = pkgs.nixosTest { - name = "nim-codex-test"; + logos-storage-nim-test = pkgs.nixosTest { + name = "logos-storage-nim-test"; nodes = { server = { config, pkgs, ... }: { - imports = [ self.nixosModules.nim-codex ]; - services.nim-codex.enable = true; - services.nim-codex.settings = { - data-dir = "/var/lib/nim-codex-test"; + imports = [ self.nixosModules.logos-storage-nim ]; + services.logos-storage-nim.enable = true; + services.logos-storage-nim.settings = { + data-dir = "/var/lib/logos-storage-nim-test"; }; - systemd.services.nim-codex.serviceConfig.StateDirectory = "nim-codex-test"; + systemd.services.logos-storage-nim.serviceConfig.StateDirectory = "logos-storage-nim-test"; }; }; testScript = '' - print("Starting test: nim-codex-test") + print("Starting test: logos-storage-nim-test") machine.start() - machine.wait_for_unit("nim-codex.service") - machine.succeed("test -d /var/lib/nim-codex-test") - machine.wait_until_succeeds("journalctl -u nim-codex.service | grep 'Started Storage node'", 10) + machine.wait_for_unit("logos-storage-nim.service") + machine.succeed("test -d /var/lib/logos-storage-nim-test") + machine.wait_until_succeeds("journalctl -u logos-storage-nim.service | grep 'Started Storage node'", 10) ''; }; }); diff --git a/nix/README.md b/nix/README.md index f389f568..ca3cce64 100644 --- a/nix/README.md +++ b/nix/README.md @@ -22,6 +22,12 @@ It can be also done without even cloning the repo: nix build 'git+https://github.com/logos-storage/logos-storage-nim?submodules=1#' ``` +To build the C bindings you can use: + +```sh +nix build ".?submodules=1#libstorage" +``` + ## Running ```sh diff --git a/nix/checksums.nix b/nix/checksums.nix index d79345d2..c9c9f3d4 100644 --- a/nix/checksums.nix +++ b/nix/checksums.nix @@ -6,7 +6,7 @@ let in pkgs.fetchFromGitHub { owner = "nim-lang"; repo = "checksums"; - rev = tools.findKeyValue "^ +ChecksumsStableCommit = \"([a-f0-9]+)\"$" sourceFile; + rev = tools.findKeyValue "^ +ChecksumsStableCommit = \"([a-f0-9]+)\".*$" sourceFile; # WARNING: Requires manual updates when Nim compiler version changes. - hash = "sha256-Bm5iJoT2kAvcTexiLMFBa9oU5gf7d4rWjo3OiN7obWQ="; + hash = "sha256-JZhWqn4SrAgNw/HLzBK0rrj3WzvJ3Tv1nuDMn83KoYY="; } diff --git a/nix/default.nix b/nix/default.nix index 3b2d7fad..c5a288d9 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -83,8 +83,14 @@ in pkgs.gcc13Stdenv.mkDerivation rec { ''; installPhase = '' - mkdir -p $out/bin - cp build/storage $out/bin/ + if [ -f build/storage ]; then + mkdir -p $out/bin + cp build/storage $out/bin/ + else + mkdir -p $out/lib $out/include + cp build/libstorage* $out/lib/ + cp library/libstorage.h $out/include/ + fi ''; meta = with pkgs.lib; { @@ -93,4 +99,4 @@ in pkgs.gcc13Stdenv.mkDerivation rec { license = licenses.mit; platforms = stableSystems; }; -} \ No newline at end of file +} diff --git a/nix/nimble.nix b/nix/nimble.nix index 39c5e0ff..6eb4c8a0 100644 --- a/nix/nimble.nix +++ b/nix/nimble.nix @@ -9,5 +9,5 @@ in pkgs.fetchFromGitHub { fetchSubmodules = true; rev = tools.findKeyValue "^ +NimbleStableCommit = \"([a-f0-9]+)\".+" sourceFile; # WARNING: Requires manual updates when Nim compiler version changes. - hash = "sha256-Rz48sGUKZEAp+UySla+MlsOfsERekuGKw69Tm11fDz8="; + hash = "sha256-wgzFhModFkwB8st8F5vSkua7dITGGC2cjoDvgkRVZMs="; } diff --git a/nix/tools.nix b/nix/tools.nix index 108d3860..47e99450 100644 --- a/nix/tools.nix +++ b/nix/tools.nix @@ -9,7 +9,12 @@ in { let linesFrom = file: splitString "\n" (fileContents file); matching = regex: lines: map (line: match regex line) lines; - extractMatch = matches: last (flatten (remove null matches)); + extractMatch = matches: + let xs = flatten (remove null matches); + in if xs == [] then + throw "findKeyValue: no match for regex '${regex}' in ${toString sourceFile}" + else + last xs; in extractMatch (matching regex (linesFrom sourceFile)); }