Skip to content

Commit

Permalink
ci: build package set with nix-eval-jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
getchoo committed Nov 26, 2024
1 parent 5de873e commit 6923d5e
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 2 deletions.
60 changes: 59 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,55 @@ on:
workflow_dispatch:

jobs:
test:
eval:
name: Evaluate packages

runs-on: ubuntu-latest

outputs:
matrix: ${{ steps.evaluate.outputs.matrix }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@V27

- name: Setup cache
uses: DeterminateSystems/magic-nix-cache-action@v8

- name: Evaluate & output matrix
id: evaluate
run: |
echo "matrix=$(nix run .#eval-matrix -- 'hydraJobs.packages')" >> "$GITHUB_OUTPUT"
packages:
name: Build packages.${{ matrix.attr }}
needs: eval

strategy:
matrix: ${{ fromJSON(needs.eval.outputs.matrix) }}

runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@V27

- name: Setup cache
uses: DeterminateSystems/magic-nix-cache-action@v8

- name: Run build
run: |
nix build --print-build-logs --show-trace '.#${{ matrix.attr }}'
modules:
name: Test Modules
needs: packages

strategy:
fail-fast: false
Expand All @@ -40,3 +87,14 @@ jobs:
github:Mic92/nix-fast-build -- \
--no-nom \
--flake ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem)"
release-gate:
name: Release Gate
needs: [ eval, packages, modules ]

runs-on: ubuntu-latest

steps:
- name: Exit with error
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
result
result-*
repl-result-*

gcroot/
80 changes: 80 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,69 @@
in
{
apps = {
eval-matrix = {
type = "app";
program = lib.getExe (
pkgs.writeShellApplication {
name = "nix-eval-matrix";

runtimeInputs = [
pkgs.jq
pkgs.nix-eval-jobs
];

text = ''
usage="Usage: $0 <attribute>"
attribute="''${1:-}"
if [ -z "$attribute" ]; then
echo -n "$usage"
exit 1
fi
filter='
{
includes: [
.[] | {
attr,
system,
os: (
if .system == "x86_64-linux" then
"ubuntu-latest"
elif .system == "aarch64-darwin" then
"macos-latest"
elif .system == "x86_64-darwin" then
"macos-13"
else
null
end
)
}
]
}
'
gcroot_dir="$(mktemp -d)"
trap 'rm -r "$gcroot_dir"' EXIT
eval_jobs_args=(
"--gc-roots-dir" "$gcroot_dir"
"--force-recurse"
"--flake" "${self.outPath}#$attribute"
)
jq_args=(
"--compact-output"
"--slurp"
"$filter"
)
nix-eval-jobs "''${eval_jobs_args[@]}" | jq "''${jq_args[@]}"
'';
}
);
};

serve = {
type = "app";
program = lib.getExe self.packages.${system}.site.serve;
Expand Down Expand Up @@ -149,6 +212,23 @@
))

{
hydraJobs =
let
supportedSystems = [
"x86_64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
in
{
checks = lib.getAttrs [
"x86_64-linux"
"aarch64-darwin"
] self.checks;

packages = lib.getAttrs supportedSystems self.packages;
};

homeManagerModules.catppuccin = mkModule {
type = "homeManager";
file = ./modules/home-manager;
Expand Down

0 comments on commit 6923d5e

Please sign in to comment.