From 41ba43a33d59cfd171acdfc474ca7ad8c5a6c8df Mon Sep 17 00:00:00 2001 From: zimbatm Date: Mon, 19 Sep 2022 16:59:49 +0200 Subject: [PATCH 1/3] 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 2ecd28c4..03439a03 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 00000000..f16e2924 --- /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}; + }; + + }; +} From 09bc19757cb23656fb1765b873193dee1c81112a Mon Sep 17 00:00:00 2001 From: Jonas Chevalier Date: Tue, 20 Sep 2022 15:53:47 +0200 Subject: [PATCH 2/3] Update modules/formatter.nix Co-authored-by: Robert Hensing --- modules/formatter.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/formatter.nix b/modules/formatter.nix index f16e2924..3f19bc49 100644 --- a/modules/formatter.nix +++ b/modules/formatter.nix @@ -28,7 +28,7 @@ in _file = ./formatter.nix; options = { packages = mkOption { - type = types.package; + type = types.nullOr types.package; default = null; description = '' A package used by nix fmt. From d6fdbbca37d1c446dca3186acb90a86db3dcc38c Mon Sep 17 00:00:00 2001 From: Jonas Chevalier Date: Tue, 20 Sep 2022 15:53:52 +0200 Subject: [PATCH 3/3] Update modules/formatter.nix Co-authored-by: Robert Hensing --- modules/formatter.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/formatter.nix b/modules/formatter.nix index 3f19bc49..a63a9bab 100644 --- a/modules/formatter.nix +++ b/modules/formatter.nix @@ -27,7 +27,7 @@ in perSystem = mkPerSystemOption ({ config, ... }: { _file = ./formatter.nix; options = { - packages = mkOption { + formatter = mkOption { type = types.nullOr types.package; default = null; description = ''