Files
process-compose-wrapper/lib.nix
2024-12-14 10:59:36 +04:00

47 lines
1001 B
Nix

{ pkgs }:
let
inherit (pkgs) lib;
in
{
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 "$@"
'';
};
}