Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use nix-eval-jobs #19

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 55 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,67 @@
name: CI

on:
push:
branches: [main]
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
flake:
name: Flake checks
eval:
name: Evaluate hydraJobs

runs-on: ubuntu-latest

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

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

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v16
- name: Setup Nix cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Run checks
uses: cachix/install-nix-action@v27

- name: Generate matrix
id: eval
run: |
nix flake check --print-build-logs --show-trace
echo "matrix=$(nix run .#generate-actions-matrix)" >> "$GITHUB_OUTPUT"

build:
name: Build ${{ matrix.attr }}
needs: [ eval ]

strategy:
fail-fast: false
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 Cachix
uses: cachix/cachix-action@v15
with:
name: prismlauncher
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}

- name: Build ${{ matrix.attr }}
run: |
nix build --print-build-logs '${{ matrix.drvPath }}^*'

# Cumulative job for all of the above
release-gate:
name: Release Gate
needs: [ build ]

runs-on: ubuntu-latest

steps:
- name: Exit with error
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
109 changes: 109 additions & 0 deletions ci.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
self,
nixpkgs,
flake-utils,
...
}:

let
inherit (nixpkgs) lib;
in

flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};

mkCheck =
name: deps: script:
pkgs.runCommand "check-${name}" { nativeBuildInputs = deps; } ''
${script}
touch $out
'';
in
{
apps = {
generate-actions-matrix = {
type = "app";
program = lib.getExe (
pkgs.writeShellApplication {
name = "generate-actions-matrix";

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

text = ''
filter='
{
include: [
.[] | {
attr,
drvPath,
os: (
if .system == "x86_64-linux" then
"ubuntu-latest"
elif .system == "x86_64-darwin" then
"macos-13"
elif .system == "aarch64-darwin" then
"macos-latest"
else
null
end
)
}
]
}
'

gcroot_dir="$(mktemp -d)"
trap 'rm -rf "$gcroot_dir"' EXIT

eval_jobs_args=(
--flake '${self.outPath}#hydraJobs'
--gc-roots-dir "$gcroot_dir"
--option allow-import-from-derivation false
--show-trace
)

jq_args=(
--compact-output
--slurp
"$filter"
)

nix-eval-jobs "''${eval_jobs_args[@]}" | jq "''${jq_args[@]}"
'';
}
);
};
};

checks = {
deadnix = mkCheck "deadnix" [ pkgs.deadnix ] "deadnix --fail ${self}";
statix = mkCheck "statix" [ pkgs.statix ] "statix check ${self}";
};
}
)
// {
hydraJobs =
let
ciSystem = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${ciSystem};

nixosConfigurations = lib.mapAttrs (lib.const (
configuration: configuration.config.system.build.toplevel
)) self.nixosConfigurations;
in
{
checks = lib.recurseIntoAttrs self.checks.${ciSystem};
devShells = lib.recurseIntoAttrs self.devShells.${ciSystem};

nixosConfigurations = lib.recurseIntoAttrs {
# TODO: Inherit nixosConfigurations from above when we can actually
# build ARM configurations in GHA
andesite = builtins.deepSeq nixosConfigurations.andesite.drvPath pkgs.emptyFile;
};
};
}
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
flake-utils.lib.meld inputs [
./machines/andesite
./modules
./ci.nix
./development.nix
];
}
2 changes: 0 additions & 2 deletions machines/andesite/disks.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ inputs, ... }:
let
in
{
imports = [
inputs.impermanence.nixosModules.impermanence
Expand Down
1 change: 0 additions & 1 deletion modules/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{ ... }:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed

{
nixosModules = {
from-facts = ./from-facts.nix;
Expand Down
2 changes: 1 addition & 1 deletion modules/from-facts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ in
config = mkIf (cfg.file != null) {
networking = {
hostName = cfg.data.hostname;
domain = cfg.data.domain;
inherit (cfg.data) domain;
interfaces.${cfg.interface} = {
useDHCP = true;
ipv6.addresses = [
Expand Down
19 changes: 10 additions & 9 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{ ... }:
{
projectRootFile = "flake.nix";

programs.actionlint.enable = true;
programs.hclfmt.enable = true;
programs.just.enable = true;
programs.mdformat.enable = true;
programs.nixfmt.enable = true;
programs.shfmt.enable = true;
programs.terraform.enable = true;
programs.yamlfmt.enable = true;
programs = {
actionlint.enable = true;
hclfmt.enable = true;
just.enable = true;
mdformat.enable = true;
nixfmt.enable = true;
shfmt.enable = true;
terraform.enable = true;
yamlfmt.enable = true;
};

settings.global.excludes = [
"**.age"
Expand Down