mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2025-03-28 02:37:12 +00:00
Generalize transposed attributes
This commit is contained in:
parent
79b42f0842
commit
6269836424
7 changed files with 62 additions and 49 deletions
|
@ -15,6 +15,7 @@
|
|||
./modules/overlays.nix
|
||||
./modules/packages.nix
|
||||
./modules/perSystem.nix
|
||||
./modules/transposition.nix
|
||||
./modules/withSystem.nix
|
||||
];
|
||||
}
|
||||
|
|
|
@ -81,15 +81,6 @@ in
|
|||
|
||||
};
|
||||
config = {
|
||||
flake.apps =
|
||||
mapAttrs
|
||||
(k: v: v.apps)
|
||||
config.allSystems;
|
||||
|
||||
perInput = system: flake:
|
||||
optionalAttrs (flake?apps.${system}) {
|
||||
apps = flake.apps.${system};
|
||||
};
|
||||
|
||||
transposition.apps = { };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,15 +39,6 @@ in
|
|||
|
||||
};
|
||||
config = {
|
||||
flake.checks =
|
||||
mapAttrs
|
||||
(k: v: v.checks)
|
||||
config.allSystems;
|
||||
|
||||
perInput = system: flake:
|
||||
optionalAttrs (flake?checks.${system}) {
|
||||
checks = flake.checks.${system};
|
||||
};
|
||||
|
||||
transposition.checks = { };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -40,14 +40,6 @@ in
|
|||
});
|
||||
};
|
||||
config = {
|
||||
flake.devShells =
|
||||
mapAttrs
|
||||
(k: v: v.devShells)
|
||||
config.allSystems;
|
||||
|
||||
perInput = system: flake:
|
||||
optionalAttrs (flake?devShells.${system}) {
|
||||
devShells = flake.devShells.${system};
|
||||
};
|
||||
transposition.devShells = { };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -38,15 +38,6 @@ in
|
|||
};
|
||||
|
||||
config = {
|
||||
flake.legacyPackages =
|
||||
mapAttrs
|
||||
(k: v: v.legacyPackages)
|
||||
config.allSystems;
|
||||
|
||||
perInput = system: flake:
|
||||
optionalAttrs (flake?legacyPackages.${system}) {
|
||||
legacyPackages = flake.legacyPackages.${system};
|
||||
};
|
||||
|
||||
transposition.legacyPackages = { };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -40,15 +40,6 @@ in
|
|||
});
|
||||
};
|
||||
config = {
|
||||
flake.packages =
|
||||
mapAttrs
|
||||
(k: v: v.packages)
|
||||
config.allSystems;
|
||||
|
||||
perInput = system: flake:
|
||||
optionalAttrs (flake?packages.${system}) {
|
||||
packages = flake.packages.${system};
|
||||
};
|
||||
|
||||
transposition.packages = { };
|
||||
};
|
||||
}
|
||||
|
|
56
modules/transposition.nix
Normal file
56
modules/transposition.nix
Normal file
|
@ -0,0 +1,56 @@
|
|||
{ config, lib, flake-parts-lib, ... }:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
filterAttrs
|
||||
mapAttrs
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
inherit (flake-parts-lib)
|
||||
mkSubmoduleOptions
|
||||
mkPerSystemOption
|
||||
;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
transposition = lib.mkOption {
|
||||
description = ''
|
||||
A helper that defines transposed attributes in the flake outputs.
|
||||
|
||||
Transposition is the operation that swaps the indices of a data structure.
|
||||
Here it refers specifically to the transposition between
|
||||
|
||||
<literal>
|
||||
perSystem: .''${system}.''${attribute}
|
||||
outputs: .''${attribute}.''${system}
|
||||
</literal>
|
||||
|
||||
It also defines the reverse operation in <option>perInput</option>.
|
||||
'';
|
||||
type =
|
||||
types.lazyAttrsOf
|
||||
(types.submoduleWith { modules = [ ]; });
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
flake =
|
||||
lib.mapAttrs
|
||||
(attrName: attrConfig:
|
||||
mapAttrs
|
||||
(system: v: v.${attrName})
|
||||
config.allSystems
|
||||
)
|
||||
config.transposition;
|
||||
|
||||
perInput =
|
||||
system: flake:
|
||||
mapAttrs
|
||||
(attrName: attrConfig: flake.${attrName}.${system})
|
||||
(filterAttrs
|
||||
(attrName: attrConfig: flake?${attrName}.${system})
|
||||
config.transposition
|
||||
);
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue