diff options
| author | seth <getchoo@tuta.io> | 2024-09-27 14:59:08 -0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-10-05 12:09:24 -0700 |
| commit | b258fd69d23fe7acbbfbd522f974d39deef78984 (patch) | |
| tree | cd0c50abeb81bb046351d1d39b68c897e2d4dc89 | |
| parent | 3ab3e778abaca67e864f3ab7bbad6ae7c0c16638 (diff) | |
| download | niri-b258fd69d23fe7acbbfbd522f974d39deef78984.tar.gz niri-b258fd69d23fe7acbbfbd522f974d39deef78984.tar.bz2 niri-b258fd69d23fe7acbbfbd522f974d39deef78984.zip | |
flake: improve packaging
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
| -rw-r--r-- | flake.nix | 253 |
1 files changed, 158 insertions, 95 deletions
@@ -12,21 +12,19 @@ self, nixpkgs, nix-filter, - ... }: let inherit (nixpkgs) lib; - systems = [ - "aarch64-linux" - "x86_64-linux" - ]; + # Support all Linux systems that the nixpkgs flake exposes + systems = lib.intersectLists lib.systems.flakeExposed lib.platforms.linux; forAllSystems = lib.genAttrs systems; nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); in { checks = forAllSystems (system: { - inherit (self.packages.${system}) niri; + # We use the debug build here to save a bit of time + inherit (self.packages.${system}) niri-debug; }); devShells = forAllSystems ( @@ -39,8 +37,14 @@ inputsFrom = [ niri ]; env = { - LD_LIBRARY_PATH = lib.makeLibraryPath niri.buildInputs; - inherit (niri.env) LIBCLANG_PATH; + inherit (niri) LIBCLANG_PATH; + + # WARN: Do not overwrite this variable in your shell! + # It is required for `dlopen()` to work on some libraries; see the comment + # in the package expression + # + # This should only be set with `CARGO_BUILD_RUSTFLAGS="$CARGO_BUILD_RUSTFLAGS -C your-flags"` + inherit (niri) CARGO_BUILD_RUSTFLAGS; }; }; } @@ -48,95 +52,154 @@ formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); - packages = forAllSystems (system: { - niri = nixpkgsFor.${system}.callPackage ( - { - cairo, - clang, - fontconfig, - gdk-pixbuf, - glib, - graphene, - gtk4, - libadwaita, - libclang, - libdisplay-info, - libglvnd, - libinput, - libxkbcommon, - mesa, - pango, - pipewire, - pixman, - pkg-config, - rustPlatform, - seatd, - stdenv, - systemd, - wayland, - xorg, - }: - rustPlatform.buildRustPackage rec { - pname = "niri"; - version = self.shortRev or self.dirtyShortRev or "unknown"; - - cargoLock = { - # NOTE: This is only used for Git dependencies - allowBuiltinFetchGit = true; - lockFile = ./Cargo.lock; - }; + packages = forAllSystems ( + system: + let + inherit (self.packages.${system}) niri; + in + { + niri = nixpkgsFor.${system}.callPackage ( + { + cairo, + clang, + dbus, + libGL, + libclang, + libdisplay-info, + libinput, + libseat, + libxkbcommon, + mesa, + pango, + pipewire, + pkg-config, + rustPlatform, + systemd, + wayland, + withDbus ? true, + withSystemd ? true, + withScreencastSupport ? true, + withDinit ? false, + }: - src = nix-filter.lib.filter { - root = self; - include = [ - "niri-config" - "niri-ipc" - "resources" - "src" + rustPlatform.buildRustPackage { + pname = "niri"; + version = self.shortRev or self.dirtyShortRev or "unknown"; + + src = nix-filter.lib.filter { + root = self; + include = [ + "niri-config" + "niri-ipc" + "niri-visual-tests" + "resources" + "src" + ./Cargo.lock + ./Cargo.toml + ]; + }; + + postPatch = '' + patchShebangs resources/niri-session + substituteInPlace resources/niri.service \ + --replace-fail '/usr/bin' "$out/bin" + ''; + + cargoLock = { + # NOTE: This is only used for Git dependencies + allowBuiltinFetchGit = true; + lockFile = ./Cargo.lock; + }; + + strictDeps = true; + + nativeBuildInputs = [ + clang + pkg-config ]; - }; - nativeBuildInputs = [ - clang - gdk-pixbuf - graphene - gtk4 - libadwaita - pkg-config - ]; - - buildInputs = [ - cairo - fontconfig - glib - libdisplay-info - libinput - libxkbcommon - mesa # For libgbm - pango - pipewire - pixman - seatd # For libseat - stdenv.cc.cc.lib - systemd # For libudev - wayland - ]; - - runtimeDependencies = [ - libglvnd # For libEGL - libxkbcommon - mesa - wayland - xorg.libXcursor - xorg.libXi - ]; - - LD_LIBRARY_PATH = lib.makeLibraryPath runtimeDependencies; - LIBCLANG_PATH = lib.getLib libclang + "/lib"; - } - ) { }; - - default = self.packages.${system}.niri; - }); + buildInputs = + [ + cairo + dbus + libGL + libdisplay-info + libinput + libseat + libxkbcommon + mesa # libgbm + pango + wayland + ] + ++ lib.optional (withDbus || withScreencastSupport || withSystemd) dbus + ++ lib.optional withScreencastSupport pipewire + # Also includes libudev + ++ lib.optional withSystemd systemd; + + buildFeatures = + lib.optional withDbus "dbus" + ++ lib.optional withDinit "dinit" + ++ lib.optional withScreencastSupport "xdp-gnome-screencast" + ++ lib.optional withSystemd "systemd"; + buildNoDefaultFeatures = true; + + postInstall = + '' + install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions + install -Dm644 resources/niri-portals.conf -t $out/share/xdg-desktop-portal + '' + + lib.optionalString withSystemd '' + install -Dm755 resources/niri-session $out/bin/niri-session + install -Dm644 resources/niri{.service,-shutdown.target} -t $out/share/systemd/user + ''; + + env = { + LIBCLANG_PATH = lib.getLib libclang + "/lib"; + + # Force linking with libEGL and libwayland-client + # so they can be discovered by `dlopen()` + CARGO_BUILD_RUSTFLAGS = toString ( + map (arg: "-C link-arg=" + arg) [ + "-Wl,--push-state,--no-as-needed" + "-lEGL" + "-lwayland-client" + "-Wl,--pop-state" + ] + ); + }; + + passthru = { + providedSessions = [ "niri" ]; + }; + + meta = { + description = "Scrollable-tiling Wayland compositor"; + homepage = "https://github.com/YaLTeR/niri"; + license = lib.licenses.gpl3Only; + mainProgram = "niri"; + platforms = lib.platforms.linux; + }; + } + ) { }; + + # NOTE: This is for development purposes only + # + # It is primarily to help with quickly iterating on + # changes made to the above expression - though it is + # also not stripped in order to better debug niri itself + niri-debug = niri.overrideAttrs ( + newAttrs: oldAttrs: { + pname = oldAttrs.pname + "-debug"; + + cargoBuildType = "debug"; + cargoCheckType = newAttrs.cargoBuildType; + + dontStrip = true; + } + ); + + default = niri; + } + ); }; } |
