{
  lib,
  config,
  pkgs,
  ...
}: let
  cfg = config.marleyos.services.swaybg;
in {
  options.marleyos.services.swaybg.enable = lib.mkEnableOption "swaybg";

  config = lib.mkIf cfg.enable {
    home.packages = with pkgs; [
      swaybg
    ];

    systemd.user.services.swaybg = {
      Install = {
        WantedBy = ["graphical-session.target"];
      };

      Unit = {
        Description = "Wallpaper tool for Wayland compositors";
        Documentation = ["man:swaybg(1)"];
        After = ["graphical-session-pre.target"];
        PartOf = ["graphical-session.target"];
      };

      Service = {
        Type = "exec";
        ExecStart = "${lib.getExe pkgs.swaybg} -i ${config.stylix.image}";
        ExecReload = "${lib.getExe' pkgs.coreutils "kill"} -SIGUSR2 $MAINPID";
        KillMode = "mixed";
        Restart = "on-failure";
      };
    };
  };
}
