mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-10 01:13:10 +00:00
nix: simplified codex service definition
configObject option is used to define the configuration which is then dumped to a toml file and is used as input to codex binary(conditionally). Signed-off-by: markoburcul <marko@status.im>
This commit is contained in:
parent
08d7fbdd2e
commit
95ae2e9db2
32
flake.nix
32
flake.nix
@ -1,5 +1,5 @@
|
||||
{
|
||||
description = "Codex build flake";
|
||||
description = "Nim Codex build flake";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
||||
@ -26,18 +26,40 @@
|
||||
};
|
||||
build = targets: buildTarget.override { inherit targets; };
|
||||
in rec {
|
||||
codex = build ["all"];
|
||||
default = codex;
|
||||
nim-codex = build ["all"];
|
||||
default = nim-codex;
|
||||
});
|
||||
|
||||
nixosModules.codex = import ./nix/codex.nix;
|
||||
nixosModules.nim-codex = import ./nix/service.nix;
|
||||
|
||||
checks = forAllSystems (system: let
|
||||
pkgs = pkgsFor.${system};
|
||||
in {
|
||||
nim-codex-test = pkgs.nixosTest {
|
||||
name = "nim-codex-test";
|
||||
nodes = {
|
||||
server = { config, pkgs, ... }: {
|
||||
imports = [ self.nixosModules.nim-codex ];
|
||||
services.nim-codex.enable = true;
|
||||
services.nim-codex.dataDir = "/var/lib/nim-codex-test";
|
||||
};
|
||||
};
|
||||
testScript = ''
|
||||
print("Starting test: nim-codex-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 codex node'", 10)
|
||||
'';
|
||||
};
|
||||
});
|
||||
|
||||
devShells = forAllSystems (system: let
|
||||
pkgs = pkgsFor.${system};
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
inputsFrom = [
|
||||
packages.${system}.codex
|
||||
packages.${system}.nim-codex
|
||||
circom-compat.packages.${system}.default
|
||||
];
|
||||
# Not using buildInputs to override fakeGit and fakeCargo.
|
||||
|
||||
@ -25,11 +25,17 @@ let
|
||||
tools = callPackage ./tools.nix {};
|
||||
in pkgs.gcc11Stdenv.mkDerivation rec {
|
||||
|
||||
pname = "codex";
|
||||
pname = "nim-codex";
|
||||
|
||||
version = "${tools.findKeyValue "version = \"([0-9]+\.[0-9]+\.[0-9]+)\"" ../codex.nimble}-${revision}";
|
||||
|
||||
inherit src;
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "codex-storage";
|
||||
repo = "nim-codex";
|
||||
rev = "HEAD";
|
||||
sha256 = "sha256-cPQDV46Z9z27Hd32eW726fC3J1dAhXyljbhAgFXVEXQ=";
|
||||
fetchSubmodules = true;
|
||||
};
|
||||
|
||||
# Dependencies that should exist in the runtime environment.
|
||||
buildInputs = with pkgs; [
|
||||
@ -76,7 +82,7 @@ in pkgs.gcc11Stdenv.mkDerivation rec {
|
||||
'';
|
||||
|
||||
meta = with pkgs.lib; {
|
||||
description = "Codex storage system";
|
||||
description = "Nim Codex storage system";
|
||||
homepage = "https://github.com/codex-storage/nim-codex";
|
||||
license = licenses.mit;
|
||||
platforms = stableSystems;
|
||||
|
||||
@ -6,27 +6,21 @@ let
|
||||
|
||||
toml = pkgs.formats.toml { };
|
||||
|
||||
cfg = config.services.codex;
|
||||
cfg = config.services.nim-codex;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
services.codex = {
|
||||
enable = mkEnableOption "Codex Node service.";
|
||||
services.nim-codex = {
|
||||
enable = mkEnableOption "Nim Codex Node service.";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.callPackage ./default.nix { };
|
||||
defaultText = literalExpression "pkgs.codex";
|
||||
description = lib.mdDoc "Package to use as Codex node.";
|
||||
defaultText = literalExpression "pkgs.nim-codex";
|
||||
description = lib.mdDoc "Package to use as Nim Codex node.";
|
||||
};
|
||||
|
||||
configFile = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "Path to the Codex configuration file.";
|
||||
};
|
||||
|
||||
configObject = lib.mkOption {
|
||||
settings = lib.mkOption {
|
||||
default = { };
|
||||
type = toml.type;
|
||||
description = ''Structured settings object that will be used to generate a TOML config file.'';
|
||||
@ -36,10 +30,10 @@ in
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.etc = {
|
||||
"codex/config.toml".source = toml.generate "config.toml" cfg.configObject;
|
||||
"nim-codex/config.toml".source = toml.generate "config.toml" cfg.settings;
|
||||
};
|
||||
systemd.services.codex = {
|
||||
description = "Codex Node";
|
||||
systemd.services.nim-codex = {
|
||||
description = "Nim Codex Node";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
@ -50,9 +44,13 @@ in
|
||||
NoNewPrivileges = true;
|
||||
PrivateDevices = true;
|
||||
MemoryDenyWriteExecute = true;
|
||||
ExecStart = ''${cfg.package}/bin/codex --config-file=${if cfg.configFile != null then cfg.configFile else "/etc/codex/config.toml"}'';
|
||||
ExecStart = "${cfg.package}/bin/nim-codex --config-file=/etc/nim-codex/config.toml";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
restartIfChanged = true;
|
||||
restartTriggers = [
|
||||
"/etc/nim-codex/config.toml"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user