dotfiles/hyprland/hyprpaper.nix

60 lines
1.4 KiB
Nix

{ inputs
, lib
, config
, pkgs
, ...
}:
{
options =
let
inherit (lib) mkOption types;
in
{
hyprpaper = {
wallpaperFolder = mkOption {
type = types.str;
};
};
};
config =
let
cfg = config.hyprpaper;
hyprlandCfg = config.hyprland;
changeWallpaperScript =
pkgs.writeShellScriptBin
"change-wallpaper"
(lib.concatStringsSep
"\n"
(lib.flatten
(map
(m:
let
output = m.name;
wallpaper = "\"$(${pkgs.findutils}/bin/find -L \"${cfg.wallpaperFolder}\" -type f | ${pkgs.coreutils}/bin/shuf -n 1)\"";
in
[
"wallpaper=${wallpaper}"
"${pkgs.hyprland}/bin/hyprctl hyprpaper preload $wallpaper"
"${pkgs.hyprland}/bin/hyprctl hyprpaper wallpaper ${output},$wallpaper"
]
)
hyprlandCfg.monitors)
++ [ "${pkgs.hyprland}/bin/hyprctl hyprpaper unload all" ])
);
in
{
hyprland.autoStart = [
"${pkgs.hyprpaper}/bin/hyprpaper"
"sleep 2; ${changeWallpaperScript}/bin/change-wallpaper"
];
home.packages = with pkgs; [
hyprpaper
changeWallpaperScript
];
};
}