From 6a28566db663fe8b185142e0d9cfdb988f6b04a9 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 25 Jun 2024 15:49:39 +0200 Subject: [PATCH] refact: concatMapAttrs -> flatMapAttrs This should be slightly easier to read. We could apply this to all concatMapAttrs calls. --- flake.nix | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index aac45af34..1be9d2fc0 100644 --- a/flake.nix +++ b/flake.nix @@ -58,6 +58,18 @@ "stdenv" ]; + /** + `flatMapAttrs attrs f` applies `f` to each attribute in `attrs` and + merges the results into a single attribute set. + + This can be nested to form a build matrix where all the attributes + generated by the innermost `f` are returned as is. + (Provided that the names are unique.) + + See https://nixos.org/manual/nixpkgs/stable/index.html#function-library-lib.attrsets.concatMapAttrs + */ + flatMapAttrs = attrs: f: lib.concatMapAttrs f attrs; + forAllSystems = lib.genAttrs systems; forAllCrossSystems = lib.genAttrs crossSystems; @@ -319,17 +331,20 @@ # system, we should reenable this. #perlBindings = self.hydraJobs.perlBindings.${system}; } - // lib.concatMapAttrs (nixpkgsPrefix: nixpkgs: - lib.concatMapAttrs (pkgName: pkg: - lib.concatMapAttrs (testName: test: { - # Add "passthru" tests - "${nixpkgsPrefix}${pkgName}-${testName}" = test; - }) pkg.tests or {} - ) nixpkgs.nix-components - ) { + # Add "passthru" tests + // flatMapAttrs { "" = nixpkgsFor.${system}.native; "static-" = nixpkgsFor.${system}.static; } + (nixpkgsPrefix: nixpkgs: + flatMapAttrs nixpkgs.nix-components + (pkgName: pkg: + flatMapAttrs pkg.tests or {} + (testName: test: { + "${nixpkgsPrefix}${pkgName}-${testName}" = test; + }) + ) + ) // devFlake.checks.${system} or {} );