-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathflake.nix
More file actions
223 lines (188 loc) · 6.73 KB
/
flake.nix
File metadata and controls
223 lines (188 loc) · 6.73 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
{
description = "Rostra";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils";
flakebox.url = "github:rustshop/flakebox?rev=9a9e59ca13f67a17f77addeebc054e3cdedfd179";
bundlers = {
url = "github:NixOS/bundlers";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
flakebox,
bundlers,
}:
{
bundlers = bundlers.bundlers;
}
// flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
projectName = "rostra";
flakeboxLib = flakebox.lib.mkLib pkgs {
config = {
github.ci.buildOutputs = [ ".#ci.${projectName}" ];
just.importPaths = [ "justfile.rostra.just" ];
just.rules.watch.enable = false;
toolchain.channel = "stable";
rust.rustfmt.enable = false;
};
};
toolchainArgs = {
# extraRustFlags = "-Z threads=0";
};
stdToolchains = (flakeboxLib.mkStdToolchains (toolchainArgs // { }));
toolchainAll = (
flakeboxLib.mkFenixToolchain (
toolchainArgs
// {
targets = pkgs.lib.getAttrs [ "default" ] (flakeboxLib.mkStdTargets { });
}
)
);
buildPaths = [
"Cargo.toml"
"Cargo.lock"
"crates"
"crates/.*"
".*/Cargo.toml"
".*\.rs"
];
buildSrc = flakeboxLib.filterSubPaths {
root = builtins.path {
name = projectName;
path = ./.;
};
paths = buildPaths;
};
multiBuild =
(flakeboxLib.craneMultiBuild {
toolchains = stdToolchains;
})
(
craneLib':
let
craneLib = (
craneLib'.overrideArgs {
pname = projectName;
src = buildSrc;
nativeBuildInputs = [ ];
}
);
in
rec {
workspaceDeps = craneLib.buildWorkspaceDepsOnly { };
workspace = craneLib.buildWorkspace {
cargoArtifacts = workspaceDeps;
};
rostraCoreFeatures = craneLib.mkCargoDerivation {
pname = "rostra-core-features";
cargoArtifacts = workspaceDeps;
installArtifacts = false;
buildPhaseCargoCommand = ''
for combo in \
"--no-default-features" \
"--no-default-features --features bincode" \
"--no-default-features --features ed25519-dalek" \
"--no-default-features --features serde" \
"--no-default-features --features ed25519-dalek,bincode" \
"--no-default-features --features ed25519-dalek,serde" \
"--no-default-features --features serde,bincode" \
"--no-default-features --features ed25519-dalek,serde,bincode" \
"--all-features" \
; do
>&2 echo "Checking rostra-core $combo ..."
cargo check --profile $CARGO_PROFILE --package rostra-core $combo
done
'';
};
tests = craneLib.cargoNextest {
cargoArtifacts = workspace;
};
clippy = craneLib.cargoClippy {
# must be deps, otherwise it will not rebuild
# anything and thus not detect anything
cargoArtifacts = workspaceDeps;
};
rostraDeps = craneLib.buildDepsOnly { };
rostra = craneLib.buildPackage {
meta.mainProgram = "rostra";
cargoArtifacts = rostraDeps;
preBuild = ''
export ROSTRA_SHARE_DIR=$out/share
'';
};
}
);
rostra-web-ui = pkgs.writeShellScriptBin "rostra-web-ui" ''
${multiBuild.rostra}/bin/rostra web-ui "$@"
'';
rostra-web-ui-tor = pkgs.writeShellScriptBin "rostra-web-ui-tor" ''
${rostra-tor}/bin/rostra-tor web-ui "$@"
'';
rostra-tor = pkgs.writeShellScriptBin "rostra-tor" ''
set -e
# Create temporary directory for Unix socket
rostra_tmpdir=$(mktemp --tmpdir --directory rostra-ui-XXXX)
export ROSTRA_LISTEN="''${rostra_tmpdir}/ui.sock"
# Separate cleanup functions
cleanup_tempdir() { rm -rf "''${rostra_tmpdir}" 2>/dev/null || true; }
trap cleanup_tempdir EXIT
# Start rostra web-ui with oniux (Tor proxy) in background
${pkgs.oniux}/bin/oniux ${multiBuild.rostra}/bin/rostra "$@" &
rostra_pid=$!
cleanup_rostra() { kill -9 "$rostra_pid" 2>/dev/null || true; }
trap cleanup_rostra EXIT
# Wait for Unix socket to be created
timeout=30
while [ $timeout -gt 0 ] && [ ! -S "''${ROSTRA_LISTEN}" ]; do
sleep 0.1
timeout=$((timeout - 1))
done
if [ ! -S "''${ROSTRA_LISTEN}" ]; then
echo "Error: Unix socket was not created within timeout"
exit 1
fi
# Find an available TCP port (starting from 3378)
tcp_port=3378
while ${pkgs.netcat}/bin/nc -z localhost $tcp_port 2>/dev/null; do
tcp_port=$((tcp_port + 1))
done
echo "Forwarding TCP port $tcp_port to Unix socket"
# Start socat to forward TCP to Unix socket
${pkgs.socat}/bin/socat TCP-LISTEN:$tcp_port,reuseaddr,fork UNIX-CONNECT:"''${ROSTRA_LISTEN}" &
socat_pid=$!
cleanup_socat() { kill -9 "$socat_pid" 2>/dev/null || true; }
trap cleanup_socat EXIT
# Give socat a moment to start
sleep .1
${pkgs.xdg-utils}/bin/xdg-open "http://127.0.0.1:$tcp_port" || {
echo "Failed to open browser. Please navigate to http://127.0.0.1:$tcp_port manually"
}
wait $rostra_pid
'';
in
{
packages = {
inherit rostra-web-ui rostra-tor rostra-web-ui-tor;
default = rostra-web-ui;
rostra = multiBuild.rostra;
};
legacyPackages = multiBuild;
devShells = flakeboxLib.mkShells {
toolchain = toolchainAll;
packages = with pkgs; [
jq
systemfd
cargo-mutants
];
};
}
);
}