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