diff --git a/.ci/attic-auth.sh b/.ci/attic-auth.sh new file mode 100755 index 00000000..63aab314 --- /dev/null +++ b/.ci/attic-auth.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -uo pipefail + +mkdir -p ~/.config/attic +cat < ~/.config/attic/config.toml +default-server = "public" + +[servers.public] +endpoint = "http://192.168.102.136:9200" +token = "$ATTIC_AUTH_TOKEN" +EOF diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73907d2b..26e95493 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ concurrency: jobs: stack: name: Stack tests - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v4 @@ -142,6 +142,82 @@ jobs: run: | .ci/test_whitespace.sh + packages: + name: Push package to cache + runs-on: self-hosted + strategy: + matrix: + ghc-version: [ "ghc9101", "ghc982", "ghc964" ] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build & test + run: | + # The -L flag outputs build logs to stderr + nix build -L .#${{ matrix.ghc-version }}.clash-protocols-base + nix build -L .#${{ matrix.ghc-version }}.clash-protocols + + # Pushes the binaries to the local network + # url: http://192.168.102.136:9200/public + # public key: public:PGGlJMx1gGmU069blMqve8tS1ndzBuriUAwGBHGOo4g= + - name: Push package to cache + env: + ATTIC_AUTH_TOKEN: ${{ secrets.ATTIC_SECRET }} + run: | + .ci/attic-auth.sh + attic push public $(nix path-info .#${{ matrix.ghc-version }}.clash-protocols-base) + attic push public $(nix path-info .#${{ matrix.ghc-version }}.clash-protocols) + + - name: Push package to cachix + if: github.ref == 'refs/heads/main' + env: + # Having the variable be named `CACHIX_AUTH_TOKEN` authenticates cachix + # https://docs.cachix.org/getting-started#authenticating + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_SECRET }} + run: | + nix path-info .#${{ matrix.ghc-version }}.clash-protocols-base | cachix push clash-lang + nix path-info .#${{ matrix.ghc-version }}.clash-protocols | cachix push clash-lang + + devshells: + name: Push Nix developer shell to cache + runs-on: self-hosted + strategy: + matrix: + ghc-version: [ "ghc9101", "ghc982", "ghc964" ] + steps: + # There's no need to configure Nix, the dockerfile handling the GHA has it done for us! + # If dependencies are already cached, we can simply reuse them! + + - name: Checkout + uses: actions/checkout@v4 + + - name: Build devshell + run: | + # Since the server is x86_64-linux, we can only build the devshell + # for that + nix build -L .#devShells.x86_64-linux.${{ matrix.ghc-version }}-full + + # Pushes the binaries to the local network + # url: http://192.168.102.136:9200/public + # public key: public:PGGlJMx1gGmU069blMqve8tS1ndzBuriUAwGBHGOo4g= + - name: Push devshell to cache + env: + ATTIC_AUTH_TOKEN: ${{ secrets.ATTIC_SECRET }} + run: | + .ci/attic-auth.sh + attic push public $(nix path-info .#devShells.x86_64-linux.${{ matrix.ghc-version }}-full) + + # Pushes the binaries to Cachix + - name: Push devshell to cachix + if: github.ref == 'refs/heads/main' + env: + # Having the variable be named `CACHIX_AUTH_TOKEN` authenticates cachix + # https://docs.cachix.org/getting-started#authenticating + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_SECRET }} + run: | + nix path-info .#devShells.x86_64-linux.${{ matrix.ghc-version }}-full | cachix push clash-lang + # Mandatory check on GitHub all: name: All jobs finished @@ -151,8 +227,10 @@ jobs: fourmolu, linting, stack, + packages, + devshells, ] - runs-on: ubuntu-22.04 + runs-on: self-hosted steps: - name: Checkout uses: actions/checkout@v4 diff --git a/README.md b/README.md index 5a9c82d8..7c20dad6 100644 --- a/README.md +++ b/README.md @@ -668,6 +668,36 @@ in And that's it! +### Cache + +Compiling Clash can take quite some time. To remedy the situation, we maintain a Cachix cache which can be used to speed up compilation. To add the cache, first (temporarily) install cachix: + +`nix shell nixpkgs#cachix` + +And then run: + +`cachix use clash-lang` + +And that's it! The cache is now set up and you no longer need cachix installed. + +Alternatively you can add the cache manually to your `nix.conf` file. Simply add the following two configurations: +```conf +extra-substituters = https://clash-lang.cachix.org +extra-trusted-public-keys = clash-lang.cachix.org-1:/2N1uka38B/heaOAC+Ztd/EWLmF0RLfizWgC5tamCBg= +``` +If a project specific cache is preferred, using a `flake.nix` with the following will only make the cache active for the specific project of the flake: +```nix +{ + nixConfig = { + extra-substituters = [ "https://clash-lang.cachix.org" ]; + extra-trusted-public-keys = [ "clash-lang.cachix.org-1:/2N1uka38B/heaOAC+Ztd/EWLmF0RLfizWgC5tamCBg=" ]; + }; + description = ...; + inputs = ...; + outputs = ...; +} +``` + # TODO 0.1