Description
The current implementation of home.activation.opencodeAuth in home/dotfiles.nix embeds a multi-line shell script directly within a Nix string. This makes the logic difficult to lint, test, and maintain.
Implementation Requirements
1. Create the Shell Script
Create a new file at home/scripts/opencode-auth-setup.sh. The script must:
- Accept the path to the authentication file as its first argument, or default to
"$HOME/.local/share/opencode/auth.json".
- Ensure the directory containing the file exists (
mkdir -p).
- Initial Setup: If the file does not exist, create it with the content:
{"ollama":{"type":"api","key":"ollama"}}.
- Validation: If the file exists, check if it is valid JSON using
jq. If invalid, print a warning to stderr and exit with code 0.
- Update Logic: If valid, use
jq to ensure the ollama key exists. If missing, append it: . + {"ollama": {"type": "api", "key": "ollama"}}.
- Atomicity: Use a temporary file for the
jq transformation and mv it to the target location.
- Safety: Use
set -euo pipefail and ensure the script is executable.
2. Update Nix Configuration
Modify home/dotfiles.nix to:
- Remove the inline shell script from
home.activation.opencodeAuth.
- Ensure the new script is available in the user's environment.
- Call the script within the
home.activation.opencodeAuth block.
Definition of Done (DoD)
Description
The current implementation of
home.activation.opencodeAuthinhome/dotfiles.nixembeds a multi-line shell script directly within a Nix string. This makes the logic difficult to lint, test, and maintain.Implementation Requirements
1. Create the Shell Script
Create a new file at
home/scripts/opencode-auth-setup.sh. The script must:"$HOME/.local/share/opencode/auth.json".mkdir -p).{"ollama":{"type":"api","key":"ollama"}}.jq. If invalid, print a warning tostderrand exit with code0.jqto ensure theollamakey exists. If missing, append it:. + {"ollama": {"type": "api", "key": "ollama"}}.jqtransformation andmvit to the target location.set -euo pipefailand ensure the script is executable.2. Update Nix Configuration
Modify
home/dotfiles.nixto:home.activation.opencodeAuth.home.activation.opencodeAuthblock.Definition of Done (DoD)
home/scripts/opencode-auth-setup.sh.shellcheck.home/dotfiles.nixno longer contains the inline shell script.