forge
Explore
Log in

Don't you dare go Hollow

flake: improve packaging

Browse files at this commit

b258fd69d23fe7acbbfbd522f974d39deef78984sethParent: 3ab3e77
Some highlights include:

- Removing some unnecessary dependencies of the package itself
- Allowing for overriding the package
- Adding Cargo feature toggles
- Installing all niri-related resources
- Avoiding `LD_LIBRARY_PATH` hacks
flake.nixmodified+158 -95
@@ -12,21 +12,19 @@
12 self,12 self,
13 nixpkgs,13 nixpkgs,
14 nix-filter,14 nix-filter,
15- ...
16 }:15 }:
17 let16 let
18 inherit (nixpkgs) lib;17 inherit (nixpkgs) lib;
19- systems = [18+ # Support all Linux systems that the nixpkgs flake exposes
20- "aarch64-linux"19+ systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux;
21- "x86_64-linux"
22- ];
23 20
24 forAllSystems = lib.genAttrs systems;21 forAllSystems = lib.genAttrs systems;
25 nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});22 nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
26 in23 in
27 {24 {
28 checks = forAllSystems (system: {25 checks = forAllSystems (system: {
29- inherit (self.packages.${system}) niri;26+ # We use the debug build here to save a bit of time
27+ inherit (self.packages.${system}) niri-debug;
30 });28 });
31 29
32 devShells = forAllSystems (30 devShells = forAllSystems (
@@ -39,8 +37,14 @@
39 inputsFrom = [ niri ];37 inputsFrom = [ niri ];
40 38
41 env = {39 env = {
42- LD_LIBRARY_PATH = lib.makeLibraryPath niri.buildInputs;40+ inherit (niri) LIBCLANG_PATH;
43- inherit (niri.env) LIBCLANG_PATH;41+
42+ # WARN: Do not overwrite this variable in your shell!
43+ # It is required for `dlopen()` to work on some libraries; see the comment
44+ # in the package expression
45+ #
46+ # This should only be set with `CARGO_BUILD_RUSTFLAGS="$CARGO_BUILD_RUSTFLAGS -C your-flags"`
47+ inherit (niri) CARGO_BUILD_RUSTFLAGS;
44 };48 };
45 };49 };
46 }50 }
@@ -48,95 +52,154 @@
48 52
49 formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);53 formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);
50 54
51- packages = forAllSystems (system: {55+ packages = forAllSystems (
52- niri = nixpkgsFor.${system}.callPackage (56+ system:
53- {57+ let
54- cairo,58+ inherit (self.packages.${system}) niri;
55- clang,59+ in
56- fontconfig,60+ {
57- gdk-pixbuf,61+ niri = nixpkgsFor.${system}.callPackage (
58- glib,62+ {
59- graphene,63+ cairo,
60- gtk4,64+ clang,
61- libadwaita,65+ dbus,
62- libclang,66+ libGL,
63- libdisplay-info,67+ libclang,
64- libglvnd,68+ libdisplay-info,
65- libinput,69+ libinput,
66- libxkbcommon,70+ libseat,
67- mesa,71+ libxkbcommon,
68- pango,72+ mesa,
69- pipewire,73+ pango,
70- pixman,74+ pipewire,
71- pkg-config,75+ pkg-config,
72- rustPlatform,76+ rustPlatform,
73- seatd,77+ systemd,
74- stdenv,78+ wayland,
75- systemd,79+ withDbus ? true,
76- wayland,80+ withSystemd ? true,
77- xorg,81+ withScreencastSupport ? true,
78- }:82+ withDinit ? false,
79- rustPlatform.buildRustPackage rec {83+ }:
80- pname = "niri";
81- version = self.shortRev or self.dirtyShortRev or "unknown";
82-
83- cargoLock = {
84- # NOTE: This is only used for Git dependencies
85- allowBuiltinFetchGit = true;
86- lockFile = ./Cargo.lock;
87- };
88 84
89- src = nix-filter.lib.filter {85+ rustPlatform.buildRustPackage {
90- root = self;86+ pname = "niri";
91- include = [87+ version = self.shortRev or self.dirtyShortRev or "unknown";
92- "niri-config"88+
93- "niri-ipc"89+ src = nix-filter.lib.filter {
94- "resources"90+ root = self;
95- "src"91+ include = [
92+ "niri-config"
93+ "niri-ipc"
94+ "niri-visual-tests"
95+ "resources"
96+ "src"
97+ ./Cargo.lock
98+ ./Cargo.toml
99+ ];
100+ };
101+
102+ postPatch = ''
103+ patchShebangs resources/niri-session
104+ substituteInPlace resources/niri.service \
105+ --replace-fail '/usr/bin' "$out/bin"
106+ '';
107+
108+ cargoLock = {
109+ # NOTE: This is only used for Git dependencies
110+ allowBuiltinFetchGit = true;
111+ lockFile = ./Cargo.lock;
112+ };
113+
114+ strictDeps = true;
115+
116+ nativeBuildInputs = [
117+ clang
118+ pkg-config
96 ];119 ];
97- };
98 120
99- nativeBuildInputs = [121+ buildInputs =
100- clang122+ [
101- gdk-pixbuf123+ cairo
102- graphene124+ dbus
103- gtk4125+ libGL
104- libadwaita126+ libdisplay-info
105- pkg-config127+ libinput
106- ];128+ libseat
107-129+ libxkbcommon
108- buildInputs = [130+ mesa # libgbm
109- cairo131+ pango
110- fontconfig132+ wayland
111- glib133+ ]
112- libdisplay-info134+ ++ lib.optional (withDbus || withScreencastSupport || withSystemd) dbus
113- libinput135+ ++ lib.optional withScreencastSupport pipewire
114- libxkbcommon136+ # Also includes libudev
115- mesa # For libgbm137+ ++ lib.optional withSystemd systemd;
116- pango138+
117- pipewire139+ buildFeatures =
118- pixman140+ lib.optional withDbus "dbus"
119- seatd # For libseat141+ ++ lib.optional withDinit "dinit"
120- stdenv.cc.cc.lib142+ ++ lib.optional withScreencastSupport "xdp-gnome-screencast"
121- systemd # For libudev143+ ++ lib.optional withSystemd "systemd";
122- wayland144+ buildNoDefaultFeatures = true;
123- ];145+
124-146+ postInstall =
125- runtimeDependencies = [147+ ''
126- libglvnd # For libEGL148+ install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions
127- libxkbcommon149+ install -Dm644 resources/niri-portals.conf -t $out/share/xdg-desktop-portal
128- mesa150+ ''
129- wayland151+ + lib.optionalString withSystemd ''
130- xorg.libXcursor152+ install -Dm755 resources/niri-session $out/bin/niri-session
131- xorg.libXi153+ install -Dm644 resources/niri{.service,-shutdown.target} -t $out/share/systemd/user
132- ];154+ '';
133-155+
134- LD_LIBRARY_PATH = lib.makeLibraryPath runtimeDependencies;156+ env = {
135- LIBCLANG_PATH = lib.getLib libclang + "/lib";157+ LIBCLANG_PATH = lib.getLib libclang + "/lib";
136- }158+
137- ) { };159+ # Force linking with libEGL and libwayland-client
138-160+ # so they can be discovered by `dlopen()`
139- default = self.packages.${system}.niri;161+ CARGO_BUILD_RUSTFLAGS = toString (
140- });162+ map (arg: "-C link-arg=" + arg) [
163+ "-Wl,--push-state,--no-as-needed"
164+ "-lEGL"
165+ "-lwayland-client"
166+ "-Wl,--pop-state"
167+ ]
168+ );
169+ };
170+
171+ passthru = {
172+ providedSessions = [ "niri" ];
173+ };
174+
175+ meta = {
176+ description = "Scrollable-tiling Wayland compositor";
177+ homepage = "https://github.com/YaLTeR/niri";
178+ license = lib.licenses.gpl3Only;
179+ mainProgram = "niri";
180+ platforms = lib.platforms.linux;
181+ };
182+ }
183+ ) { };
184+
185+ # NOTE: This is for development purposes only
186+ #
187+ # It is primarily to help with quickly iterating on
188+ # changes made to the above expression - though it is
189+ # also not stripped in order to better debug niri itself
190+ niri-debug = niri.overrideAttrs (
191+ newAttrs: oldAttrs: {
192+ pname = oldAttrs.pname + "-debug";
193+
194+ cargoBuildType = "debug";
195+ cargoCheckType = newAttrs.cargoBuildType;
196+
197+ dontStrip = true;
198+ }
199+ );
200+
201+ default = niri;
202+ }
203+ );
141 };204 };
142 }205 }