---
- block:
    - name: "Cabal update"
      command: "{{cabal_bin}} v2-update --with-ghc=ghc-{{ghc_version}}"

    - name: Remove stale GHC environments
      file:
        path: "/tmp/env.{{config.user}}"
        state: absent

    - name: Hackage modules
      command: "{{cabal_bin}} v2-install --with-ghc=ghc-{{ghc_version}} --lib --package-env=/tmp/env.{{config.user}} {{item}}"
      loop: "{{pkgs}}"

    - name: Hackage extra modules
      command: "{{cabal_bin}} v2-install --with-ghc=ghc-{{ghc_version}} --lib --package-env=/tmp/env.{{config.user}} {{item}}"

      loop: "{{config.extra_pkgs}}"
      when: config.extra_pkgs is defined

    - name: hsExprTest checkout
      git:
        dest: '~/hsExprTest'
        repo: https://github.com/vlstill/hsExprTest.git
        update: true

    - name: Install hsExprTest
      command:
        chdir: '~/hsExprTest'
        cmd: "{{cabal_bin}} v2-install --with-ghc=ghc-{{ghc_version}} --lib --package-env=/tmp/env.{{config.user}}"

    - name: Create GHC environment dir
      file:
        state: directory
        path: "~/.local/share/ghc/x86_64-linux-{{ghc_version}}/environments"

    - name: Deploy modified GHC environment
      command: "mv /tmp/env.{{config.user}} ~/.local/share/ghc/x86_64-linux-{{ghc_version}}/environments/default"
  become: true
  become_user: "{{config.user}}"
