diff --git a/.ci/attic-auth.sh b/.ci/attic-auth.sh new file mode 100644 index 0000000..63aab31 --- /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 new file mode 100644 index 0000000..45a2098 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,82 @@ +name: CI + +# Trigger the workflow on all pushes +on: + push: + branches: + - main + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + packages: + name: Push package to local 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 }} + + - 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 }}) + + - 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 }} | cachix push clash-lang + + devshells: + name: Push Nix developer shell to local 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 a dependencies are already cached, we can simply re-use 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 .#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 + 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 + diff --git a/README.md b/README.md index 9148c93..b4678ba 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,47 @@ You can also look through Adam Walker's excellent list of [prebuilt Clash circui # Nix This project exposes several Nix flake outputs. Most notably the `clash-cores` package, exposed individually or as an overlay (which you need to apply on top of clash-compiler). +## Usage + Contributing to `clash-cores` can be done via the developer shell exposed by the Nix flake. Open a terminal and type: `nix develop`. Optionally a specific GHC version can be selected as well as a `-minimal` or `-full` version. The `-minimal` shell does **NOT** contain the Haskell Language Server, whilst the `-full` shell does. When using the developer shell, do not forget to remove the `cabal.project` file. This file contains a package source and Cabal prioritizes local package sources over Nix sources. Removing the `cabal.project` file should work fine when developing with Nix. +Compiling Clash and all dependencies related to it may take a long time. To remidy long compilation times, you can make use of the publically available cache on Cachix: + +### Cachix (binary cache) + +Cachix contains all commits on the main branch of `clash-cores` since the cache has been setup. It is recommended to add the publically available cachix cache to your project/computer to minimize the amount of time manually compiling Clash related dependencies. + +To make use of Cachix, you can (temporarily) install the CLI: + +`nix shell nixpkgs#cachix` + +And then run: + +`cachix use clash-lang` + +And that's it! Whenever you run a Nix command, it will look if there are precompiled binaries available in Cachix. + +Alternatively, you can add it to your `nix.conf` manually without installing Cachix. This file is usually located under `~/.config/nix`, you can create it if it does not exist: +```conf +extra-substituters = https://clash-lang.cachix.org +extra-trusted-public-keys = clash-lang.cachix.org-1:/2N1uka38B/heaOAC+Ztd/EWLmF0RLfizWgC5tamCBg= +``` + +If you would like to use the substituter for your local projects only, then it is possible to add it as part of your `flake.nix` like thus: +```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 = ...; +} +``` + +## As a dependency + You can also add this project as a Nix-dependency. This project depends on `clash-compiler`, the recommended way to add this to your project as a Nix dependency is as follows: First add `clash-compiler` and `clash-cores` to your flake inputs: