---
- name: Install attic
  hosts: ulna

  tasks:
  - name: Install nix libraries
    ansible.builtin.apt:
      name: nix-bin
      state: present
    become: true

  - name: Unarchive
    ansible.builtin.unarchive:
      src: files/attic.tar.xz
      dest: /usr/local
    become: true

  - name: Install service file
    ansible.builtin.template:
      src: templates/attic/attic.service.j2
      dest: /etc/systemd/system/attic.service
    become: true

  - name: Install config file
    ansible.builtin.template:
      src: templates/attic/attic-server.toml.j2
      dest: /etc/attic-server.toml
    become: true

  - name: Create share directory
    ansible.builtin.file:
      path: /usr/local/share/attic
      mode: "0700"
      owner: root
      group: root
      state: directory
    become: true

  - name: Restart service
    ansible.builtin.systemd:
      state: restarted
      name: attic
      enabled: true
      daemon_reload: true
    become: true
