diff --git a/lib.nix b/lib.nix index 0f0f6ed..4986d93 100644 --- a/lib.nix +++ b/lib.nix @@ -1,4 +1,46 @@ { pkgs }: +let + inherit (pkgs) lib; +in { - mkWrapper = { }: { }; + mkWrapper = + { + config, + name, + enableTui ? false, + }: + let + removeNullAndEmptyAttrs = + attrs: + let + f = lib.filterAttrsRecursive (key: value: value != null && value != { }); + in + # filterAttrsRecursive doesn't delete the *resulting* empty attrs, so we must + # evaluate it again and to get rid of it. + lib.pipe attrs [ + f + f + ]; + toPCJson = + name: attrs: + pkgs.writeTextFile { + name = "process-compose-${name}.json"; + text = builtins.toJSON attrs; + }; + configFile = toPCJson name ( + removeNullAndEmptyAttrs ( + config + // { + is_tui_disabled = !enableTui; + } + ) + ); + in + pkgs.writeShellApplication { + inherit name; + text = '' + PC_CONFIG_FILES=${configFile} ${pkgs.process-compose}/bin/process-compose "$@" + + ''; + }; }