1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00

gemini-cli: context support multiple file generation

Support multiple context files since gemini supports configuring
multiple names as supported / looked for.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-10-12 17:43:05 -05:00
parent 5ead1867bb
commit e121f3773f
6 changed files with 74 additions and 38 deletions

View file

@ -91,29 +91,41 @@ in
}; };
context = lib.mkOption { context = lib.mkOption {
type = lib.types.nullOr (lib.types.either lib.types.lines lib.types.path); type = lib.types.attrsOf (lib.types.either lib.types.lines lib.types.path);
default = null; default = { };
example = lib.literalExpression '' example = lib.literalExpression ''
# Inline content example: {
''' GEMINI = '''
# Global Context # 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 - Follow consistent code style
- Write clear comments - Write clear comments
- Test your changes - Test your changes
''' ''';
# Or reference an existing file: AGENTS = ./path/to/agents.md;
# ./path/to/GEMINI.md
CONTEXT = '''
Additional context instructions here.
''';
}
''; '';
description = '' 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 != { }) { file.".gemini/settings.json" = lib.mkIf (cfg.settings != { }) {
source = jsonFormat.generate "gemini-cli-settings.json" 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; 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' ( home.file = lib.mapAttrs' (
n: v: n: v:

View file

@ -0,0 +1 @@
Additional context for specialized tasks.

View file

@ -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

View file

@ -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}
'';
}

View file

@ -1,21 +1,45 @@
{ {
programs.gemini-cli = { programs.gemini-cli = {
enable = true; enable = true;
context = '' context = {
# Global 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 - Follow consistent code style
- Write clear comments - Write clear comments
- Test your changes - 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 = '' nmt.script = ''
assertFileExists home-files/.gemini/GEMINI.md assertFileExists home-files/.gemini/GEMINI.md
assertFileContent 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} ${./context.md}
assertFileExists home-files/.gemini/CONTEXT.md
assertFileContent home-files/.gemini/CONTEXT.md \
${./context-additional.md}
''; '';
} }

View file

@ -1,5 +1,4 @@
{ {
gemini-cli-settings = ./settings.nix; gemini-cli-settings = ./settings.nix;
gemini-cli-context = ./context.nix; gemini-cli-context = ./context.nix;
gemini-cli-context-source = ./context-source.nix;
} }