{ inputs, ... }: {
  flake.nixosModules.desktopWallpapers =
    { config, lib, pkgs, ... }:
    let
      cfg = config.chiasson.desktop.wallpapers;
      d = config.chiasson.desktop;
      guiEnabled = d.hyprland.enable || d.niri.enable || d.plasma.enable;

      wallpaperDir = pkgs.stdenvNoCC.mkDerivation {
        pname = "chiasson-nix-wallpapers";
        version = "0.1";
        src = builtins.path {
          path = cfg.source;
          name = "wallpapers-src";
        };
        dontConfigure = true;
        dontBuild = true;
        installPhase = ''
          mkdir -p "$out/share/wallpapers"
          find "$src" -mindepth 1 -maxdepth 1 ! -name .git -exec cp -a {} "$out/share/wallpapers/" \;
        '';
      };

      installPath = "${wallpaperDir}/share/wallpapers";
    in
    {
      options.chiasson.desktop.wallpapers = {
        enable = lib.mkEnableOption ''
          Copy `source` into the store; sets `CHIASSON_NIX_WALLPAPERS` and `/etc/wallpapers`.
        '' // {
          default = true;
        };

        source = lib.mkOption {
          type = lib.types.path;
          default = inputs.wallpapers;
          description = ''
            Directory copied into the store. Default: `inputs.wallpapers`
            (`git+https://git.chiasson.cloud/Olivier/wallpapers`, pinned in `flake.lock`).
          '';
        };
      };

      config = lib.mkIf (guiEnabled && cfg.enable) {
        environment = {
          variables.CHIASSON_NIX_WALLPAPERS = installPath;
          sessionVariables.CHIASSON_NIX_WALLPAPERS = installPath;
          etc."wallpapers".source = installPath;
        };
      };
    };
}
