Building River latest with wlroots unstable?

Hello, I’m new to nixos I have searched around in many locations and
can’t figure out that easiest and best way to build river from source code.
Preferably I would like to pin to a commit.

I tried this:

  nixpkgs.overlays = [
	(final: prev: {
		river = prev.river.overrideAttrs (old: { src = /home/alex/Downloads/river ;});
	})
  ];

But it won’t build without wlroots 17.2. I decided to move to channel unstable and
I’m still getting an error.

install transitive failure
(0mq(B install river transitive failure
   (0mq(B zig build-exe river ReleaseSafe native-native 3 errors
river/main.zig:35:9: error: river requires at least wlroots version 0.17.2 due to bugs in wlroots 0.17.0/0.17.1
        @compileError("river requires at least wlroots version 0.17.2 due to bugs in wlroots 0.17.0/0.17.1");
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
deps/zig-wlroots/src/wlroots.zig:210:9: error: zig-wlroots requires wlroots version 0.17
        @compileError("zig-wlroots requires wlroots version 0.17");
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
river/Server.zig:282:60: error: FIXME
    if (wlr.version.major != 0 or wlr.version.minor != 17) @compileError("FIXME");
                                                           ^~~~~~~~~~~~~~~~~~~~~~

error: builder for '/nix/store/1y6izwh27wb5h48bldf694j6dy9qkmc2-river-0.2.6.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/y5c031ca5p3dphjir39y3s1i9cvw2lch-desktops.drv' failed to build
error: 1 dependencies of derivation '/nix/store/c4nk7n65ba4fmkbxgycchw4z17wgn28h-man-paths.drv' failed to build
error: 1 dependencies of derivation '/nix/store/7xw8l5zhb5vibp062xxqida3bny6qp31-river-0.2.6_fish-completions.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ii7sk9zvh69fiyak6knm08nl2hpjhdp0-rivercarro-0.3.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/pz8y4xhy1ijr5f517ab0mazgrzzciih5-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/qgka665j7rxn7n6v8n9bq4ai4kl7kzvk-nixos-system-nixos-24.05pre604424.d8fe5e6c92d0.drv' failed to build

I’m not familar with fake, so not sure if it would be a better approach. Ideally
I would have liked to stayed on stable and only upgraded wlroots and river.

I also tried this:

wayland.windowManager.river = {
    enable = true;
    package = with pkgs; pkgs.river.overrideAttrs (old: {
      src = river;
      buildInputs = lib.lists.remove wlroots_0_16 old.buildInputs ++ [
        (wlroots.overrideAttrs (_: {
          version = "0.17.2";
        }))
      ];
    });
};

But I get The option `wayland’ does not exist. Definition values.

I also tried this but don’t think it worked because I’m in my environment.

nix-shell -I nixpkgs=channel:nixpkgs-unstable -p wlroots_0_17

I’m not sure what else I need to do to upgrade river by building
it from source?

UPDATE: I figured it out but not sure how to use wlroots 17 to build the package.
I can build it locally but would prefer building it from my configuration.nix with overlays.

 error: zig-wlroots requires wlroots version 0.17

You can use it like this:
pkgs/river.nix

{
  src,
  version,
  lib,
  stdenv,
  libGL,
  libX11,
  libevdev,
  libinput,
  libxkbcommon,
  pixman,
  pkg-config,
  scdoc,
  udev,
  wayland,
  wayland-protocols,
  wayland-scanner,
  wlroots,
  xwayland,
  zig,
  withManpages ? true,
  xwaylandSupport ? true,
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "river";
  inherit version;

  outputs = [ "out" ] ++ lib.optionals withManpages [ "man" ];
  inherit src;

  nativeBuildInputs = [
    pkg-config
    wayland
    wayland-scanner
    zig.hook
    xwayland
  ] ++ lib.optional withManpages scdoc;

  buildInputs = [
    libGL
    libevdev
    libinput
    libxkbcommon
    pixman
    udev
    wayland-protocols
    wlroots
  ] ++ lib.optional xwaylandSupport libX11;

  dontConfigure = true;

  zigBuildFlags =
    lib.optional withManpages "-Dman-pages"
    ++ lib.optional xwaylandSupport "-Dxwayland";

  postInstall = ''
    install contrib/river.desktop -Dt $out/share/wayland-sessions
  '';

  passthru.providedSessions = [ "river" ];

  meta = {
    homepage = "https://github.com/ifreund/river";
    description = "A dynamic tiling wayland compositor";
    longDescription = ''
      River is a dynamic tiling Wayland compositor with flexible runtime
      Its design goals are:
      - Simple and predictable behavior, river should be easy to use and have a
        low cognitive load.
      - Window management based on a stack of views and tags.
      - Dynamic layouts generated by external, user-written executables. A
        default rivertile layout generator is provided.
      - Scriptable configuration and control through a custom Wayland protocol
        and separate riverctl binary implementing it.
    '';
    changelog = "https://github.com/ifreund/river/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.gpl3Plus;
    maintainers = with lib.maintainers; [
      adamcstephens
      fortuneteller2k
      rodrgz
    ];
    mainProgram = "river";
    platforms = lib.platforms.linux;
  };
})

Then overlay using nixpkgs.overlays:

river = final.callPackage ../pkgs/river.nix {
      # wlroots = final.wlroots-river;
      src = inputs.river-src;
      version = "git";
    };

Where inputs.river-src used in flake.nix as follows:

inputs.river-src = {
      url = "git+https://codeberg.org/river/river?submodules=1";
      flake = false;
    };

It looks similar to mine, it looks like you are building locally with pkgs/river.nix?
The only diffrence is I have this in my local source default.niix:

 src = fetchFromGitHub {
    owner = "riverwm";
    repo = "river";
    rev = "36d8e90a5423c4da037ca6fb2dd02c70cf6a4f3b";
    hash = "sha256-JTto0za9zIw8W3KN3eIPGfpsQU3VH+M3i8Gk6KUNHMQ=";
    fetchSubmodules = true;
  };

I then build it like this in configuration.nix.

(pkgs.callPackage ./dev/river/river-dev/default.nix {})

This works fine, the problem is I don’t want to have local source code.
Is there a way to build it directly from configuration.nix? I can’t
seem how to figure this out since I get an error: attribute 'wlroots_0_17' missing.
I tried putting it on top.

How can I build directly from configurating.nix, is it possible to buile without a local source?
With snapper I can build fine. However, river requires wlroots 17 and
some tweaks. This is what I have been trying but I can’t figure it out:

  nixpkgs.overlays = [
    # self: super:
    (final: prev: {
      snapper = prev.snapper.overrideAttrs (old: {
        src = prev.fetchFromGitHub {
          owner = "openSUSE";
          repo = "snapper";
          rev = "f7a1f9aa6d9c248fc77ee8d746c17c44e48cc343";
          sha256 = "sha256-ZuOQnZAi/+Q5Dwuu+f3KNmfPy+0q0leZ0pQWlcgekLY=";
        };
      });

            river = prev.river.overrideAttrs (oldAttrs: rec {
              version = "0.3";
              wlroots = pkgs.wlroots-unstable;
              src = prev.fetchFromGitHub {
                owner = "riverwm";
                repo = "river";
                rev = "36d8e90a5423c4da037ca6fb2dd02c70cf6a4f3b";
                hash = "sha256-JTto0za9zIw8W3KN3eIPGfpsQU3VH+M3i8Gk6KUNHMQ=";
                fetchSubmodules = true;
              };
              buildInputs = with pkgs;
                [
                  libGL
                  libevdev
                  libinput
                  libxkbcommon
                  pixman
                  udev
                  wayland-protocols
                  wlroots_0_17
                  libX11
                  xwaylandSupport
                ]; # ++ lib.optional true libX11;
            });
    })
  ];

As far as I can see, you actually would need to change 2 things:
wlroots in river should be defined as

wlroots_0_16=pkgs.wlroots-unstable;

And in build inputs just use this wlroots_0_16 because you already defined it as a wlroots_0_17 earlier.

Thanks for the idea, so based on your idea. I made some modifications and was
able to build. I’m not sure how I would use xwaylandSupport ? true but it’s not
a big deal I just put lib.optional true libX11. So the changes I made to make it work:

In the overlay:

wlroots_0_17 = pkgs.pkgsLinux.wlroots_0_17;
libX11 = pkgs.xorg.libX11;

In the build:

        buildInputs = with pkgs; [
          libGL
          libevdev
          libinput
          libxkbcommon
          pixman
          udev
          wayland-protocols
          # wlroots_0_16 #0.2.6
          wlroots_0_17 # 0.3.0
        ]  ++ lib.optional true libX11;