# This will prevent pools from being imported, but since my laptop has a single pool with a single disk which is mounted during boot, disabling this service saves me 10 seconds at boot. Reference: https://github.com/openzfs/zfs/issues/10891
- name: Disable services
  systemd:
    enabled: no
    masked: true
    name: "{{ item }}"
    daemon_reload: yes
  loop:
    - systemd-udev-settle.service

- name: Install tmpfiles.d configuration
  when: hwpstate is defined and hwpstate and cores is defined
  copy:
    src: "files/{{ item }}_tmpfiles.conf"
    dest: "/etc/tmpfiles.d/{{ item }}.conf"
    mode: 0644
    owner: root
    group: wheel
  loop:
    - screen_brightness

- name: Install module config
  copy:
    src: "files/{{ item }}_modprobe.conf"
    dest: "/etc/modprobe.d/{{ item }}.conf"
    mode: 0644
    owner: root
    group: wheel
  loop:
    - iwlwifi
    - snd_hda_intel
    - disable_sp5100_watchdog

- name: Configure kernel command line
  zfs:
    name: "zroot/linux"
    state: present
    extra_zfs_properties:
      # amdgpu.abmlevel=3 :: Automatically reduce screen brightness but tweak colors to compensate for power reduction.
      # pcie_aspm=force pcie_aspm.policy=powersupersave :: Enable PCIe active state power management for power reduction.
      # nowatchdog :: Disable watchdog for power savings (related to disable_sp5100_watchdog above).
      # amd_pstate=passive :: Fully automated hardware pstate control.
      # amd_pstate=active :: Same as passive except we can set the energy performance preference (EPP) to suggest how much we prefer performance or energy efficiency.
      # amd_pstate=guided :: Same as passive except we can set upper and lower frequency bounds.
      "org.zfsbootmenu:commandline": "rw quiet amdgpu.abmlevel=3 pcie_aspm=force pcie_aspm.policy=powersupersave nowatchdog"

- name: Install Configuration
  copy:
    src: "files/{{ item.src }}"
    dest: "{{ item.dest }}"
    mode: 0600
    owner: root
    group: wheel
  loop:
    - src: gpe10-boot.service
      dest: /etc/systemd/system/gpe10-boot.service
    - src: gpe10-sleep.service
      dest: /etc/systemd/system/gpe10-sleep.service

- name: Enable services
  systemd:
    enabled: yes
    name: "{{ item }}"
    daemon_reload: yes
  loop:
    - gpe10-boot.service
    - gpe10-sleep.service
