diff --git a/modules/programs/aiac.nix b/modules/programs/aiac.nix new file mode 100644 index 000000000..26b9efe84 --- /dev/null +++ b/modules/programs/aiac.nix @@ -0,0 +1,54 @@ +{ + lib, + pkgs, + config, + ... +}: +let + inherit (lib) + mkIf + mkEnableOption + mkPackageOption + mkOption + ; + + cfg = config.programs.aiac; + tomlFormat = pkgs.formats.toml { }; +in +{ + meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ]; + options.programs.aiac = { + enable = mkEnableOption "aiac"; + package = mkPackageOption pkgs "aiac" { nullable = true; }; + settings = mkOption { + inherit (tomlFormat) type; + default = { }; + example = { + default_backend = "official_openai"; + backends = { + official_openai = { + type = "openai"; + api_key = "API KEY"; + default_model = "gpt-4o"; + }; + + localhost = { + type = "ollama"; + url = "http://localhost:11434/api"; + }; + }; + }; + description = '' + Configuration settings for aiac. All the available options can be found here: + . + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = mkIf (cfg.package != null) [ cfg.package ]; + xdg.configFile."aiac/aiac.toml" = mkIf (cfg.settings != { }) { + source = tomlFormat.generate "aiac.toml" cfg.settings; + }; + }; +} diff --git a/tests/modules/programs/aiac/aiac.toml b/tests/modules/programs/aiac/aiac.toml new file mode 100644 index 000000000..b4de8c9bc --- /dev/null +++ b/tests/modules/programs/aiac/aiac.toml @@ -0,0 +1,10 @@ +default_backend = "official_openai" + +[backends.localhost] +type = "ollama" +url = "http://localhost:11434/api" + +[backends.official_openai] +api_key = "API KEY" +default_model = "gpt-4o" +type = "openai" diff --git a/tests/modules/programs/aiac/default.nix b/tests/modules/programs/aiac/default.nix new file mode 100644 index 000000000..5d93c582d --- /dev/null +++ b/tests/modules/programs/aiac/default.nix @@ -0,0 +1 @@ +{ aiac-example-config = ./example-config.nix; } diff --git a/tests/modules/programs/aiac/example-config.nix b/tests/modules/programs/aiac/example-config.nix new file mode 100644 index 000000000..71e53031d --- /dev/null +++ b/tests/modules/programs/aiac/example-config.nix @@ -0,0 +1,26 @@ +{ + programs.aiac = { + enable = true; + settings = { + default_backend = "official_openai"; + backends = { + official_openai = { + type = "openai"; + api_key = "API KEY"; + default_model = "gpt-4o"; + }; + + localhost = { + type = "ollama"; + url = "http://localhost:11434/api"; + }; + }; + }; + }; + + nmt.script = '' + assertFileExists home-files/.config/aiac/aiac.toml + assertFileContent home-files/.config/aiac/aiac.toml \ + ${./aiac.toml} + ''; +}