diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 2fbbfe370..e70fcce1d 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -685,4 +685,10 @@ github = "3ulalia"; githubId = "179992797"; }; + ipsavitsky = { + name = "Ilya Savitsky"; + email = "ipsavitsky234@gmail.com"; + github = "ipsavitsky"; + githubId = 33558632; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 995aeba1b..f088f2909 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2118,6 +2118,17 @@ in { systemd service to ensure its execution. ''; } + + { + time = "2025-01-26T16:40:00+00:00"; + message = '' + A new module is available: 'programs.mods' + + mods is a command line AI tool that is highly configurable and allows + querying AI models hosted locally or by other services (OpenAI, + Cohere, Groq). + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 5f150f02d..7d3b54043 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -169,6 +169,7 @@ let ./programs/mercurial.nix ./programs/micro.nix ./programs/mise.nix + ./programs/mods.nix ./programs/mpv.nix ./programs/mr.nix ./programs/msmtp.nix diff --git a/modules/programs/mods.nix b/modules/programs/mods.nix new file mode 100644 index 000000000..95e5559bc --- /dev/null +++ b/modules/programs/mods.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: + +with lib; +let + cfg = config.programs.mods; + yamlFormat = pkgs.formats.yaml { }; +in { + meta.maintainers = [ hm.maintainers.ipsavitsky ]; + + options.programs.mods = { + enable = mkEnableOption "mods"; + + package = mkOption { + type = types.package; + default = pkgs.mods; + defaultText = literalExpression "pkgs.mods"; + description = "The mods package to install"; + }; + + settings = mkOption { + type = yamlFormat.type; + default = { }; + example = '' + { + default-model = "llama3.2"; + apis = { + ollama = { + base-url = "http://localhost:11434/api"; + models = { + "llama3.2" = { + max-input-chars = 650000; + }; + }; + }; + }; + } + ''; + description = '' + Configuration written to + {file}`$XDG_CONFIG_HOME/mods/mods.yml`. + + See for the full + list of options. + ''; + }; + + enableBashIntegration = + lib.hm.shell.mkBashIntegrationOption { inherit config; }; + + enableZshIntegration = + lib.hm.shell.mkZshIntegrationOption { inherit config; }; + + enableFishIntegration = + lib.hm.shell.mkFishIntegrationOption { inherit config; }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."mods/mods.yml" = mkIf (cfg.settings != { }) { + source = yamlFormat.generate "mods.yml" cfg.settings; + }; + + programs.bash.initExtra = mkIf cfg.enableBashIntegration (mkOrder 200 '' + source <(${cfg.package}/bin/mods completion bash) + ''); + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration (mkOrder 200 '' + source <(${cfg.package}/bin/mods completion zsh) + ''); + + programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration + (mkOrder 200 '' + ${cfg.package}/bin/mods completion fish | source + ''); + }; +} diff --git a/tests/default.nix b/tests/default.nix index b15491421..94a993da4 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -249,6 +249,7 @@ in import nmtSrc { ./modules/programs/mbsync ./modules/programs/micro ./modules/programs/mise + ./modules/programs/mods ./modules/programs/mpv ./modules/programs/mu ./modules/programs/mujmap diff --git a/tests/modules/programs/mods/basic-configuration.nix b/tests/modules/programs/mods/basic-configuration.nix new file mode 100644 index 000000000..31b97276a --- /dev/null +++ b/tests/modules/programs/mods/basic-configuration.nix @@ -0,0 +1,22 @@ +{ config, pkgs, ... }: { + config = { + programs.mods = { + enable = true; + package = pkgs.writeScriptBin "dummy-mods" ""; + settings = { + default-model = "llama3.2"; + apis = { + ollama = { + base-url = "http://localhost:11434/api"; + models = { "llama3.2" = { max-input-chars = 650000; }; }; + }; + }; + }; + }; + nmt.script = '' + assertFileExists home-files/.config/mods/mods.yml + assertFileContent home-files/.config/mods/mods.yml \ + ${./basic-configuration.yml} + ''; + }; +} diff --git a/tests/modules/programs/mods/basic-configuration.yml b/tests/modules/programs/mods/basic-configuration.yml new file mode 100644 index 000000000..aec63e220 --- /dev/null +++ b/tests/modules/programs/mods/basic-configuration.yml @@ -0,0 +1,7 @@ +apis: + ollama: + base-url: http://localhost:11434/api + models: + llama3.2: + max-input-chars: 650000 +default-model: llama3.2 diff --git a/tests/modules/programs/mods/default.nix b/tests/modules/programs/mods/default.nix new file mode 100644 index 000000000..cf9909b1b --- /dev/null +++ b/tests/modules/programs/mods/default.nix @@ -0,0 +1 @@ +{ mods-basic-configuration = ./basic-configuration.nix; }