summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Mühlbacher <tmuehlbacher@posteo.net>2025-03-31 14:35:05 +0000
committerKent Overstreet <kent.overstreet@linux.dev>2025-03-31 12:54:46 -0400
commitea5bdadabd9262f63f0fa3761388214e554e0ada (patch)
treecd16f8ef79f14d9fcde9fd24768736ee4d3339bc
parent66c943be6caf033c2992c7e4cf99a35e0b1460c1 (diff)
chore(nix): structure github CI nix flake checks
Makes it way easier to identify CI failures for people who try to use github for contributions. Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--.github/workflows/nix-flake.yml41
-rw-r--r--flake.lock21
-rw-r--r--flake.nix89
3 files changed, 100 insertions, 51 deletions
diff --git a/.github/workflows/nix-flake.yml b/.github/workflows/nix-flake.yml
index 4dfb6453..91d9b27e 100644
--- a/.github/workflows/nix-flake.yml
+++ b/.github/workflows/nix-flake.yml
@@ -1,22 +1,31 @@
-name: "Nix-Tests"
+name: Nix Flake actions
+
on:
pull_request:
push:
+
jobs:
- nix-flake-check:
+ nix-matrix:
runs-on: ubuntu-latest
+ outputs:
+ matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- - uses: actions/checkout@v4
- - uses: cachix/install-nix-action@v27
- with:
- extra_nix_config: |
- experimental-features = nix-command flakes
- access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- - uses: cachix/cachix-action@v15
- with:
- name: bcachefs-tools
- # If you chose API tokens for write access OR if you have a private cache
- authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- - run: nix flake show
- - run: nix flake check --print-build-logs
- - run: nix build --print-build-logs
+ - uses: actions/checkout@v4
+ - uses: cachix/install-nix-action@v30
+ - id: set-matrix
+ name: Generate Nix Matrix
+ run: |
+ set -Eeu
+ matrix="$(nix eval --json '.#githubActions.matrix')"
+ echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
+
+ nix-build:
+ name: ${{ matrix.name }} (${{ matrix.system }})
+ needs: nix-matrix
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}}
+ steps:
+ - uses: actions/checkout@v4
+ - uses: cachix/install-nix-action@v30
+ - run: nix build -L '.#${{ matrix.attr }}'
diff --git a/flake.lock b/flake.lock
index c8ea8d15..0a9b2b85 100644
--- a/flake.lock
+++ b/flake.lock
@@ -49,6 +49,26 @@
"type": "github"
}
},
+ "nix-github-actions": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1737420293,
+ "narHash": "sha256-F1G5ifvqTpJq7fdkT34e/Jy9VCyzd5XfJ9TO8fHhJWE=",
+ "owner": "nix-community",
+ "repo": "nix-github-actions",
+ "rev": "f4158fa080ef4503c8f4c820967d946c2af31ec9",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-community",
+ "repo": "nix-github-actions",
+ "type": "github"
+ }
+ },
"nixpkgs": {
"locked": {
"lastModified": 1742422364,
@@ -85,6 +105,7 @@
"crane": "crane",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
+ "nix-github-actions": "nix-github-actions",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay",
"treefmt-nix": "treefmt-nix"
diff --git a/flake.nix b/flake.nix
index 1200a3b9..79ebfb94 100644
--- a/flake.nix
+++ b/flake.nix
@@ -22,6 +22,11 @@
url = "github:edolstra/flake-compat";
flake = false;
};
+
+ nix-github-actions = {
+ url = "github:nix-community/nix-github-actions";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
};
outputs =
@@ -33,6 +38,7 @@
crane,
rust-overlay,
flake-compat,
+ nix-github-actions,
}:
let
systems = nixpkgs.lib.filter (s: nixpkgs.lib.hasSuffix "-linux" s) nixpkgs.lib.systems.flakeExposed;
@@ -40,6 +46,13 @@
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.treefmt-nix.flakeModule ];
+ flake = {
+ githubActions = nix-github-actions.lib.mkGithubMatrix {
+ # github actions supports fewer architectures
+ checks = nixpkgs.lib.getAttrs [ "aarch64-linux" "x86_64-linux" ] self.checks;
+ };
+ };
+
inherit systems;
perSystem =
@@ -225,49 +238,55 @@
default = config.packages.${name};
};
- checks.cargo-clippy = common.craneLib.cargoClippy (
- common.args
- // {
- inherit (common) cargoArtifacts;
- cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
- }
- );
-
- # we have to build our own `craneLib.cargoTest`
- checks.cargo-test = common.craneLib.mkCargoDerivation (
- common.args
- // {
- inherit (common) cargoArtifacts;
- doCheck = true;
-
- enableParallelChecking = true;
-
- pnameSuffix = "-test";
- buildPhaseCargoCommand = "";
- checkPhaseCargoCommand = ''
- make ''${enableParallelChecking:+-j''${NIX_BUILD_CORES}} $makeFlags libbcachefs.a
- cargo test --profile release -- --nocapture
- '';
- }
- );
+ checks = {
+ inherit (config.packages)
+ bcachefs-tools
+ bcachefs-tools-fuse
+ bcachefs-tools-fuse-i686-linux
+ ;
- # cargo clippy with the current minimum supported rust version
- # according to Cargo.toml
- checks.msrv =
- let
- rustVersion = cargoToml.package.rust-version;
- common = pkgs.callPackage mkCommon { inherit crane rustVersion; };
- in
- common.craneLib.cargoClippy (
+ cargo-clippy = common.craneLib.cargoClippy (
common.args
// {
- pname = "msrv";
inherit (common) cargoArtifacts;
cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
}
);
- checks."32-bit" = config.packages."${cargoToml.package.name}-i686-linux";
+ # we have to build our own `craneLib.cargoTest`
+ cargo-test = common.craneLib.mkCargoDerivation (
+ common.args
+ // {
+ inherit (common) cargoArtifacts;
+ doCheck = true;
+
+ enableParallelChecking = true;
+
+ pnameSuffix = "-test";
+ buildPhaseCargoCommand = "";
+ checkPhaseCargoCommand = ''
+ make ''${enableParallelChecking:+-j''${NIX_BUILD_CORES}} $makeFlags libbcachefs.a
+ cargo test --profile release -- --nocapture
+ '';
+ }
+ );
+
+ # cargo clippy with the current minimum supported rust version
+ # according to Cargo.toml
+ msrv =
+ let
+ rustVersion = cargoToml.package.rust-version;
+ common = pkgs.callPackage mkCommon { inherit crane rustVersion; };
+ in
+ common.craneLib.cargoClippy (
+ common.args
+ // {
+ pname = "msrv";
+ inherit (common) cargoArtifacts;
+ cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
+ }
+ );
+ };
devShells.default = pkgs.mkShell {
inputsFrom = [