Skip to content

Commit

Permalink
flake template checks: Reimplement as top-level flake checks
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Nov 8, 2024
1 parent 38f7083 commit 9a4c190
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/nix-github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,10 @@ jobs:
with:
name: adisbladis
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

- name: Flake show hello-world
run: nix flake show --no-update-lock-file --override-input uv2nix . --reference-lock-file ./flake.lock ./templates/hello-world
- name: Build hello-world template
run: nix build -L --no-update-lock-file --override-input uv2nix . --reference-lock-file ./flake.lock ./templates/hello-world ./templates/hello-world#devShells.x86_64-linux.uv2nix ./templates/hello-world#devShells.x86_64-linux.impure

- name: Show testing template
run: nix flake show --no-update-lock-file --override-input uv2nix . --reference-lock-file ./flake.lock ./templates/testing
- name: Build testing template
run: nix build -L --no-update-lock-file --override-input uv2nix . --reference-lock-file ./flake.lock ./templates/testing#default ./templates/testing#full ./templates/testing#checks.x86_64-linux.pytest ./templates/testing#devShells.x86_64-linux.default

collect:
runs-on: ubuntu-latest
Expand Down
41 changes: 41 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,47 @@
inherit pyproject-nix pkgs lib;
uv2nix = self.lib;
}
//
# Test flake templates
(
let

inherit (builtins) mapAttrs functionArgs;

# Call a nested flake with the inputs from this one.
callFlake =
path:
let
flake' = import (path + "/flake.nix");
args = mapAttrs (name: _: inputs'.${name}) (functionArgs flake'.outputs);

flake = flake'.outputs args;

inputs' = inputs // {
uv2nix = self;
self = flake;
};
in
flake;

in
lib.listToAttrs (
lib.concatLists (
lib.mapAttrsToList (
template: _:
let
flake = callFlake (./templates + "/${template}");
mkChecks =
prefix: attr:
lib.mapAttrsToList (check: drv: lib.nameValuePair "template-${template}-${prefix}-${check}" drv) (
flake.${attr}.${system} or { }
);
in
mkChecks "check" "checks" ++ mkChecks "package" "packages" ++ mkChecks "devShell" "devShells"
) (builtins.readDir ./templates)
)
)
)
// {
formatter =
pkgs.runCommand "fmt-check"
Expand Down

0 comments on commit 9a4c190

Please sign in to comment.