shithub: wl9m

ref: bffc4bdc7f73139ae834619e3a018c17ceee9398
dir: /linux/flake.nix/

View raw version
{
  description = "p9wl - Wayland compositor proxy to Plan 9";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};

        p9wl = pkgs.stdenv.mkDerivation {
          pname = "p9wl";
          version = "0.1.0";

          src = ./.;

          nativeBuildInputs = with pkgs; [
            pkg-config
            wayland-scanner
            gnumake
          ];

          buildInputs = with pkgs; [
            wlroots
            wayland
            wayland-protocols
            libxkbcommon
            pixman
            lz4
            zlib
          ];

          preBuild = ''
            # Generate xdg-shell protocol header
            wayland-scanner server-header \
              ${pkgs.wayland-protocols}/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml \
              xdg-shell-protocol.h

            wayland-scanner private-code \
              ${pkgs.wayland-protocols}/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml \
              xdg-shell-protocol.c
          '';

          # Just use the Makefile
          buildPhase = ''
            runHook preBuild
            make
            runHook postBuild
          '';

          installPhase = ''
            runHook preInstall
            mkdir -p $out/bin
            cp p9wl $out/bin/
            runHook postInstall
          '';

          meta = with pkgs.lib; {
            description = "Wayland compositor that proxies display to Plan 9";
            license = licenses.mit;
            platforms = platforms.linux;
            mainProgram = "p9wl";
          };
        };

      in {
        packages = {
          default = p9wl;
          p9wl = p9wl;
        };

        devShells.default = pkgs.mkShell {
          inputsFrom = [ p9wl ];

          packages = with pkgs; [
            gcc
            gdb
            wayland-scanner
          ];

          shellHook = ''
            # Generate protocol headers for development
            if [ ! -f xdg-shell-protocol.h ]; then
              echo "Generating xdg-shell-protocol.h..."
              wayland-scanner server-header \
                ${pkgs.wayland-protocols}/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml \
                xdg-shell-protocol.h
            fi

            if [ ! -f xdg-shell-protocol.c ]; then
              echo "Generating xdg-shell-protocol.c..."
              wayland-scanner private-code \
                ${pkgs.wayland-protocols}/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml \
                xdg-shell-protocol.c
            fi

            echo "p9wl development shell"
            echo "  Build: make"
            echo "  Run:   ./p9wl <plan9-ip> [port]"
          '';
        };
      }
    );
}