-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
209 lines (190 loc) · 7.41 KB
/
Copy pathflake.nix
File metadata and controls
209 lines (190 loc) · 7.41 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
{
description = "ringo — terminal SIP softphone (ringo-phone) and scenario runner (ringo-flow)";
# Building ringo means compiling OpenSSL, libre and libbaresip before the Rust
# code — ten minutes or so, more on a small machine. This cache holds the
# result for every platform below, filled from the default branch by
# .github/workflows/nix-cache.yml.
#
# Nix honours these only for a trusted user; everyone else is asked once, or
# sees the settings ignored with a warning. `cachix use ringo` (or
# nix.settings on NixOS) is the reliable route — see the docs.
nixConfig = {
extra-substituters = [ "https://ringo.cachix.org" ];
extra-trusted-public-keys = [
"ringo.cachix.org-1:Zfdjuf1dHz+C0a4BOKfPbBOxTcHmKy3c2Ddr0tUiawk="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# libre + libbaresip are git submodules of ringo-core (see .gitmodules).
# Flake sources do not carry submodules, so we pin the same upstream release
# tags here and copy them into crates/ringo-core/vendor/ before the build.
# Keep these tags in sync with `branch = ` in .gitmodules (and re-run
# `nix flake update re baresip` after bumping).
re = {
url = "github:baresip/re/v4.11.0";
flake = false;
};
baresip = {
url = "github:baresip/baresip/v4.11.0";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
re,
baresip,
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
# Apple Silicon only; nixpkgs-unstable dropped x86_64-darwin (Intel).
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs systems;
pkgsFor = system: nixpkgs.legacyPackages.${system};
# Shared derivation builder. `crate` is the workspace member / cargo
# package; `bin` is the produced executable; `audio` toggles the
# default-audio (PulseAudio) backend — on for the phone, off (headless
# aubridge) for flow. `icon` (optional) is installed into hicolor under
# the binary's name, so desktop entries can reference it.
mkRingo =
{
pkgs,
crate,
bin,
audio,
icon ? null,
}:
let
lib = pkgs.lib;
cargoToml = lib.importTOML (./crates + "/${crate}/Cargo.toml");
in
pkgs.rustPlatform.buildRustPackage {
pname = crate;
version = cargoToml.package.version;
src = self;
cargoLock.lockFile = ./Cargo.lock;
# Inject the vendored C sources (git submodules) that the flake
# source does not include.
postPatch = ''
mkdir -p crates/ringo-core/vendor
rm -rf crates/ringo-core/vendor/re crates/ringo-core/vendor/baresip
cp -r --no-preserve=mode,ownership ${re} crates/ringo-core/vendor/re
cp -r --no-preserve=mode,ownership ${baresip} crates/ringo-core/vendor/baresip
'';
nativeBuildInputs = [
pkgs.cmake # builds libre + libbaresip
pkgs.pkg-config # locates opus/spandsp/libpulse
pkgs.perl # openssl-sys vendored build
pkgs.rustPlatform.bindgenHook # sets LIBCLANG_PATH + clang headers for bindgen
pkgs.installShellFiles # ship shell completions
];
# Dynamically linked libs — placed in buildInputs so the nix
# cc-wrapper adds their store paths to the binary's RPATH. OpenSSL is
# vendored (statically linked), so it is intentionally absent here.
#
# Audio backend for the phone (`audio = true`): PulseAudio on Linux
# (build.rs auto-detects it via pkg-config), CoreAudio on macOS. The
# macOS CoreAudio/AudioToolbox/SystemConfiguration frameworks come
# from the Apple SDK in the darwin stdenv — no derivation needed.
buildInputs =
[
pkgs.opus
pkgs.spandsp
pkgs.zlib
]
++ lib.optional (audio && pkgs.stdenv.isLinux) pkgs.libpulseaudio;
# cmake is only used by build.rs to compile the vendored C libs; the
# setup hook's configure/build phases would fight cargo, so disable it.
dontUseCmakeConfigure = true;
cargoBuildFlags = [
"-p"
crate
];
# Headless build for ringo-flow: no default-audio feature.
buildNoDefaultFeatures = !audio;
# The test suites are not part of the install artifact and some need a
# SIP peer / audio device; build the binary only.
doCheck = false;
# Install the icon and generate + install shell completions from the
# built binary (clap's COMPLETE=<shell> emits the script). The icon is
# unconditional (a file copy, works on cross builds); completions need
# to execute the binary, so they are skipped on cross builds.
postInstall =
lib.optionalString (icon != null) ''
install -Dm644 ${icon} $out/share/icons/hicolor/scalable/apps/${bin}.svg
''
+ lib.optionalString (pkgs.stdenv.buildPlatform.canExecute pkgs.stdenv.hostPlatform) ''
installShellCompletion --cmd ${bin} \
--fish <(COMPLETE=fish $out/bin/${bin}) \
--bash <(COMPLETE=bash $out/bin/${bin}) \
--zsh <(COMPLETE=zsh $out/bin/${bin})
'';
meta = {
inherit (cargoToml.package) description;
homepage = "https://github.com/davidborzek/ringo";
license = lib.licenses.mit;
mainProgram = bin;
platforms = systems;
};
};
in
{
packages = forAllSystems (
system:
let
pkgs = pkgsFor system;
in
rec {
ringo-phone = mkRingo {
inherit pkgs;
crate = "ringo-phone";
bin = "ringo";
audio = true;
# The docs logo doubles as the application icon; the Home-Manager
# module's desktop entry points at the installed store path.
icon = ./docs/src/logo.svg;
};
ringo-flow = mkRingo {
inherit pkgs;
crate = "ringo-flow";
bin = "ringo-flow";
audio = false;
};
default = ringo-phone;
}
);
devShells = forAllSystems (
system:
let
pkgs = pkgsFor system;
in
{
# Inherit the full build environment (cmake, pkg-config, perl, bindgen,
# opus, spandsp, zlib, libpulseaudio, cargo, rustc) from the package so
# the shell can never drift from the actual build.
default = pkgs.mkShell {
inputsFrom = [ self.packages.${system}.ringo-phone ];
packages = with pkgs; [ rustfmt clippy rust-analyzer ];
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
};
}
);
overlays.default = final: _prev: {
ringo-phone = self.packages.${final.stdenv.hostPlatform.system}.ringo-phone;
ringo-flow = self.packages.${final.stdenv.hostPlatform.system}.ringo-flow;
};
nixosModules = rec {
ringo-flow = import ./nix/nixos-ringo-flow.nix { inherit self; };
default = ringo-flow;
};
homeManagerModules = rec {
ringo = import ./nix/hm-ringo.nix { inherit self; };
default = ringo;
};
};
}