nixos-config/modules/services/kanshi/default.nix

73 lines
1.7 KiB
Nix
Raw Normal View History

{
config
, lib
, pkgs
, ...
}:
let
kanshi = pkgs.kanshi;
writeShellScript = pkgs.writeShellScript;
wallpapersPath = "/home/${config.ptw.system.singleUser}/Data/Wallpaper";
wallpapersHorizontal = "${wallpapersPath}/horizontal";
wallpapersVertical = "${wallpapersPath}/vertical";
wallpaperScript = writeShellScript "wallpaper.sh" ''
set -x
[[ $# -lt 1 ]] && echo "No profile specified" && exit 1
random_file() {
find "$1" -maxdepth 1 -type f | shuf -n 1
}
setbg() {
# Sets the background of $1 to $2
swaymsg "output \"$1\" background $2 fill"
}
case $1 in
homeMultihead)
horiz=$(random_file ${wallpapersHorizontal})
vert=$(random_file ${wallpapersVertical})
setbg "DP-2" $horiz
setbg "HDMI-A-3" $vert
;;
genericMultihead)
horiz1=$(random_file ${wallpapersHorizontal})
horiz2=$(random_file ${wallpapersHorizontal})
setbg "eDP-1" $horiz1
setbg "HDMI-A-1" $horiz2
;;
laptop)
horiz=$(random_file ${wallpapersHorizontal})
setbg "eDP-1" $horiz
;;
esac
'';
mkProfile = name: outputs: {
outputs = outputs;
exec = "${wallpaperScript} ${name}";
};
cfg = config.ptw.services.kanshi;
in {
options.ptw.services.kanshi = {
enable = lib.mkEnableOption "Enable kanshi and configure using HomeManager";
profiles = lib.mkOption {
description = "The actual kanshi configuration";
type = lib.types.anything;
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ kanshi ];
home-manager.users."${config.ptw.system.singleUser}".services.kanshi = {
enable = true;
inherit (cfg) profiles;
};
};
}