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