~ruther/agent-environments

ref: 5c9177d3efc133d65f5bccfbb5a2e36c6a282985 agent-environments/modules/claude.nix -rw-r--r-- 1.2 KiB
5c9177d3 — František Boháček Update flake inputs a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.claude;
  settingsFile = (pkgs.formats.json { }).generate "claude-settings.json" cfg.settings;
in
{
  options.claude = {
    enable = lib.mkEnableOption "Claude Code";
    package = lib.mkOption {
      type = lib.types.package;
      description = "The Claude Code package; must provide bin/claude.";
    };
    settings = lib.mkOption {
      type = (pkgs.formats.json { }).type;
      default = { };
      description = "Settings layered over the account's settings.json via --settings.";
    };
    plugins = lib.mkOption {
      type = lib.types.listOf lib.types.path;
      default = [ ];
      description = "Plugin directories, loaded with --plugin-dir. Nothing is installed into the account.";
    };
  };

  config.build.agents.claude = lib.mkIf cfg.enable {
    exe = lib.getExe' cfg.package "claude";
    stateEnvVar = "CLAUDE_CONFIG_DIR";
    instructionsFile = "CLAUDE.md";
    # Managed links: path relative to the state dir -> store path.
    files = { };
    flags =
      lib.optionals (cfg.settings != { }) [
        "--settings"
        "${settingsFile}"
      ]
      ++ lib.concatMap (p: [
        "--plugin-dir"
        "${p}"
      ]) cfg.plugins;
  };
}