-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
229 lines (199 loc) · 7.32 KB
/
Copy pathflake.nix
File metadata and controls
229 lines (199 loc) · 7.32 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
{
description = "automatic loudness and per-app volume control (pipewire)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs =
{
self,
nixpkgs,
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs systems;
pkgsFor =
system:
import nixpkgs {
inherit system;
};
perSystem =
system:
let
pkgs = pkgsFor system;
# native libs the audio crates link against
nativeAudioBuildInputs = with pkgs; [
pipewire
pipewire.dev
];
nativeBuildTools = with pkgs; [
pkg-config
clang
];
# system libs iced (wgpu/winit/cosmic-text) compiles + dlopens at runtime.
# wayland-only (x11 feature off); re-add libx11/libxcursor/libxi/libxrandr/libxcb if x11 re-enabled
guiLibs = with pkgs; [
vulkan-loader
libxkbcommon
wayland
libGL
fontconfig
];
commonEnv = {
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
PKG_CONFIG_PATH = "${pkgs.pipewire.dev}/lib/pkgconfig";
};
in
{
# nix develop — dev environment
devShell = pkgs.mkShell (
{
name = "headroom-dev";
nativeBuildInputs = nativeBuildTools ++ [
pkgs.cargo
pkgs.clippy
pkgs.rust-analyzer
pkgs.rustc
pkgs.rustfmt
];
buildInputs =
nativeAudioBuildInputs
++ guiLibs
++ (with pkgs; [
socat # poke the ipc socket
jq # pretty-print json
pipewire # pw-cli, pw-cat, etc.
wireplumber
]);
shellHook = ''
echo "headroom dev shell — rustc $(rustc --version | cut -d' ' -f2)"
echo " cargo build / cargo test for iteration."
echo " nix build .#headroom for the packaged binary."
echo " cargo run -p headroom-gui for the GUI (needs a display)."
export RUST_BACKTRACE=1
export RUST_LOG=headroom=debug,info
# iced/wgpu dlopen vulkan/wayland/xkbcommon at runtime
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath guiLibs}''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
'';
}
// commonEnv
);
# nix build — packaged daemon + cli
headroom = pkgs.rustPlatform.buildRustPackage (
{
pname = "headroom";
# workspace version (per-crate manifests use version.workspace = true)
version =
(builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version
+ "-"
+ (toString self.lastModifiedDate);
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
# allowBuiltinFetchGit = true;
};
nativeBuildInputs = nativeBuildTools;
buildInputs = nativeAudioBuildInputs;
# one binary: `headroom` (cli + daemon)
cargoBuildFlags = [
"-p"
"headroom-cli"
];
doCheck = true;
# exclude headroom-gui from the test sweep — pulls iced's gpu stack, not part of the daemon
cargoTestFlags = [
"--workspace"
"--exclude"
"headroom-gui"
];
# systemd user unit (@bindir@ templated to this derivation's bin, not PATH)
# + canonical profiles under share/headroom/profiles (daemon finds via $XDG_DATA_DIRS)
postInstall = ''
install -Dm644 contrib/systemd/headroom.service \
"$out/lib/systemd/user/headroom.service"
substituteInPlace "$out/lib/systemd/user/headroom.service" \
--replace-fail '@bindir@' "$out/bin"
mkdir -p "$out/share/headroom/profiles"
cp -r profiles/. "$out/share/headroom/profiles/"
'';
meta = with pkgs.lib; {
description = "automatic loudness and per-app volume control (pipewire)";
license = licenses.gpl3Plus;
platforms = platforms.linux;
mainProgram = "headroom";
};
}
// commonEnv
);
# `nix build .#headroom-gui` — optional iced GUI monitor.
# separate package so the default build stays graphics-free. iced/wgpu
# dlopen vulkan/libGL/wayland/xkbcommon at runtime → wrap with LD_LIBRARY_PATH.
# also ships the .desktop entry.
headroom-gui = pkgs.rustPlatform.buildRustPackage (
{
pname = "headroom-gui";
version =
(builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version
+ "-"
+ (toString self.lastModifiedDate);
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
# makeWrapper for the LD_LIBRARY_PATH wrap. gui doesn't link pipewire
# (talks to the daemon over the socket via headroom-client) → no pipewire/clang
nativeBuildInputs = [
pkgs.pkg-config
pkgs.makeWrapper
];
buildInputs = guiLibs;
cargoBuildFlags = [
"-p"
"headroom-gui"
];
# gui tests drive iced view/update; no display in the sandbox.
# run them via `cargo test -p headroom-gui` in the dev shell instead
doCheck = false;
postInstall = ''
install -Dm644 contrib/desktop/headroom-gui.desktop \
"$out/share/applications/headroom-gui.desktop"
substituteInPlace "$out/share/applications/headroom-gui.desktop" \
--replace-fail '@bindir@' "$out/bin"
'';
postFixup = ''
wrapProgram "$out/bin/headroom-gui" \
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath guiLibs}"
'';
meta = with pkgs.lib; {
description = "automatic loudness and per-app volume control (pipewire)";
license = licenses.eupl12;
platforms = platforms.linux;
mainProgram = "headroom-gui";
};
}
// commonEnv
);
};
in
{
devShells = forAllSystems (system: {
default = (perSystem system).devShell;
});
packages = forAllSystems (
system:
let
ps = perSystem system;
in
rec {
default = headroom;
headroom = ps.headroom;
headroom-gui = ps.headroom-gui;
}
);
formatter = forAllSystems (system: (pkgsFor system).nixpkgs-fmt);
# System-independent outputs — modules.
nixosModules.default = import ./nix/nixos-module.nix self;
};
}