diff --git a/conmorfeusz/conmorfeusz/cli/__init__.py b/conmorfeusz/conmorfeusz/cli/__init__.py index a71d904..ad5f77b 100644 --- a/conmorfeusz/conmorfeusz/cli/__init__.py +++ b/conmorfeusz/conmorfeusz/cli/__init__.py @@ -14,9 +14,8 @@ from conmorfeusz.server import StandaloneApplication @click.option('--ccpl-port', default=3000, help='Port which internal concraft-pl server will be listening on.') @click.option('--ccpl-model', default=None, help='Model used by concraft-pl. It will fallback to CONCRAFT_PL_MODEL envvar if not specified.') @click.option('--ccpl-bin', default=None, help='Concraft-pl binary file. It will fallback to CONCRAFT_PL_BIN envvar if not specified.') -@click.option('--ccpl-core-num', default=1, help='Number of cores used to run Concraft-pl logic.') -@click.option('--ccpl-alloc-size', default=64, help='Allocation size for Concraft-pl.') -def run(host, port, workers, ccpl_port, ccpl_model, ccpl_bin, ccpl_core_num, ccpl_alloc_size): +@click.option("--ccpl-rts", default="-A4M -N4", help='Runtime system configuration for Concraft-pl VM.') +def run(host, port, workers, ccpl_port, ccpl_model, ccpl_bin, ccpl_rts): """ Glues all services together and starts the holistic app. """ @@ -30,7 +29,7 @@ def run(host, port, workers, ccpl_port, ccpl_model, ccpl_bin, ccpl_core_num, ccp if ccpl_bin is None: raise Exception("Concraft-pl binary file must be specified either by --ccpl-bin option or by CONCRAFT_PL_BIN environment variable") - concraft_cfg = (ccpl_model, ccpl_bin, ccpl_port, ccpl_core_num, ccpl_alloc_size) + concraft_cfg = (ccpl_model, ccpl_bin, ccpl_port, ccpl_rts.split()) with ccpl.start_server(*concraft_cfg): options = { diff --git a/conmorfeusz/conmorfeusz/concraft/__init__.py b/conmorfeusz/conmorfeusz/concraft/__init__.py index c834814..2431a94 100644 --- a/conmorfeusz/conmorfeusz/concraft/__init__.py +++ b/conmorfeusz/conmorfeusz/concraft/__init__.py @@ -86,7 +86,7 @@ class Concraft(object): class Server(object): def __init__(self, model_path, concraft_path="concraft-pl", port=3000, - core_num=1, allocation_size=64): + runtimeArgs=[]): """ Start a Concraft-pl server instance in the background. @@ -105,8 +105,7 @@ class Server(object): """ self.port = port self.concraft_server = Popen([concraft_path, 'server', - '--port={}'.format(port), '-i', model_path, '+RTS', - '-N{}'.format(core_num), '-A{}M'.format(allocation_size),], + '--port={}'.format(port), '-i', model_path, '+RTS', *runtimeArgs], stdin=PIPE, stdout=PIPE, stderr=PIPE) # print(u"Concraft model " + model_path + u" loading...") loaded = False diff --git a/module.nix b/module.nix index 615be5e..85c3089 100644 --- a/module.nix +++ b/module.nix @@ -6,20 +6,6 @@ self: { ... }: let cfg = config.services.conmorfeusz; - - # Helper function to convert attrset to CLI arguments - # { host = "0.0.0.0"; port = 8888; } -> "--host '0.0.0.0' --port '8888'" - attrsToArgs = attrs: - lib.concatStringsSep " " ( - lib.mapAttrsToList (name: value: "--${name} ${lib.escapeShellArg (toString value)}") attrs - ); - - # Helper function to convert attrset to CLI arguments with prefix - # { port = 3000; bin = "..."; } -> "--ccpl-port '3000' --ccpl-bin '...'" - attrsToArgsWithPrefix = prefix: attrs: - lib.concatStringsSep " " ( - lib.mapAttrsToList (name: value: "--${prefix}-${name} ${lib.escapeShellArg (toString value)}") attrs - ); in { options.services.conmorfeusz = { enableMorfeusz = lib.mkEnableOption "Morfeusz in environment.systemPackages"; @@ -91,8 +77,14 @@ in { serviceConfig = { Type = "simple"; ExecStart = let - mainArgs = attrsToArgs cfg.conmorfeusz.config; - ccplArgs = attrsToArgsWithPrefix "ccpl" cfg.conmorfeusz.concraft-pl; + mainArgs = lib.cli.toGNUCommandLineShell {} cfg.conmorfeusz.config; + + ccplArgs = + lib.cli.toGNUCommandLineShell { + mkOptionName = k: "--ccpl-${k}"; + } + cfg.conmorfeusz.concraft-pl; + allArgs = lib.concatStringsSep " " (lib.filter (s: s != "") [mainArgs ccplArgs]); in "${self.packages.${pkgs.system}.conmorfeusz}/bin/conmorfeusz ${allArgs}";