Skip to content

Instantly share code, notes, and snippets.

@BvngeeCord
Last active April 4, 2024 18:44
Show Gist options
  • Save BvngeeCord/6e7ce1cd14623870bcbd583ae1bb2725 to your computer and use it in GitHub Desktop.
Save BvngeeCord/6e7ce1cd14623870bcbd583ae1bb2725 to your computer and use it in GitHub Desktop.
How to compile Sway and wlroots together from source (on NixOS)
{ pkgs ? import <nixpkgs-unstable> { }, ... }:
let
# NOTE: i only need this because of the specifix nixpkgs-unstable I use for my system - you probably wont need this
pkgsNew = import
(fetchTarball "https://github.com/NixOS/nixpkgs/archive/4907e7a50c83b6214239d30a833f59493754eb48.tar.gz")
{ };
in
pkgs.mkShell {
name = "wlroots";
packages = with pkgs; [
pkgsNew.libdrm
libGL
wayland
libxkbcommon
pcre2
json_c
libevdev
pango
cairo
libinput
gdk-pixbuf
librsvg
pkgsNew.wayland-protocols
xorg.xcbutilwm
pkg-config
meson
ninja
wayland-scanner
scdoc
pkg-config
];
}

How to compile Sway and wlroots together from source (on NixOS)

I came up with this process when I needed to compile the latest commit of Sway to test a new feature, and my distro (NixOS) didn't have the required wlroots version packaged so I needed to compile that too. Here are the commands I ran for each repo:

1) wlroots

git clone https://gitlab.freedesktop.org/wlroots/wlroots

(NixOS users: use a shell.nix to get all the necessary deps. A sample file is attached to this gist) Now you can compile wlroots. Notes:

  • -Doptimization avoids compile errors due to default nix fortify flags
  • --prefix tells meson to use a new out subdir as the prefix instead of the default /usr/local
meson setup build -Ddebug=true -Doptimization=2 --prefix=/home/<user>/dev/wlroots/build/out
ninja -C build install # installs to the previously specified prefix

2) Sway

git clone https://github.com/swaywm/sway/

(NixOS users: another nearly identical shell.nix can be used to get all of Sway's deps (not shown)) Now, the fun part: setup Sway to use our local wlroots

PKG_CONFIG_LIBDIR="/home/<user>/dev/wlroots/build/out/lib/pkgconfig/" meson setup build -Ddebug=true -Doptimization=2

And now compile:

ninja -C build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment