From 5682ef4dd914162d93fa4a715c665597de00cf46 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Mon, 3 Jul 2023 13:08:20 -0400 Subject: [PATCH] added make-mprocs function --- flake.nix | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index c2d64f2..2f5789d 100644 --- a/flake.nix +++ b/flake.nix @@ -14,14 +14,14 @@ { writePythonApplication = {name, contentFile, extraRuntimeInputs ? [], python ? null}: let - python-to-use = python == null then pkgs.python311 else python; + python-to-use = if python == null then pkgs.python311 else python; wrappedScript = pkgs.writeText "wrappedScript" (builtins.readFile contentFile); in pkgs.writeShellApplication { name = name; runtimeInputs = [ wrappedScript - if python-to-use] ++ extraRuntimeInputs; + python-to-use] ++ extraRuntimeInputs; text = '' exec ${python-to-use}/bin/python ${wrappedScript} "$@" ''; @@ -39,5 +39,19 @@ exec ${pkgs.babashka}/bin/bb ${wrappedScript} "$@" ''; }; + make-mprocs = {name, derivations ? []}: let + mk-mprocs-procs = ret: derivation: ret ++ [{name = derivation.name; + value = {cmd = ["${derivation}/bin/${derivation.name}"];}; + }]; + mprocs-procs = builtins.listToAttrs (builtins.foldl' mk-mprocs-procs [] derivations); + mprocs-config = builtins.toJSON {procs = mprocs-procs;}; + mprocs-config-file = pkgs.writeText "config.yaml" mprocs-config; + in pkgs.writeShellApplication { + name = name; + runtimeInputs = [pkgs.mprocs] ++ derivations; + text = '' + ${pkgs.mprocs}/bin/mprocs --config ${mprocs-config-file} + ''; + }; }); }