{
  config,
  lib,
  pkgs,
  home-manager,
  ...
}:

let
  inherit (lib)
    filter
    attrNames
    ;
in
{
  imports = [ ];

  options.me = {
    copy.file = lib.mkOption {
      type = lib.types.attrsOf (
        lib.types.submodule (
          { name, config, ... }:
          {
            options = {
              enable = lib.mkOption {
                type = lib.types.bool;
                default = true;
                defaultText = "me.copy.file.‹name›.enable";
                example = false;
                description = "Whether we want to copy this file.";
              };
              mode = lib.mkOption {
                type = lib.types.str;
                default = "0444";
                defaultText = "me.copy.file.‹name›.mode";
                example = "0750";
                description = "The read, write, execute permission flags.";
              };
              source = lib.mkOption {
                type = lib.types.path;
                defaultText = "me.copy.file.‹name›.source";
                example = ./files/foo.txt;
                description = "The source file to copy into the destination.";
              };
              target = lib.mkOption {
                type = lib.types.str;
                defaultText = "me.copy.file.‹name›.target";
                example = ".local/share/foo/bar.txt";
                description = "The path where the file should be written.";
              };
            };

            config = {
              target = lib.mkDefault name;
            };
          }
        )
      );
      defaultText = "me.copy.file.‹name›";
      default = { };
      example = lib.literalExpression ''
        {
          ".config/foo/bar.txt" = {
            source = ./files/bar.txt
          };
        }
      '';
    };
  };

  config = lib.mkMerge [
    (lib.mkIf (config.me.copy.file != { }) (
      let
        cfg = config.me.copy.file;
        copy_file_targets = filter (target: config.me.copy.file."${target}".enable) (attrNames cfg);
      in
      {
        home.activation = {
          # TODO: Perhaps place a script in checkLinkTargets to verify copy targets can be overwritten so home-manager aborts before files are changed.
          copyFiles = home-manager.lib.hm.dag.entryAfter [ "writeBoundary" ] (
            let
              copy_commands = builtins.map (
                target:
                let
                  target_config = config.me.copy.file."${target}";
                  source = lib.strings.escapeShellArg "${target_config.source}";
                  destination = lib.strings.escapeShellArg "${target_config.target}";
                  mode = lib.strings.escapeShellArg "${target_config.mode}";
                in
                # $DRY_RUN_CMD ${pkgs.toyboy}/bin/install $VERBOSE_ARG -D -m ${mode} ${source} ${destination}
                ''
                  $DRY_RUN_CMD install $VERBOSE_ARG -D --compare -m ${mode} ${source} ${destination}
                ''
              ) copy_file_targets;
            in
            (lib.strings.concatStringsSep "\n" copy_commands)
          );
        };
      }
    ))
  ];
}
