-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathflake.nix
More file actions
139 lines (122 loc) · 5.05 KB
/
flake.nix
File metadata and controls
139 lines (122 loc) · 5.05 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
{
description = "goose - An AI agent CLI";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ rust-overlay.overlays.default ];
pkgs = import nixpkgs { inherit system overlays; };
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
# Read package metadata from Cargo.toml
cargoToml = builtins.fromTOML (builtins.readFile ./crates/goose-cli/Cargo.toml);
workspaceToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
commonInputs = [
rust
pkgs.rust-analyzer
pkgs.pkg-config
pkgs.openssl
];
darwinInputs = with pkgs; [
libiconv
apple-sdk
];
buildInputs = commonInputs
++ pkgs.lib.optionals pkgs.stdenv.isDarwin darwinInputs;
in
{
packages.default = pkgs.rustPlatform.buildRustPackage {
pname = cargoToml.package.name;
version = workspaceToml.workspace.package.version;
src = self;
cargoLock.lockFile = ./Cargo.lock;
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
# Pre-fetch rusty_v8 binary to avoid network access during build
# Map Nix system to rusty_v8 target triple
RUSTY_V8_ARCHIVE = let
cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock);
rustyV8Version = (builtins.head (builtins.filter (p: p.name == "v8") cargoLock.package)).version;
rustyV8Target = {
"x86_64-linux" = "x86_64-unknown-linux-gnu";
"aarch64-linux" = "aarch64-unknown-linux-gnu";
"x86_64-darwin" = "x86_64-apple-darwin";
"aarch64-darwin" = "aarch64-apple-darwin";
}.${system} or (throw "Unsupported system: ${system}");
rustyV8Sha256 = {
"x86_64-linux" = "sha256-chV1PAx40UH3Ute5k3lLrgfhih39Rm3KqE+mTna6ysE=";
"aarch64-linux" = "sha256-4IivYskhUSsMLZY97+g23UtUYh4p5jk7CzhMbMyqXyY=";
"x86_64-darwin" = "sha256-1jUuC+z7saQfPYILNyRJanD4+zOOhXU2ac/LFoytwho=";
"aarch64-darwin" = "sha256-yHa1eydVCrfYGgrZANbzgmmf25p7ui1VMas2A7BhG6k=";
}.${system};
in pkgs.fetchurl {
url = "https://github.com/denoland/rusty_v8/releases/download/v${rustyV8Version}/librusty_v8_release_${rustyV8Target}.a.gz";
sha256 = rustyV8Sha256;
};
nativeBuildInputs = with pkgs; [
pkg-config
clang
cmake
];
buildInputs = with pkgs; [
openssl
cacert # CA certificates for tests
libxcb # Required for xcap screenshot functionality
dbus # Required for system integration features
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin darwinInputs;
# Build only the CLI package
cargoBuildFlags = [ "--package" "goose-cli" ];
# Enable tests with proper environment
# Tests need writable HOME and XDG directories for config/cache access
doCheck = true;
checkPhase = ''
export HOME=$(mktemp -d)
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export XDG_STATE_HOME=$HOME/.local/state
export XDG_CACHE_HOME=$HOME/.cache
mkdir -p $XDG_CONFIG_HOME $XDG_DATA_HOME $XDG_STATE_HOME $XDG_CACHE_HOME
# Run tests for goose-cli package only
cargo test --package goose-cli --release
'';
meta = with pkgs.lib; {
description = workspaceToml.workspace.package.description;
homepage = workspaceToml.workspace.package.repository;
license = licenses.asl20; # Maps from "Apache-2.0" in Cargo.toml
mainProgram = "goose";
};
};
devShells.default = pkgs.mkShell {
packages = buildInputs ++ (with pkgs; [
cargo-watch
cargo-edit
clippy
gemini-cli # potentially useful during dev/testing
go_1_25 # 'just' run-ui
just # used in dev/test
nodejs_24 # 'just' run-ui
ripgrep
rustfmt
libxcb
dbus
yarn # 'just' install-deps
]);
shellHook = ''
echo "goose development environment"
echo "Rust version: $(rustc --version)"
echo ""
echo "Commands:"
echo " nix build - Build goose CLI"
echo " nix run - Run goose CLI"
echo " cargo build -p goose-cli - Build with cargo"
echo " cargo run -p goose-cli - Run with cargo"
'';
};
}
);
}