Generating several attribute sets per system for a flake

I would like to generate a flake top level that is defined like this (very simplified to try and focus on my specific question) mapping doesn’t seem to work very well primarily because it’s return result is a list of containing all the variations instead of an actual attribute set.

mkFlake inputs {
 systems = [ "x86_64-linux" "another-architecture" ];
 devShells.default = pkgs: pkgs.mkShellNoCC {
    buildInputs = with pkgs; [ alejandra nixd ] ;
 };
}

But it’s actual return result is this

{
  devShells.86_64-linux.default = { ... };
  devShells.another-architecture = { ... };
}

Here is my current mkFlake implementation, I’ve stripped it down to just focus on this specific question initially.

{lib}: {
  mkFlake = {
    self,
    nixpkgs ? inputs.nixpkgs,
    ...
  } @ inputs: {
    devShells ? {},
    systems,
    ...
  } @ flake: let
    b = builtins;

    inherit (lib.attrsets) mapAttrs filterAttrs;
    perSystemAttributes = b.map (system: let
      pkgs = import nixpkgs {
        inherit system;
      };
    in
      filterAttrs (_: v: v.${system} != {}) {
        devShells.${system} = mapAttrs (_: v: v pkgs) devShells;
      }) systems;
  in
    perSystemAttributes;
}

As additional info, the reason I’m not just using a pattern like forEachSystem as the definition will be like, and I only want to instiate pkgs once, so something like devShells = forEachSystem (system: pkgs: …)isn’t ideal.

{
  devShells.${system} = mapAttrs (_: v: v pkgs) devShells;
  packages.${system} = packagesFromDirectoryRecursive {
    callPackages = callPackageWith pkgs;
    directory = packages; # ./packages
  };
}

I’ve found a solution to this

    perSystemAttributes = fn: b.foldl' recursiveUpdate {} (map fn systems);
    in (perSystemAttributes (system: let
      pkgs = import nixpkgs { inherit system; };
    in {
      devShells.${system} = mapAttrs (_: v: v pkgs) devShells;
    });