{ config, pkgs, lib, ... }: let cfg = config.wayland.windowManager.hyprland; in { options.wayland.windowManager.hyprland = with lib; with types; { onMonitorChange.services = mkOption { type = listOf str; default = [ ]; description = "Services to restart when a monitor is connected or disconnected"; }; }; config.systemd.user.services.hyprland-monitor-watcher = { Unit = { Description = "Restarts services on monitor change"; After = [ "graphical-session.target" ]; PartOf = [ "graphical-session.target" ]; }; Service = { ExecStart = lib.meta.getExe ( pkgs.writeShellApplication { name = "hyprland-monitor-watcher"; runtimeInputs = with pkgs; [ socat systemd ]; runtimeEnv.SERVICES = lib.strings.concatStringsSep " " cfg.onMonitorChange.services; text = builtins.readFile ./scripts/monitors.sh; } ); Restart = "on-failure"; }; Install.WantedBy = [ "graphical-session.target" ]; }; }