From 86561bdafc4a4d89d8978cda4ce84b27f9535a37 Mon Sep 17 00:00:00 2001
From: Daniel Firth <dan.firth@homotopic.tech>
Date: Mon, 13 Mar 2023 10:18:52 +0000
Subject: [PATCH] run cachix in parallel

---
 .cachix.dhall  | 22 ++++++++++++++--------
 .gitlab-ci.yml |  3 ++-
 flake.nix      |  5 +++++
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/.cachix.dhall b/.cachix.dhall
index be21b7ae..29ecf474 100644
--- a/.cachix.dhall
+++ b/.cachix.dhall
@@ -10,7 +10,11 @@ let H =
 let toStep
     : Text → Text
     = λ(x : Text) →
-        "nix build --json .#${x} | jq -r '.[].outputs | to_entries[].value' | cachix push horizon"
+        "nix build --accept-flake-config --json .#${x} | jq -r '.[].outputs | to_entries[].value' | cachix push horizon"
+
+let toEchoStep
+    : Text → Text
+    = λ(x : Text) → "echo \"${toStep x}\""
 
 let input =
       Prelude.Map.keys
@@ -24,11 +28,13 @@ let input =
             ./horizon.dhall
         )
 
-let packages = Prelude.List.map Text Text toStep (input : List Text)
+let packages = Prelude.List.map Text Text toEchoStep (input : List Text)
 
-in  Prelude.List.fold
-      Text
-      packages
-      Text
-      (λ(x : Text) → λ(y : Text) → x ++ "\n" ++ y)
-      ""
+in      "("
+    ++  Prelude.List.fold
+          Text
+          packages
+          Text
+          (λ(x : Text) → λ(y : Text) → x ++ ";" ++ y)
+          ""
+    ++  ") | parallel -j 16"
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4f8c637c..5cb6ab10 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,4 +23,5 @@ cachix:
   only:
     refs:
     - master
-  script: dhall --file .cachix.dhall | dhall text | bash
+    - cachix
+  script: nix-shell -p jq cachix parallel --command 'dhall --file .cachix.dhall | dhall text | bash'
diff --git a/flake.nix b/flake.nix
index c9718001..463cdc4b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,6 +2,11 @@
 
   description = "Horizon Haskell Platform";
 
+  nixConfig = {
+    extra-substituters = "https://horizon.cachix.org";
+    extra-trusted-public-keys = "horizon.cachix.org-1:MeEEDRhRZTgv/FFGCv3479/dmJDfJ82G6kfUDxMSAw0=";
+  };
+
   inputs = {
     get-flake.url = "github:ursi/get-flake";
     flake-parts.url = "github:hercules-ci/flake-parts";
-- 
GitLab