stages:
- generate
- ghc
- packages
- cache

generate-flake-ci:
  stage: generate
  script:
  - nix run develop/#flake-to-gitlab-ci > flake-ci-x86_64-linux.yml
  artifacts:
    paths:
      - flake-ci-x86_64-linux.yml

x86_64-linux.ghc:
  stage: ghc
  script:
  - nix build .#packages.x86_64-linux.ghc -L
  except:
    refs:
    - master
    - cachix

x86_64-linux.ghc.cachix:
  stage: ghc
  script:
  - nix-shell -p jq cachix --command "nix build -L --json .#packages.x86_64-linux.ghc | jq -r '.[].outputs | to_entries[].value' | cachix push horizon"
  only:
    refs:
    - master
    - cachix

x86_64-linux-ci:
  stage: packages
  trigger:
    include:
      - artifact: flake-ci-x86_64-linux.yml
        job: generate-flake-ci
    strategy: depend

cachix:
  stage: cache
  only:
    refs:
    - master
    - cachix
    - /^lts\/.*$/
  script:
  - nix-shell -p cachix --command "nix build github:srid/devour-flake -L --no-link --print-out-paths --override-input flake . | xargs cat | cachix push horizon"