forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBb0eb8adIvan Molodetskikh3 months ago2857 commits

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