1
0
Fork 0
mirror of https://github.com/hercules-ci/flake-parts.git synced 2024-12-14 11:47:31 +00:00

formatter: Use mkTransposedPerSystemModule

This commit is contained in:
Shea Levy 2022-10-30 07:03:32 -04:00
parent 5e259eb312
commit e7da962abb
No known key found for this signature in database
GPG key ID: 5C0BD6957D86FE27

View file

@ -1,55 +1,21 @@
{ config, lib, flake-parts-lib, ... }:
let
inherit (lib)
filterAttrs
mapAttrs
mkOption
optionalAttrs
types
;
inherit (flake-parts-lib)
mkSubmoduleOptions
mkPerSystemOption
mkTransposedPerSystemModule
;
in
{
options = {
flake = mkSubmoduleOptions {
formatter = mkOption {
type = types.lazyAttrsOf types.package;
default = { };
description = ''
Per system package used by <literal>nix fmt</literal>.
'';
};
};
perSystem = mkPerSystemOption ({ config, ... }: {
_file = ./formatter.nix;
options = {
formatter = mkOption {
type = types.nullOr types.package;
default = null;
description = ''
A package used by <literal>nix fmt</literal>.
'';
};
};
});
};
config = {
flake.formatter =
mapAttrs
(k: v: v.formatter)
(filterAttrs
(k: v: v.formatter != null)
config.allSystems
);
perInput = system: flake:
optionalAttrs (flake?formatter.${system}) {
formatter = flake.formatter.${system};
};
mkTransposedPerSystemModule {
name = "formatter";
option = mkOption {
type = types.nullOr types.package;
default = null;
description = ''
A package used by <literal>nix fmt</literal>.
'';
};
file = ./formatter.nix;
}