Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add formatter schema #56

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions all-modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
./modules/darwinModules.nix
./modules/devShells.nix
./modules/flake.nix
./modules/formatter.nix
./modules/legacyPackages.nix
./modules/moduleWithSystem.nix
./modules/nixosConfigurations.nix
Expand Down
55 changes: 55 additions & 0 deletions modules/formatter.nix
Original file line number Diff line number Diff line change
@@ -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 {
zimbatm marked this conversation as resolved.
Show resolved Hide resolved
type = types.package;
zimbatm marked this conversation as resolved.
Show resolved Hide resolved
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};
};

};
}