mirror of
https://github.com/hercules-ci/flake-parts.git
synced 2025-03-31 04:04:55 +00:00
add formatter schema
This is needed for flakes that want to support `nix fmt`
This commit is contained in:
parent
89cce5852d
commit
41ba43a33d
2 changed files with 56 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
./modules/darwinModules.nix
|
./modules/darwinModules.nix
|
||||||
./modules/devShells.nix
|
./modules/devShells.nix
|
||||||
./modules/flake.nix
|
./modules/flake.nix
|
||||||
|
./modules/formatter.nix
|
||||||
./modules/legacyPackages.nix
|
./modules/legacyPackages.nix
|
||||||
./modules/moduleWithSystem.nix
|
./modules/moduleWithSystem.nix
|
||||||
./modules/nixosConfigurations.nix
|
./modules/nixosConfigurations.nix
|
||||||
|
|
55
modules/formatter.nix
Normal file
55
modules/formatter.nix
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
{ config, lib, flake-parts-lib, ... }:
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
filterAttrs
|
||||||
|
mapAttrs
|
||||||
|
mkOption
|
||||||
|
optionalAttrs
|
||||||
|
types
|
||||||
|
;
|
||||||
|
inherit (flake-parts-lib)
|
||||||
|
mkSubmoduleOptions
|
||||||
|
mkPerSystemOption
|
||||||
|
;
|
||||||
|
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 = {
|
||||||
|
packages = mkOption {
|
||||||
|
type = 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};
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue