flake: use nightly rust-analyzer and add rust-src component (#735)
Browse files at this commit1 changed file +146 -130
- flake.nix +146 -130
flake.nixmodified+146 -130
| @@ -22,6 +22,130 @@ | |||
| 22 | rust-overlay, | 22 | rust-overlay, |
| 23 | }: | 23 | }: |
| 24 | let | 24 | let |
| 25 | + niri-package = | ||
| 26 | + { | ||
| 27 | + lib, | ||
| 28 | + cairo, | ||
| 29 | + clang, | ||
| 30 | + dbus, | ||
| 31 | + libGL, | ||
| 32 | + libclang, | ||
| 33 | + libdisplay-info, | ||
| 34 | + libinput, | ||
| 35 | + libseat, | ||
| 36 | + libxkbcommon, | ||
| 37 | + mesa, | ||
| 38 | + pango, | ||
| 39 | + pipewire, | ||
| 40 | + pkg-config, | ||
| 41 | + rustPlatform, | ||
| 42 | + systemd, | ||
| 43 | + wayland, | ||
| 44 | + withDbus ? true, | ||
| 45 | + withSystemd ? true, | ||
| 46 | + withScreencastSupport ? true, | ||
| 47 | + withDinit ? false, | ||
| 48 | + }: | ||
| 49 | + | ||
| 50 | + rustPlatform.buildRustPackage { | ||
| 51 | + pname = "niri"; | ||
| 52 | + version = self.shortRev or self.dirtyShortRev or "unknown"; | ||
| 53 | + | ||
| 54 | + src = nix-filter.lib.filter { | ||
| 55 | + root = self; | ||
| 56 | + include = [ | ||
| 57 | + "niri-config" | ||
| 58 | + "niri-ipc" | ||
| 59 | + "niri-visual-tests" | ||
| 60 | + "resources" | ||
| 61 | + "src" | ||
| 62 | + ./Cargo.lock | ||
| 63 | + ./Cargo.toml | ||
| 64 | + ]; | ||
| 65 | + }; | ||
| 66 | + | ||
| 67 | + postPatch = '' | ||
| 68 | + patchShebangs resources/niri-session | ||
| 69 | + substituteInPlace resources/niri.service \ | ||
| 70 | + --replace-fail '/usr/bin' "$out/bin" | ||
| 71 | + ''; | ||
| 72 | + | ||
| 73 | + cargoLock = { | ||
| 74 | + # NOTE: This is only used for Git dependencies | ||
| 75 | + allowBuiltinFetchGit = true; | ||
| 76 | + lockFile = ./Cargo.lock; | ||
| 77 | + }; | ||
| 78 | + | ||
| 79 | + strictDeps = true; | ||
| 80 | + | ||
| 81 | + nativeBuildInputs = [ | ||
| 82 | + clang | ||
| 83 | + pkg-config | ||
| 84 | + ]; | ||
| 85 | + | ||
| 86 | + buildInputs = | ||
| 87 | + [ | ||
| 88 | + cairo | ||
| 89 | + dbus | ||
| 90 | + libGL | ||
| 91 | + libdisplay-info | ||
| 92 | + libinput | ||
| 93 | + libseat | ||
| 94 | + libxkbcommon | ||
| 95 | + mesa # 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 | + postInstall = | ||
| 112 | + '' | ||
| 113 | + install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions | ||
| 114 | + install -Dm644 resources/niri-portals.conf -t $out/share/xdg-desktop-portal | ||
| 115 | + '' | ||
| 116 | + + lib.optionalString withSystemd '' | ||
| 117 | + install -Dm755 resources/niri-session $out/bin/niri-session | ||
| 118 | + install -Dm644 resources/niri{.service,-shutdown.target} -t $out/share/systemd/user | ||
| 119 | + ''; | ||
| 120 | + | ||
| 121 | + env = { | ||
| 122 | + LIBCLANG_PATH = lib.getLib libclang + "/lib"; | ||
| 123 | + | ||
| 124 | + # Force linking with libEGL and libwayland-client | ||
| 125 | + # so they can be discovered by `dlopen()` | ||
| 126 | + CARGO_BUILD_RUSTFLAGS = toString ( | ||
| 127 | + map (arg: "-C link-arg=" + arg) [ | ||
| 128 | + "-Wl,--push-state,--no-as-needed" | ||
| 129 | + "-lEGL" | ||
| 130 | + "-lwayland-client" | ||
| 131 | + "-Wl,--pop-state" | ||
| 132 | + ] | ||
| 133 | + ); | ||
| 134 | + }; | ||
| 135 | + | ||
| 136 | + passthru = { | ||
| 137 | + providedSessions = [ "niri" ]; | ||
| 138 | + }; | ||
| 139 | + | ||
| 140 | + meta = { | ||
| 141 | + description = "Scrollable-tiling Wayland compositor"; | ||
| 142 | + homepage = "https://github.com/YaLTeR/niri"; | ||
| 143 | + license = lib.licenses.gpl3Only; | ||
| 144 | + mainProgram = "niri"; | ||
| 145 | + platforms = lib.platforms.linux; | ||
| 146 | + }; | ||
| 147 | + }; | ||
| 148 | + | ||
| 25 | inherit (nixpkgs) lib; | 149 | inherit (nixpkgs) lib; |
| 26 | # Support all Linux systems that the nixpkgs flake exposes | 150 | # Support all Linux systems that the nixpkgs flake exposes |
| 27 | systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux; | 151 | systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux; |
| @@ -39,17 +163,31 @@ | |||
| 39 | system: | 163 | system: |
| 40 | let | 164 | let |
| 41 | pkgs = nixpkgsFor.${system}; | 165 | pkgs = nixpkgsFor.${system}; |
| 166 | + rust-bin = rust-overlay.lib.mkRustBin { } pkgs; | ||
| 42 | inherit (self.packages.${system}) niri; | 167 | inherit (self.packages.${system}) niri; |
| 43 | in | 168 | in |
| 44 | { | 169 | { |
| 45 | default = pkgs.mkShell { | 170 | default = pkgs.mkShell { |
| 46 | packages = [ | 171 | packages = [ |
| 47 | - # NOTE: Nixpkgs' Rust toolchain isn't used here as we prefer | 172 | + # We don't use the toolchain from nixpkgs |
| 48 | - # a nightly toolchain for development, and *require* a nightly | 173 | + # because we prefer a nightly toolchain |
| 49 | - # `rustfmt` | 174 | + # and we *require* a nightly rustfmt |
| 50 | - rust-overlay.packages.${system}.rust-nightly | 175 | + (rust-bin.selectLatestNightlyWith ( |
| 51 | - | 176 | + toolchain: |
| 52 | - pkgs.rust-analyzer | 177 | + toolchain.default.override { |
| 178 | + extensions = [ | ||
| 179 | + # includes already: | ||
| 180 | + # rustc | ||
| 181 | + # cargo | ||
| 182 | + # rust-std | ||
| 183 | + # rust-docs | ||
| 184 | + # rustfmt-preview | ||
| 185 | + # clippy-preview | ||
| 186 | + "rust-analyzer" | ||
| 187 | + "rust-src" | ||
| 188 | + ]; | ||
| 189 | + } | ||
| 190 | + )) | ||
| 53 | ]; | 191 | ]; |
| 54 | 192 | ||
| 55 | nativeBuildInputs = [ | 193 | nativeBuildInputs = [ |
| @@ -81,7 +219,7 @@ | |||
| 81 | packages = forAllSystems ( | 219 | packages = forAllSystems ( |
| 82 | system: | 220 | system: |
| 83 | let | 221 | let |
| 84 | - inherit (self.overlays.default nixpkgsFor.${system} null) niri; | 222 | + niri = nixpkgsFor.${system}.callPackage niri-package { }; |
| 85 | in | 223 | in |
| 86 | { | 224 | { |
| 87 | inherit niri; | 225 | inherit niri; |
| @@ -107,129 +245,7 @@ | |||
| 107 | ); | 245 | ); |
| 108 | 246 | ||
| 109 | overlays.default = final: _: { | 247 | overlays.default = final: _: { |
| 110 | - niri = final.callPackage ( | 248 | + niri = final.callPackage niri-package { }; |
| 111 | - { | ||
| 112 | - cairo, | ||
| 113 | - clang, | ||
| 114 | - dbus, | ||
| 115 | - libGL, | ||
| 116 | - libclang, | ||
| 117 | - libdisplay-info, | ||
| 118 | - libinput, | ||
| 119 | - libseat, | ||
| 120 | - libxkbcommon, | ||
| 121 | - mesa, | ||
| 122 | - pango, | ||
| 123 | - pipewire, | ||
| 124 | - pkg-config, | ||
| 125 | - rustPlatform, | ||
| 126 | - systemd, | ||
| 127 | - wayland, | ||
| 128 | - withDbus ? true, | ||
| 129 | - withSystemd ? true, | ||
| 130 | - withScreencastSupport ? true, | ||
| 131 | - withDinit ? false, | ||
| 132 | - }: | ||
| 133 | - | ||
| 134 | - rustPlatform.buildRustPackage { | ||
| 135 | - pname = "niri"; | ||
| 136 | - version = self.shortRev or self.dirtyShortRev or "unknown"; | ||
| 137 | - | ||
| 138 | - src = nix-filter.lib.filter { | ||
| 139 | - root = self; | ||
| 140 | - include = [ | ||
| 141 | - "niri-config" | ||
| 142 | - "niri-ipc" | ||
| 143 | - "niri-visual-tests" | ||
| 144 | - "resources" | ||
| 145 | - "src" | ||
| 146 | - ./Cargo.lock | ||
| 147 | - ./Cargo.toml | ||
| 148 | - ]; | ||
| 149 | - }; | ||
| 150 | - | ||
| 151 | - postPatch = '' | ||
| 152 | - patchShebangs resources/niri-session | ||
| 153 | - substituteInPlace resources/niri.service \ | ||
| 154 | - --replace-fail '/usr/bin' "$out/bin" | ||
| 155 | - ''; | ||
| 156 | - | ||
| 157 | - cargoLock = { | ||
| 158 | - # NOTE: This is only used for Git dependencies | ||
| 159 | - allowBuiltinFetchGit = true; | ||
| 160 | - lockFile = ./Cargo.lock; | ||
| 161 | - }; | ||
| 162 | - | ||
| 163 | - strictDeps = true; | ||
| 164 | - | ||
| 165 | - nativeBuildInputs = [ | ||
| 166 | - clang | ||
| 167 | - pkg-config | ||
| 168 | - ]; | ||
| 169 | - | ||
| 170 | - buildInputs = | ||
| 171 | - [ | ||
| 172 | - cairo | ||
| 173 | - dbus | ||
| 174 | - libGL | ||
| 175 | - libdisplay-info | ||
| 176 | - libinput | ||
| 177 | - libseat | ||
| 178 | - libxkbcommon | ||
| 179 | - mesa # libgbm | ||
| 180 | - pango | ||
| 181 | - wayland | ||
| 182 | - ] | ||
| 183 | - ++ lib.optional (withDbus || withScreencastSupport || withSystemd) dbus | ||
| 184 | - ++ lib.optional withScreencastSupport pipewire | ||
| 185 | - # Also includes libudev | ||
| 186 | - ++ lib.optional withSystemd systemd; | ||
| 187 | - | ||
| 188 | - buildFeatures = | ||
| 189 | - lib.optional withDbus "dbus" | ||
| 190 | - ++ lib.optional withDinit "dinit" | ||
| 191 | - ++ lib.optional withScreencastSupport "xdp-gnome-screencast" | ||
| 192 | - ++ lib.optional withSystemd "systemd"; | ||
| 193 | - buildNoDefaultFeatures = true; | ||
| 194 | - | ||
| 195 | - postInstall = | ||
| 196 | - '' | ||
| 197 | - install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions | ||
| 198 | - install -Dm644 resources/niri-portals.conf -t $out/share/xdg-desktop-portal | ||
| 199 | - '' | ||
| 200 | - + lib.optionalString withSystemd '' | ||
| 201 | - install -Dm755 resources/niri-session $out/bin/niri-session | ||
| 202 | - install -Dm644 resources/niri{.service,-shutdown.target} -t $out/share/systemd/user | ||
| 203 | - ''; | ||
| 204 | - | ||
| 205 | - env = { | ||
| 206 | - LIBCLANG_PATH = lib.getLib libclang + "/lib"; | ||
| 207 | - | ||
| 208 | - # Force linking with libEGL and libwayland-client | ||
| 209 | - # so they can be discovered by `dlopen()` | ||
| 210 | - CARGO_BUILD_RUSTFLAGS = toString ( | ||
| 211 | - map (arg: "-C link-arg=" + arg) [ | ||
| 212 | - "-Wl,--push-state,--no-as-needed" | ||
| 213 | - "-lEGL" | ||
| 214 | - "-lwayland-client" | ||
| 215 | - "-Wl,--pop-state" | ||
| 216 | - ] | ||
| 217 | - ); | ||
| 218 | - }; | ||
| 219 | - | ||
| 220 | - passthru = { | ||
| 221 | - providedSessions = [ "niri" ]; | ||
| 222 | - }; | ||
| 223 | - | ||
| 224 | - meta = { | ||
| 225 | - description = "Scrollable-tiling Wayland compositor"; | ||
| 226 | - homepage = "https://github.com/YaLTeR/niri"; | ||
| 227 | - license = lib.licenses.gpl3Only; | ||
| 228 | - mainProgram = "niri"; | ||
| 229 | - platforms = lib.platforms.linux; | ||
| 230 | - }; | ||
| 231 | - } | ||
| 232 | - ) { }; | ||
| 233 | }; | 249 | }; |
| 234 | }; | 250 | }; |
| 235 | } | 251 | } |