diff --git a/modules/programs/gemini-cli.nix b/modules/programs/gemini-cli.nix index 5b5c1731d..accfdabf5 100644 --- a/modules/programs/gemini-cli.nix +++ b/modules/programs/gemini-cli.nix @@ -91,29 +91,41 @@ in }; context = lib.mkOption { - type = lib.types.nullOr (lib.types.either lib.types.lines lib.types.path); - default = null; + type = lib.types.attrsOf (lib.types.either lib.types.lines lib.types.path); + default = { }; example = lib.literalExpression '' - # Inline content example: - ''' - # Global Context + { + GEMINI = ''' + # Global Context - You are a helpful AI assistant for software development. + You are a helpful AI assistant for software development. - ## Coding Standards + ## Coding Standards - - Follow consistent code style - - Write clear comments - - Test your changes - ''' + - Follow consistent code style + - Write clear comments + - Test your changes + '''; - # Or reference an existing file: - # ./path/to/GEMINI.md + AGENTS = ./path/to/agents.md; + + CONTEXT = ''' + Additional context instructions here. + '''; + } ''; description = '' - Global context instructions that will be available across all projects. + An attribute set of context files to create in `~/.gemini/`. + The attribute name becomes the filename with `.md` extension automatically added. + The value is either inline content or a path to a file. - This will be written to `~/.gemini/GEMINI.md`. + Note: You can customize which context file names gemini-cli looks for by setting + `settings.context.fileName`. For example: + ```nix + settings = { + context.fileName = ["AGENTS.md", "CONTEXT.md", "GEMINI.md"]; + }; + ``` ''; }; }; @@ -126,12 +138,14 @@ in file.".gemini/settings.json" = lib.mkIf (cfg.settings != { }) { source = jsonFormat.generate "gemini-cli-settings.json" cfg.settings; }; - file.".gemini/GEMINI.md" = lib.mkIf (cfg.context != null) ( - if lib.isPath cfg.context then { source = cfg.context; } else { text = cfg.context; } - ); sessionVariables.GEMINI_MODEL = cfg.defaultModel; }; } + { + home.file = lib.mapAttrs' ( + n: v: lib.nameValuePair ".gemini/${n}.md" (if lib.isPath v then { source = v; } else { text = v; }) + ) cfg.context; + } { home.file = lib.mapAttrs' ( n: v: diff --git a/tests/modules/programs/gemini-cli/context-additional.md b/tests/modules/programs/gemini-cli/context-additional.md new file mode 100644 index 000000000..7e9fe2c85 --- /dev/null +++ b/tests/modules/programs/gemini-cli/context-additional.md @@ -0,0 +1 @@ +Additional context for specialized tasks. diff --git a/tests/modules/programs/gemini-cli/context-inline.md b/tests/modules/programs/gemini-cli/context-inline.md new file mode 100644 index 000000000..e5f3e288d --- /dev/null +++ b/tests/modules/programs/gemini-cli/context-inline.md @@ -0,0 +1,9 @@ +# Global Context + +You are a helpful AI assistant for software development. + +## Coding Standards + +- Follow consistent code style +- Write clear comments +- Test your changes diff --git a/tests/modules/programs/gemini-cli/context-source.nix b/tests/modules/programs/gemini-cli/context-source.nix deleted file mode 100644 index 004479368..000000000 --- a/tests/modules/programs/gemini-cli/context-source.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - programs.gemini-cli = { - enable = true; - context = ./context.md; - }; - nmt.script = '' - assertFileExists home-files/.gemini/GEMINI.md - assertFileContent home-files/.gemini/GEMINI.md \ - ${./context.md} - ''; -} diff --git a/tests/modules/programs/gemini-cli/context.nix b/tests/modules/programs/gemini-cli/context.nix index 329a1bd99..f4b547ac5 100644 --- a/tests/modules/programs/gemini-cli/context.nix +++ b/tests/modules/programs/gemini-cli/context.nix @@ -1,21 +1,45 @@ { programs.gemini-cli = { enable = true; - context = '' - # Global Context + context = { + # Test inline content + GEMINI = '' + # Global Context - You are a helpful AI assistant for software development. + You are a helpful AI assistant for software development. - ## Coding Standards + ## Coding Standards - - Follow consistent code style - - Write clear comments - - Test your changes - ''; + - Follow consistent code style + - Write clear comments + - Test your changes + ''; + # Test file path + AGENTS = ./context.md; + # Test another inline content + CONTEXT = '' + Additional context for specialized tasks. + ''; + }; + settings = { + context.fileName = [ + "AGENTS.md" + "CONTEXT.md" + "GEMINI.md" + ]; + }; }; nmt.script = '' assertFileExists home-files/.gemini/GEMINI.md assertFileContent home-files/.gemini/GEMINI.md \ + ${./context-inline.md} + + assertFileExists home-files/.gemini/AGENTS.md + assertFileContent home-files/.gemini/AGENTS.md \ ${./context.md} + + assertFileExists home-files/.gemini/CONTEXT.md + assertFileContent home-files/.gemini/CONTEXT.md \ + ${./context-additional.md} ''; } diff --git a/tests/modules/programs/gemini-cli/default.nix b/tests/modules/programs/gemini-cli/default.nix index 7f4fe41a0..e3e14bf20 100644 --- a/tests/modules/programs/gemini-cli/default.nix +++ b/tests/modules/programs/gemini-cli/default.nix @@ -1,5 +1,4 @@ { gemini-cli-settings = ./settings.nix; gemini-cli-context = ./context.nix; - gemini-cli-context-source = ./context-source.nix; }