Skip to content

Commit

Permalink
Merge #56
Browse files Browse the repository at this point in the history
56: add formatter schema r=roberth a=zimbatm

This is needed for flakes that want to support `nix fmt`.

Right now it's missing some testing as I didn't find a test framework for it.

Needed by numtide/treefmt#169


Co-authored-by: zimbatm <zimbatm@zimbatm.com>
Co-authored-by: Jonas Chevalier <zimbatm@zimbatm.com>
  • Loading branch information
bors[bot] and zimbatm committed Sep 20, 2022
2 parents 89cce58 + d6fdbbc commit 509193a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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 = {
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};
};

};
}

0 comments on commit 509193a

Please sign in to comment.