-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
200 lines (170 loc) · 5.84 KB
/
flake.nix
File metadata and controls
200 lines (170 loc) · 5.84 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# [Created by AI: Claude Code]
{
description = "AI Bash Command - Natural language to shell command translation";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python311;
# Build the core abc-cli package
abc-cli = python.pkgs.buildPythonApplication rec {
pname = "abc-cli";
version = "2025.09.04";
format = "pyproject";
src = ./.;
nativeBuildInputs = with python.pkgs; [
hatchling
];
propagatedBuildInputs = with python.pkgs; [
click
tomli
distro
prompt-toolkit
readchar
];
# Only include the abc_cli directory
preBuild = ''
cd $src
cp -r abc_cli pyproject.toml LICENSE README.md $NIX_BUILD_TOP/
cd $NIX_BUILD_TOP
'';
# Install shell integration scripts
postInstall = ''
mkdir -p $out/share/abc
cp ${./abc_cli/abc.sh} $out/share/abc/abc.sh
cp ${./abc_cli/abc.tcsh} $out/share/abc/abc.tcsh
# Don't patch the scripts here - let the wrapper handle it
'';
pythonImportsCheck = [ "abc_cli" ];
};
# Build provider packages
abc-provider-anthropic = python.pkgs.buildPythonPackage rec {
pname = "abc-provider-anthropic";
version = "2025.09.04";
format = "pyproject";
src = ./abc_provider_anthropic;
nativeBuildInputs = with python.pkgs; [
hatchling
];
propagatedBuildInputs = with python.pkgs; [
anthropic
abc-cli
];
pythonImportsCheck = [ "abc_provider_anthropic" ];
};
abc-provider-aws-bedrock = python.pkgs.buildPythonPackage rec {
pname = "abc-provider-aws-bedrock";
version = "2025.09.04";
format = "pyproject";
src = ./abc_provider_aws_bedrock;
nativeBuildInputs = with python.pkgs; [
hatchling
];
propagatedBuildInputs = with python.pkgs; [
boto3
abc-cli
];
pythonImportsCheck = [ "abc_provider_aws_bedrock" ];
};
# Combined package with all providers (wrapper around abc-cli)
abc-with-providers = pkgs.symlinkJoin {
name = "abc-${abc-cli.version}";
paths = [ abc-cli ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
# Wrap the executables to include providers in PYTHONPATH
wrapProgram $out/bin/abc_generate \
--prefix PYTHONPATH : "${python.pkgs.makePythonPath [
abc-provider-anthropic
abc-provider-aws-bedrock
]}"
wrapProgram $out/bin/abc_setup \
--prefix PYTHONPATH : "${python.pkgs.makePythonPath [
abc-provider-anthropic
abc-provider-aws-bedrock
]}"
# Copy and patch shell scripts to use the wrapped executables
rm -rf $out/share/abc
mkdir -p $out/share/abc
cp ${abc-cli}/share/abc/abc.sh $out/share/abc/abc.sh
cp ${abc-cli}/share/abc/abc.tcsh $out/share/abc/abc.tcsh
substituteInPlace $out/share/abc/abc.sh \
--replace "abc_generate" "$out/bin/abc_generate"
substituteInPlace $out/share/abc/abc.tcsh \
--replace "abc_generate" "$out/bin/abc_generate"
'';
passthru = {
inherit (abc-cli) version;
pythonPath = python.pkgs.makePythonPath [
abc-cli
abc-provider-anthropic
abc-provider-aws-bedrock
];
};
};
# Shell integration helper script
shellIntegrationSetup = pkgs.writeShellScriptBin "abc-shell-setup" ''
#!/usr/bin/env bash
set -e
SHELL_NAME=$(basename "$SHELL")
ABC_SHARE="${abc-with-providers}/share/abc"
case "$SHELL_NAME" in
bash|zsh)
echo "source $ABC_SHARE/abc.sh"
;;
tcsh)
echo "source $ABC_SHARE/abc.tcsh"
;;
*)
echo "Unsupported shell: $SHELL_NAME" >&2
echo "Supported shells: bash, zsh, tcsh" >&2
exit 1
;;
esac
'';
in
{
# Packages
packages = {
default = abc-with-providers;
abc-cli = abc-cli;
abc-provider-anthropic = abc-provider-anthropic;
abc-provider-aws-bedrock = abc-provider-aws-bedrock;
abc-shell-setup = shellIntegrationSetup;
};
# Development shell
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
(python.withPackages (ps: with ps; [
click
tomli
anthropic
boto3
pytest
pytest-cov
build
twine
]))
abc-with-providers
];
shellHook = ''
echo "abc development environment"
echo "Python: ${python.version}"
echo ""
echo "To enable abc in this shell:"
echo " source ${abc-with-providers}/share/abc/abc.sh"
echo ""
export ABC_SHELL_INTEGRATION="${abc-with-providers}/share/abc"
'';
};
# App for nix run
apps.default = {
type = "app";
program = "${abc-with-providers}/bin/abc_generate";
};
});
}