forked from librefang/librefang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
263 lines (236 loc) · 9.95 KB
/
Copy pathflake.nix
File metadata and controls
263 lines (236 loc) · 9.95 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
{
description = "LibreFang - Open-source Agent Operating System";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" "rust-analyzer" "clippy" ];
};
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
# Common build inputs needed by every workspace crate.
nativeBuildInputs = with pkgs; [
pkg-config
rustToolchain
];
buildInputs = with pkgs; [
openssl
dbus
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.apple-sdk
pkgs.libiconv
];
# `librefang-desktop` pulls in Tauri / wry, which require the GTK
# webview stack at link time. Split these out so the CLI build (the
# common case) doesn't pay for the heavy native graphics deps just to
# produce a server binary — this is what breaks `nix build
# .#librefang-cli` on stock NixOS today (#2937).
desktopBuildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs; [
glib
gtk3
libsoup_3
webkitgtk_4_1
atkmm
cairo
gdk-pixbuf
pango
# tray-icon dlopens libayatana-appindicator3.so.1 at runtime, not
# a link dep. wrapGAppsHook3 + gappsWrapperArgs in the desktop
# derivation below puts this lib dir on LD_LIBRARY_PATH so the
# dlopen resolves (#3052, #3192).
libayatana-appindicator
]);
# Filter source to include Rust files plus non-Rust assets needed at compile time
src = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
./crates/librefang-types/locales
./crates/librefang-api/static
./crates/librefang-api/src/login_page.html
./crates/librefang-cli/templates
./crates/librefang-cli/locales
./crates/librefang-desktop/tauri.conf.json
./crates/librefang-desktop/capabilities
./crates/librefang-desktop/icons
./crates/librefang-desktop/gen
./packages/whatsapp-gateway
./deploy/docker-compose.observability.yml
./deploy/grafana
./deploy/otel-collector
./deploy/prometheus
./deploy/tempo
];
};
commonArgs = {
inherit src nativeBuildInputs buildInputs;
pname = "librefang";
strictDeps = true;
};
# CLI build scope — do NOT compile the desktop crate's native
# dependencies just to produce the CLI binary. Scoping the
# deps-only build to `--package librefang-cli` keeps
# `nix build .#librefang-cli` green on machines that don't have
# the GTK / webview stack installed.
cliArgs = commonArgs // {
pname = "librefang-cli";
cargoExtraArgs = "--package librefang-cli";
};
cliCargoArtifacts = craneLib.buildDepsOnly cliArgs;
librefang-cli = craneLib.buildPackage (cliArgs // {
cargoArtifacts = cliCargoArtifacts;
doCheck = false; # Tests require network/runtime setup.
meta = with pkgs.lib; {
description = "LibreFang — Open-source Agent Operating System (CLI / daemon)";
homepage = "https://github.com/librefang/librefang";
license = licenses.mit;
platforms = platforms.unix;
mainProgram = "librefang";
};
});
# Desktop build scope — adds the GTK / webview deps on Linux.
desktopArgs = commonArgs // {
pname = "librefang-desktop";
cargoExtraArgs = "--package librefang-desktop";
buildInputs = buildInputs ++ desktopBuildInputs;
};
desktopCargoArtifacts = craneLib.buildDepsOnly desktopArgs;
# Desktop entry assembled with the standard nixpkgs helper so the
# output matches XDG conventions (proper escaping, hicolor icon
# theme layout, no manual heredoc).
librefangDesktopItem = pkgs.makeDesktopItem {
name = "librefang-desktop";
desktopName = "LibreFang";
comment = "Open-source Agent Operating System";
exec = "librefang-desktop";
icon = "librefang-desktop";
terminal = false;
type = "Application";
categories = [ "Development" "Utility" ];
keywords = [ "AI" "Agent" "LLM" "Automation" ];
# Match the GTK app id Tauri reports so launchers can pair the
# window with its menu entry / icon.
startupWMClass = "librefang-desktop";
};
librefang-desktop = craneLib.buildPackage (desktopArgs // {
cargoArtifacts = desktopCargoArtifacts;
doCheck = false;
# `copyDesktopItems` is a no-op on darwin; gating the hook on
# Linux keeps the macOS build path unchanged.
nativeBuildInputs = nativeBuildInputs
++ pkgs.lib.optionals pkgs.stdenv.isLinux [
pkgs.copyDesktopItems
# wrapGAppsHook3 injects LD_LIBRARY_PATH (via gappsWrapperArgs
# below) and the GTK runtime env (XDG_DATA_DIRS,
# GIO_MODULE_DIR, GSETTINGS_SCHEMA_DIR, …) the webview needs.
pkgs.wrapGAppsHook3
];
desktopItems = pkgs.lib.optionals pkgs.stdenv.isLinux [ librefangDesktopItem ];
# tray-icon → libappindicator-sys dlopens
# `libayatana-appindicator3.so.1` at runtime with no DT_NEEDED
# entry. patchelf --add-rpath writes DT_RUNPATH, which ld.so only
# consults for DT_NEEDED deps — never for dlopen string lookups —
# so the previous RPATH fix (#3052) never actually worked, the
# tray icon silently failed to appear on NixOS (#3192). Wrapping
# with gappsWrapperArgs prepends the appindicator lib dir to
# LD_LIBRARY_PATH so the dlopen call resolves.
preFixup = pkgs.lib.optionalString pkgs.stdenv.isLinux ''
gappsWrapperArgs+=(
--prefix LD_LIBRARY_PATH : "${pkgs.libayatana-appindicator}/lib"
)
'';
postInstall =
let
# `128x128@2x.png` contains an `@`, which is not a legal
# character inside `${…}` Nix path-expression interpolation,
# so we bind the icons directory once and concatenate the
# filenames at the shell layer.
iconsDir = ./crates/librefang-desktop/icons;
in
pkgs.lib.optionalString pkgs.stdenv.isLinux ''
# Install icons into the hicolor theme at every native size
# we ship in the repo so DEs can pick the right one without
# rescaling. Icon name must match the desktop entry's Icon=
# key.
install -Dm644 "${iconsDir}/32x32.png" \
"$out/share/icons/hicolor/32x32/apps/librefang-desktop.png"
install -Dm644 "${iconsDir}/128x128.png" \
"$out/share/icons/hicolor/128x128/apps/librefang-desktop.png"
install -Dm644 "${iconsDir}/128x128@2x.png" \
"$out/share/icons/hicolor/256x256/apps/librefang-desktop.png"
install -Dm644 "${iconsDir}/icon.png" \
"$out/share/icons/hicolor/512x512/apps/librefang-desktop.png"
'';
meta = with pkgs.lib; {
description = "LibreFang — Open-source Agent Operating System (desktop UI)";
homepage = "https://github.com/librefang/librefang";
license = licenses.mit;
platforms = platforms.linux ++ platforms.darwin;
mainProgram = "librefang-desktop";
};
});
# Full-workspace args for checks (clippy runs across the whole tree
# including librefang-desktop, so it needs the GTK inputs too).
workspaceArgs = commonArgs // {
buildInputs = buildInputs ++ desktopBuildInputs;
};
workspaceCargoArtifacts = craneLib.buildDepsOnly workspaceArgs;
in
{
checks = {
inherit librefang-cli;
librefang-clippy = craneLib.cargoClippy (workspaceArgs // {
cargoArtifacts = workspaceCargoArtifacts;
cargoClippyExtraArgs = "--workspace --all-targets -- -D warnings";
});
librefang-fmt = craneLib.cargoFmt {
inherit src;
pname = "librefang";
};
};
packages = {
default = librefang-cli;
inherit librefang-cli librefang-desktop;
};
apps.default = (flake-utils.lib.mkApp {
drv = librefang-cli;
}) // {
# Propagate the package's meta so `nix flake check` doesn't warn
# about the app lacking metadata.
meta = librefang-cli.meta;
};
devShells.default = craneLib.devShell {
checks = self.checks.${system};
packages = with pkgs; [
# Rust tooling (provided by crane devShell via checks)
cargo-watch
cargo-edit
cargo-expand
# Development tools
just
gh
git
nodejs
python3
] ++ desktopBuildInputs;
inputsFrom = [ librefang-cli ];
shellHook = ''
echo "LibreFang development environment loaded"
echo "Rust: $(rustc --version)"
'';
};
}
);
}