- name: Install basic custom void packages
  hosts: interface
  become: true
  tags:
    - interface
    - packages
  tasks:
    - name: Set up keyd for custom key events
      community.general.xbps:
        name:
          - keyd
        state: "{{ desired_package_state }}"
      notify: installed-keyd

    - name: Install many fonts
      community.general.xbps:
        name: "{{ fonts }}"
        state: "{{ desired_package_state }}"
      notify: installed-fonts
      when: fonts

  handlers:
    - name: Activate keyd service
      ansible.builtin.file:
        force: "yes"
        src: "/etc/sv/{{ item }}"
        dest: "/etc/runit/runsvdir/default/{{ item }}"
        state: link
      with_items: [keyd]
      listen: installed-keyd

    - name: Regenerate fontconfig
      ansible.builtin.command:
        argv:
          - xbps-reconfigure
          - --force
          - fontconfig
      listen: installed-fonts

- name: Install bluetooth
  hosts: target_system
  become: true
  tags:
    - bluetooth
  tasks:
    - name: Install bluetooth packages
      community.general.xbps:
        name:
          - bluez
        state: "{{ desired_package_state }}"
      notify: installed-bluetooth

  handlers:
    - name: Activate bluetooth service
      ansible.builtin.file:
        force: "yes"
        src: "/etc/sv/{{ item }}"
        dest: "/etc/runit/runsvdir/default/{{ item }}"
        state: link
      with_items: [bluetoothd, dbus]
      listen: installed-bluetooth

- name: Install gnupg
  hosts: target_system
  become: true
  tags:
    - packages
    - gpg
  tasks:
    - name: Install a bunch of base custom stuff
      community.general.xbps:
        name: [gnupg, gnupg2-scdaemon]
        state: "{{ desired_package_state }}"
  handlers:
    - name: Put user in plugdev group
      ansible.builtin.user:
        name: "{{ user_name }}"
        groups: [plugdev]
        append: true

- name: Install basic custom void packages
  hosts: target_system
  become: true
  tags:
    - packages
  tasks:
    - name: Install a bunch of base custom stuff
      community.general.xbps:
        name: "{{ lookup('community.general.merge_variables', '^packages_.*') }}"
        state: "{{ desired_package_state }}"