diff --git a/devenv.lock b/devenv.lock index 60bb274a25..873dc8c623 100644 --- a/devenv.lock +++ b/devenv.lock @@ -246,6 +246,9 @@ "git-hooks": "git-hooks", "nix": "nix", "nixpkgs": "nixpkgs_2", + "pre-commit-hooks": [ + "git-hooks" + ], "rust-overlay": "rust-overlay" } }, @@ -271,4 +274,4 @@ }, "root": "root", "version": 7 -} \ No newline at end of file +} diff --git a/flake-module.nix b/flake-module.nix index a6f619c7c9..e8bdc35b68 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -44,8 +44,45 @@ devenvFlake: { flake-parts-lib, lib, inputs, ... }: { ''; default = { }; }; + options.devenv.git-hooks = { + enable = lib.mkOption { + type = lib.types.bool; + default = (inputs.git-hooks or null) != null; + description = "Enable git-hooks git-hooks."; + }; + shell = lib.mkOption { + type = lib.types.str; + default = "default"; + description = "Shell name to read git-hooks git-hooks configuration from."; + }; + }; + options.devenv.treefmt = { + enable = lib.mkOption { + type = lib.types.bool; + default = (inputs.treefmt-nix or null) != null; + description = "Enable treefmt."; + }; + shell = lib.mkOption { + type = lib.types.str; + default = "default"; + description = "Shell name to read treefmt configuration from."; + }; + }; + config.devShells = lib.mapAttrs (_name: devenv: devenv.shell) config.devenv.shells; + config.pre-commit.settings = + if config.devenv.git-hooks.enable && builtins.hasAttr config.devenv.git-hooks.shell config.devenv.shells then + config.devenv.shells.${config.devenv.git-hooks.shell}.git-hooks + else + { }; + + config.treefmt = + if config.devenv.treefmt.enable && builtins.hasAttr config.devenv.treefmt.shell config.devenv.shells then + config.devenv.shells.${config.devenv.treefmt.shell}.treefmt.config + else + { }; + # Deprecated packages # These were used to wire up commands in the devenv shim and are no longer necessary. config.packages =