From 41ba43a33d59cfd171acdfc474ca7ad8c5a6c8df Mon Sep 17 00:00:00 2001 From: zimbatm Date: Mon, 19 Sep 2022 16:59:49 +0200 Subject: [PATCH] add formatter schema This is needed for flakes that want to support `nix fmt` --- all-modules.nix | 1 + modules/formatter.nix | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 modules/formatter.nix diff --git a/all-modules.nix b/all-modules.nix index 2ecd28c..03439a0 100644 --- a/all-modules.nix +++ b/all-modules.nix @@ -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 diff --git a/modules/formatter.nix b/modules/formatter.nix new file mode 100644 index 0000000..f16e292 --- /dev/null +++ b/modules/formatter.nix @@ -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 nix fmt. + ''; + }; + }; + + perSystem = mkPerSystemOption ({ config, ... }: { + _file = ./formatter.nix; + options = { + packages = mkOption { + type = types.package; + default = null; + description = '' + A package used by nix fmt. + ''; + }; + }; + }); + }; + 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}; + }; + + }; +}