Unverified Commit 15aa26ce authored by Masum Reza's avatar Masum Reza Committed by GitHub
Browse files

Merge pull request #318815 from OPNA2608/init/miracle-wm

miracle-wm: init at 0.3.0
parents 35f02c74 c8b213a2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@
  ./programs/wayland/hyprlock.nix
  ./programs/wayland/hyprland.nix
  ./programs/wayland/labwc.nix
  ./programs/wayland/miracle-wm.nix
  ./programs/wayland/river.nix
  ./programs/wayland/sway.nix
  ./programs/wayland/waybar.nix
+43 −0
Original line number Diff line number Diff line
{
  config,
  pkgs,
  lib,
  ...
}:

let
  cfg = config.programs.wayland.miracle-wm;
in
{
  options.programs.wayland.miracle-wm = {
    enable = lib.mkEnableOption ''
      miracle-wm, a tiling Mir based Wayland compositor. You can manually launch miracle-wm by
      executing "exec miracle-wm" on a TTY, or launch it from a display manager.
      Consult the USERGUIDE.md at <https://github.com/mattkae/miracle-wm> for information on
      how to use & configure it
    '';
  };

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        environment = {
          systemPackages = [ pkgs.miracle-wm ];
        };

        # To make the miracle-wm session available if a display manager like SDDM is enabled:
        services.displayManager.sessionPackages = [ pkgs.miracle-wm ];
      }

      (import ./wayland-session.nix {
        inherit lib pkgs;
        # Hardcoded path in Mir, not really possible to disable
        enableXWayland = true;
        # No portal support yet: https://github.com/mattkae/miracle-wm/issues/164
        enableWlrPortal = false;
      })
    ]
  );

  meta.maintainers = with lib.maintainers; [ OPNA2608 ];
}
+1 −0
Original line number Diff line number Diff line
@@ -579,6 +579,7 @@ in {
  minidlna = handleTest ./minidlna.nix {};
  miniflux = handleTest ./miniflux.nix {};
  minio = handleTest ./minio.nix {};
  miracle-wm = runTest ./miracle-wm.nix;
  miriway = handleTest ./miriway.nix {};
  misc = handleTest ./misc.nix {};
  mjolnir = handleTest ./matrix/mjolnir.nix {};
+131 −0
Original line number Diff line number Diff line
{ pkgs, lib, ... }:
{
  name = "miracle-wm";

  meta = {
    maintainers = with lib.maintainers; [ OPNA2608 ];
  };

  nodes.machine =
    { config, ... }:
    {
      imports = [
        ./common/auto.nix
        ./common/user-account.nix
      ];

      # Seems to very rarely get interrupted by oom-killer
      virtualisation.memorySize = 2047;

      test-support.displayManager.auto = {
        enable = true;
        user = "alice";
      };

      services.xserver.enable = true;
      services.displayManager.defaultSession = lib.mkForce "miracle-wm";

      programs.wayland.miracle-wm.enable = true;

      # To ensure a specific config for the tests
      systemd.tmpfiles.rules =
        let
          testConfig = (pkgs.formats.yaml { }).generate "miracle-wm.yaml" {
            terminal = "env WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY= alacritty";
            startup_apps = [
              {
                command = "foot";
                restart_on_death = false;
              }
            ];
          };
        in
        [
          "d ${config.users.users.alice.home}/.config 0700 alice users - -"
          "L ${config.users.users.alice.home}/.config/miracle-wm.yaml - - - - ${testConfig}"
        ];

      environment = {
        shellAliases = {
          test-wayland = "wayland-info | tee /tmp/test-wayland.out && touch /tmp/test-wayland-exit-ok";
          test-x11 = "glinfo | tee /tmp/test-x11.out && touch /tmp/test-x11-exit-ok";
        };

        systemPackages = with pkgs; [
          mesa-demos
          wayland-utils
          foot
          alacritty
        ];

        # To help with OCR
        etc."xdg/foot/foot.ini".text = lib.generators.toINI { } {
          main = {
            font = "inconsolata:size=16";
          };
          colors = rec {
            foreground = "000000";
            background = "ffffff";
            regular2 = foreground;
          };
        };
        etc."xdg/alacritty/alacritty.yml".text = lib.generators.toYAML { } {
          font = rec {
            normal.family = "Inconsolata";
            bold.family = normal.family;
            italic.family = normal.family;
            bold_italic.family = normal.family;
            size = 16;
          };
          colors = rec {
            primary = {
              foreground = "0x000000";
              background = "0xffffff";
            };
            normal = {
              green = primary.foreground;
            };
          };
        };
      };

      fonts.packages = [ pkgs.inconsolata ];
    };

  enableOCR = true;

  testScript =
    { ... }:
    ''
      start_all()
      machine.wait_for_unit("multi-user.target")

      # Wait for Miriway to complete startup
      machine.wait_for_file("/run/user/1000/wayland-0")
      machine.succeed("pgrep miracle-wm")
      machine.screenshot("miracle-wm_launched")

      # Test Wayland
      with subtest("wayland client works"):
          # We let miracle-wm start the first terminal, as we might get stuck if it's not ready to process the first keybind
          # machine.send_key("ctrl-alt-t")
          machine.wait_for_text("alice@machine")
          machine.send_chars("test-wayland\n")
          machine.wait_for_file("/tmp/test-wayland-exit-ok")
          machine.copy_from_vm("/tmp/test-wayland.out")
          machine.screenshot("foot_wayland_info")
          machine.send_chars("exit\n")
          machine.wait_until_fails("pgrep foot")

      # Test XWayland
      with subtest("x11 client works"):
          machine.send_key("meta_l-ret")
          machine.wait_for_text("alice@machine")
          machine.send_chars("test-x11\n")
          machine.wait_for_file("/tmp/test-x11-exit-ok")
          machine.copy_from_vm("/tmp/test-x11.out")
          machine.screenshot("alacritty_glinfo")
          machine.send_chars("exit\n")
          machine.wait_until_fails("pgrep alacritty")
    '';
}
+105 −0
Original line number Diff line number Diff line
{
  stdenv,
  lib,
  fetchFromGitHub,
  gitUpdater,
  nixosTests,
  boost,
  cmake,
  glib,
  glm,
  gtest,
  libevdev,
  libglvnd,
  libnotify,
  libuuid,
  libxkbcommon,
  mesa,
  mir,
  nlohmann_json,
  pcre2,
  pkg-config,
  yaml-cpp,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "miracle-wm";
  version = "0.3.0";

  src = fetchFromGitHub {
    owner = "mattkae";
    repo = "miracle-wm";
    rev = "v${finalAttrs.version}";
    hash = "sha256-Ss93yI33e+XFjbKedbBjmYHkjPeWUWxEStwNTgTszA4=";
  };

  postPatch =
    ''
      substituteInPlace session/usr/local/share/wayland-sessions/miracle-wm.desktop.in \
        --replace-fail '@CMAKE_INSTALL_FULL_BINDIR@/miracle-wm' 'miracle-wm'
    ''
    + lib.optionalString (!finalAttrs.finalPackage.doCheck) ''
      substituteInPlace CMakeLists.txt \
        --replace-fail 'add_subdirectory(tests/)' ""
    '';

  strictDeps = true;

  # Source has a path "session/usr/local/...", don't break references to that
  dontFixCmake = true;

  nativeBuildInputs = [
    cmake
    pkg-config
  ];

  buildInputs = [
    boost
    glib
    glm
    libevdev
    libglvnd
    libnotify
    libuuid
    libxkbcommon
    mesa # gbm.h
    mir
    nlohmann_json
    pcre2
    yaml-cpp
  ];

  checkInputs = [ gtest ];

  doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;

  checkPhase = ''
    runHook preCheck

    ./bin/miracle-wm-tests

    runHook postCheck
  '';

  passthru = {
    updateScript = gitUpdater { rev-prefix = "v"; };
    providedSessions = [ "miracle-wm" ];
    tests.vm = nixosTests.miracle-wm;
  };

  meta = with lib; {
    description = "Tiling Wayland compositor based on Mir";
    longDescription = ''
      miracle-wm is a Wayland compositor based on Mir. It features a tiling window manager at its core, very much in
      the style of i3 and sway. The intention is to build a compositor that is flashier and more feature-rich than
      either of those compositors, like swayfx.

      See the user guide for info on how to use miracle-wm: https://github.com/mattkae/miracle-wm/blob/v${finalAttrs.version}/USERGUIDE.md
    '';
    homepage = "https://github.com/mattkae/miracle-wm";
    license = licenses.gpl3Only;
    mainProgram = "miracle-wm";
    maintainers = with maintainers; [ OPNA2608 ];
    platforms = platforms.linux;
  };
})