forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9ff2f83Ivan Molodetskikh1 year ago2099 commits

flake.nix261 lines, 7.7 KiBHistoryRawDownload
1# This flake file is community maintained
2{
3 description = "Niri: A scrollable-tiling Wayland compositor.";
4
5 inputs = {
6 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
7 nix-filter.url = "github:numtide/nix-filter";
8
9 # NOTE: This is not necessary for end users
10 # You can omit it with `inputs.rust-overlay.follows = ""`
11 rust-overlay = {
12 url = "github:oxalica/rust-overlay";
13 inputs.nixpkgs.follows = "nixpkgs";
14 };
15 };
16
17 outputs =
18 {
19 self,
20 nixpkgs,
21 nix-filter,
22 rust-overlay,
23 }:
24 let
25 niri-package =
26 {
27 lib,
28 cairo,
29 dbus,
30 libGL,
31 libdisplay-info,
32 libinput,
33 seatd,
34 libxkbcommon,
35 libgbm,
36 pango,
37 pipewire,
38 pkg-config,
39 rustPlatform,
40 systemd,
41 wayland,
42 installShellFiles,
43 withDbus ? true,
44 withSystemd ? true,
45 withScreencastSupport ? true,
46 withDinit ? false,
47 }:
48
49 rustPlatform.buildRustPackage {
50 pname = "niri";
51 version = self.shortRev or self.dirtyShortRev or "unknown";
52
53 src = nix-filter.lib.filter {
54 root = self;
55 include = [
56 "niri-config"
57 "niri-ipc"
58 "niri-visual-tests"
59 "resources"
60 "src"
61 ./Cargo.lock
62 ./Cargo.toml
63 ];
64 };
65
66 postPatch = ''
67 patchShebangs resources/niri-session
68 substituteInPlace resources/niri.service \
69 --replace-fail '/usr/bin' "$out/bin"
70 '';
71
72 cargoLock = {
73 # NOTE: This is only used for Git dependencies
74 allowBuiltinFetchGit = true;
75 lockFile = ./Cargo.lock;
76 };
77
78 strictDeps = true;
79
80 nativeBuildInputs = [
81 rustPlatform.bindgenHook
82 pkg-config
83 installShellFiles
84 ];
85
86 buildInputs =
87 [
88 cairo
89 dbus
90 libGL
91 libdisplay-info
92 libinput
93 seatd
94 libxkbcommon
95 libgbm
96 pango
97 wayland
98 ]
99 ++ lib.optional (withDbus || withScreencastSupport || withSystemd) dbus
100 ++ lib.optional withScreencastSupport pipewire
101 # Also includes libudev
102 ++ lib.optional withSystemd systemd;
103
104 buildFeatures =
105 lib.optional withDbus "dbus"
106 ++ lib.optional withDinit "dinit"
107 ++ lib.optional withScreencastSupport "xdp-gnome-screencast"
108 ++ lib.optional withSystemd "systemd";
109 buildNoDefaultFeatures = true;
110
111 # ever since this commit:
112 # https://github.com/YaLTeR/niri/commit/771ea1e81557ffe7af9cbdbec161601575b64d81
113 # niri now runs an actual instance of the real compositor (with a mock backend) during tests
114 # and thus creates a real socket file in the runtime dir.
115 # this is fine for our build, we just need to make sure it has a directory to write to.
116 preCheck = ''
117 export XDG_RUNTIME_DIR="$(mktemp -d)"
118 '';
119
120 postInstall =
121 ''
122 installShellCompletion --cmd niri \
123 --bash <($out/bin/niri completions bash) \
124 --fish <($out/bin/niri completions fish) \
125 --zsh <($out/bin/niri completions zsh)
126
127 install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions
128 install -Dm644 resources/niri-portals.conf -t $out/share/xdg-desktop-portal
129 ''
130 + lib.optionalString withSystemd ''
131 install -Dm755 resources/niri-session $out/bin/niri-session
132 install -Dm644 resources/niri{.service,-shutdown.target} -t $out/share/systemd/user
133 '';
134
135 env = {
136 # Force linking with libEGL and libwayland-client
137 # so they can be discovered by `dlopen()`
138 RUSTFLAGS = toString (
139 map (arg: "-C link-arg=" + arg) [
140 "-Wl,--push-state,--no-as-needed"
141 "-lEGL"
142 "-lwayland-client"
143 "-Wl,--pop-state"
144 ]
145 );
146 };
147
148 passthru = {
149 providedSessions = [ "niri" ];
150 };
151
152 meta = {
153 description = "Scrollable-tiling Wayland compositor";
154 homepage = "https://github.com/YaLTeR/niri";
155 license = lib.licenses.gpl3Only;
156 mainProgram = "niri";
157 platforms = lib.platforms.linux;
158 };
159 };
160
161 inherit (nixpkgs) lib;
162 # Support all Linux systems that the nixpkgs flake exposes
163 systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux;
164
165 forAllSystems = lib.genAttrs systems;
166 nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
167 in
168 {
169 checks = forAllSystems (system: {
170 # We use the debug build here to save a bit of time
171 inherit (self.packages.${system}) niri-debug;
172 });
173
174 devShells = forAllSystems (
175 system:
176 let
177 pkgs = nixpkgsFor.${system};
178 rust-bin = rust-overlay.lib.mkRustBin { } pkgs;
179 inherit (self.packages.${system}) niri;
180 in
181 {
182 default = pkgs.mkShell {
183 packages = [
184 # We don't use the toolchain from nixpkgs
185 # because we prefer a nightly toolchain
186 # and we *require* a nightly rustfmt
187 (rust-bin.selectLatestNightlyWith (
188 toolchain:
189 toolchain.default.override {
190 extensions = [
191 # includes already:
192 # rustc
193 # cargo
194 # rust-std
195 # rust-docs
196 # rustfmt-preview
197 # clippy-preview
198 "rust-analyzer"
199 "rust-src"
200 ];
201 }
202 ))
203 ];
204
205 nativeBuildInputs = [
206 pkgs.rustPlatform.bindgenHook
207 pkgs.pkg-config
208 pkgs.wrapGAppsHook4 # For `niri-visual-tests`
209 ];
210
211 buildInputs = niri.buildInputs ++ [
212 pkgs.libadwaita # For `niri-visual-tests`
213 ];
214
215 env = {
216 # WARN: Do not overwrite this variable in your shell!
217 # It is required for `dlopen()` to work on some libraries; see the comment
218 # in the package expression
219 #
220 # This should only be set with `CARGO_BUILD_RUSTFLAGS="$CARGO_BUILD_RUSTFLAGS -C your-flags"`
221 CARGO_BUILD_RUSTFLAGS = niri.RUSTFLAGS;
222 };
223 };
224 }
225 );
226
227 formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);
228
229 packages = forAllSystems (
230 system:
231 let
232 niri = nixpkgsFor.${system}.callPackage niri-package { };
233 in
234 {
235 inherit niri;
236
237 # NOTE: This is for development purposes only
238 #
239 # It is primarily to help with quickly iterating on
240 # changes made to the above expression - though it is
241 # also not stripped in order to better debug niri itself
242 niri-debug = niri.overrideAttrs (
243 newAttrs: oldAttrs: {
244 pname = oldAttrs.pname + "-debug";
245
246 cargoBuildType = "debug";
247 cargoCheckType = newAttrs.cargoBuildType;
248
249 dontStrip = true;
250 }
251 );
252
253 default = niri;
254 }
255 );
256
257 overlays.default = final: _: {
258 niri = final.callPackage niri-package { };
259 };
260 };
261}