nixos-config/components/terminal/heygpt.nix
Ingolf Wagner 7a6510a4e6
nix fmt
2024-08-29 08:26:04 +07:00

31 lines
855 B
Nix

{
config,
lib,
pkgs,
...
}:
with lib;
{
options.components.terminal.heygpt.enable = mkOption {
type = lib.types.bool;
#default = config.components.terminal.enable;
default = false;
};
config = mkIf (config.components.terminal.heygpt.enable) {
environment.systemPackages = [
(pkgs.writers.writeBashBin "heygpt" ''
export OPENAI_API_BASE="https://api.openai.com/v1"
export OPENAI_API_KEY=$(pass openai/apikey)
${lib.getExe pkgs.heygpt} "$@"
'')
(pkgs.writers.writeBashBin "heygpt-models" ''
export OPENAI_API_KEY=$(pass openai/apikey)
${getExe pkgs.curl} https://api.openai.com/v1/models \
-H "Authorization: Bearer $OPENAI_API_KEY" \
| ${getExe pkgs.jq} --raw-output '.data[] | .id' \
| ${getExe pkgs.gum} filter
'')
];
};
}