Skip to content

Commit

Permalink
Add GitHub action to build project flakes
Browse files Browse the repository at this point in the history
Build all known project flakes on each push/PR.
  • Loading branch information
anoadragon453 committed Oct 26, 2023
1 parent d6494b2 commit 819aa1a
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .ci/scripts/build-all-dev-envs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env sh
PROJECT_FLAKES_DIR="project-flakes"

# Print lines of this script as they're executed, and exit on any failure.
set -ex

# Loop through each sub-directory in 'project-flakes'
for project in "$PROJECT_FLAKES_DIR"/*/ ; do
# Remove the trailing '/'
project=${project%*/}
# Extract the project name
project=${project##*/}
# Echo the project name for logging
echo "Running nix develop on project: $project"
# Extract the git URL of the project. We often need the files of the
# project locally in order to build the development shell:
url=$(grep "^# ci.project-url:" "$PROJECT_FLAKES_DIR/$project/default.nix" | awk -F': ' '{print $2}')
echo "Cloning repo: $url"
# Clone the project to a directory with the same name.
git clone --depth 1 -q "$url" "$project"
# Enter the project directory.
cd "$project"
# Show the generated outputs of the flake.
nix flake show ..
# Attempt to build and enter the development environment,
# then immediately exit the built shell.
nix develop --impure ..#"$project" -c "true"
# Leave the project directory.
cd ..
# Delete the project directory.
rm -rf "$project"
done
13 changes: 13 additions & 0 deletions .github/workflows/build-projects.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: "Build project flakes"
on:
pull_request:
push:
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: DeterminateSystems/nix-installer-action@bc7b19257469c8029b46f45ac99ecc11156c8b2d # v6
- uses: DeterminateSystems/magic-nix-cache-action@8a218f9e264e9c3803c9a1ee1c30d8e4ab55be63 # v2
- run: .ci/scripts/build-all-dev-envs.sh
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,38 @@ provided by this flake's outputs:
Note that `composeShell` takes a list as an argument. You can provide multiple
project names in this list, and `composeShell` will build a development shell
dependencies from all projects combined together.

## Development

To add a new project to this repo, create a directory with its name under
[`project-flakes/`](project-flakes/), and inside of it create a `default.nix`
file. This file is not a flake itself, but a function written in the nix
language that returns a devenv module. A basic example of a `default.nix`:

```nix
# The below line tells CI where to clone the project from when testing
# the build of your devenv module. Any git URL is supported.
# ci.project-url: https://github.com/foo/bar
# Function arguments.
{ pkgs, ... }:
# The returned devenv module attribute set.
{
# Set some devenv options...
packages = with pkgs; [ sqlite mdbook ]
languages.c.enable = true;
# ...
}
```

See [devenv's flake guide](https://devenv.sh/guides/using-with-flakes/) for an
introduction; the attribute sets returned by your function are what get slotted
into the `modules` attribute under `devenv.lib.mkShell`. [`flake.nix`](flake.nix)
is where all that happens.

[Devenv's reference](https://devenv.sh/reference/options/) has a list of all
available options you can specify.

The [Nix Language basics](https://zero-to-nix.com/concepts/nix-language) is a
recommended read.
1 change: 1 addition & 0 deletions project-flakes/complement/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ci.project-url: https://github.com/matrix-org/complement
{ pkgs, ... }:

{
Expand Down
1 change: 1 addition & 0 deletions project-flakes/element-web/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ci.project-url: https://github.com/vector-im/element-web
{ pkgs, ... }:

{
Expand Down
1 change: 1 addition & 0 deletions project-flakes/synapse/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ci.project-url: https://github.com/matrix-org/synapse
{ pkgs, ... }:

{
Expand Down
1 change: 1 addition & 0 deletions project-flakes/sytest/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ci.project-url: https://github.com/matrix-org/sytest
{ pkgs, ... }:

{
Expand Down

0 comments on commit 819aa1a

Please sign in to comment.