diff --git a/.ci/scripts/build-all-dev-envs.sh b/.ci/scripts/build-all-dev-envs.sh new file mode 100755 index 0000000..20802dc --- /dev/null +++ b/.ci/scripts/build-all-dev-envs.sh @@ -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 \ No newline at end of file diff --git a/.github/workflows/build-projects.yaml b/.github/workflows/build-projects.yaml new file mode 100644 index 0000000..8708a63 --- /dev/null +++ b/.github/workflows/build-projects.yaml @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 42a8e2a..a15a967 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/project-flakes/complement/default.nix b/project-flakes/complement/default.nix index 29d78ac..989f4f2 100644 --- a/project-flakes/complement/default.nix +++ b/project-flakes/complement/default.nix @@ -1,3 +1,4 @@ +# ci.project-url: https://github.com/matrix-org/complement { pkgs, ... }: { diff --git a/project-flakes/element-web/default.nix b/project-flakes/element-web/default.nix index 61d8ef5..c54040d 100644 --- a/project-flakes/element-web/default.nix +++ b/project-flakes/element-web/default.nix @@ -1,3 +1,4 @@ +# ci.project-url: https://github.com/vector-im/element-web { pkgs, ... }: { diff --git a/project-flakes/synapse/default.nix b/project-flakes/synapse/default.nix index 5720200..2191ec7 100644 --- a/project-flakes/synapse/default.nix +++ b/project-flakes/synapse/default.nix @@ -1,3 +1,4 @@ +# ci.project-url: https://github.com/matrix-org/synapse { pkgs, ... }: { diff --git a/project-flakes/sytest/default.nix b/project-flakes/sytest/default.nix index 017ec67..07af257 100644 --- a/project-flakes/sytest/default.nix +++ b/project-flakes/sytest/default.nix @@ -1,3 +1,4 @@ +# ci.project-url: https://github.com/matrix-org/sytest { pkgs, ... }: {