{
  pkgs,
  lib,
  stdenv,
  ...
}:
{
  palette,
  wallpaper,
}:
let
  strPal =
    let
      inherit (lib) concatStringsSep;
      inherit (builtins) foldl' attrValues;
    in
    concatStringsSep " " (
      foldl' (acc: el: acc ++ (attrValues el)) [ ] [ palette.normal palette.bright palette.util ]
    );
in
stdenv.mkDerivation {
  name = "generated-wallpaper.png";
  src = wallpaper;
  buildInputs = [
    pkgs.lutgen
  ];

  phases = [ "installPhase" ];

  installPhase = ''
    echo -e "Generating wallpaper from ${wallpaper} using palette:\n${strPal}.."
    ${lib.getExe pkgs.lutgen} apply --lum 0.8 -l 10 -s 128 -n 8 -o $out ${wallpaper} -- ${strPal}
  '';
}
