From bd4fc8e8c8dc92b37d94754b4e1f42070aca9804 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Mon, 19 Jan 2026 07:32:38 -0300 Subject: [PATCH] Remove flake-parts input --- flake.lock | 30 +------ flake.nix | 29 +++---- maintainers/flake-module.nix | 116 ------------------------- packaging/dev-shell.nix | 12 +-- packaging/pre-commit-hook-settings.nix | 103 ++++++++++++++++++++++ 5 files changed, 127 insertions(+), 163 deletions(-) delete mode 100644 maintainers/flake-module.nix create mode 100644 packaging/pre-commit-hook-settings.nix diff --git a/flake.lock b/flake.lock index b2173f90b34..7c16be58a77 100644 --- a/flake.lock +++ b/flake.lock @@ -16,43 +16,20 @@ "type": "github" } }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1733312601, - "narHash": "sha256-4pDvzqnegAfRkPwO3wmwBhVi/Sye1mzps0zHWYnP88c=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "205b12d8b7cd4802fbcb8e8ef6a0f1408781a4f9", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "git-hooks-nix": { "inputs": { "flake-compat": [], "gitignore": [], "nixpkgs": [ "nixpkgs" - ], - "nixpkgs-stable": [ - "nixpkgs" ] }, "locked": { - "lastModified": 1734279981, - "narHash": "sha256-NdaCraHPp8iYMWzdXAt5Nv6sA3MUzlCiGiR586TCwo0=", + "lastModified": 1767281941, + "narHash": "sha256-6MkqajPICgugsuZ92OMoQcgSHnD6sJHwk8AxvMcIgTE=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "aa9f40c906904ebd83da78e7f328cd8aeaeae785", + "rev": "f0927703b7b1c8d97511c4116eb9b4ec6645a0fa", "type": "github" }, "original": { @@ -109,7 +86,6 @@ "root": { "inputs": { "flake-compat": "flake-compat", - "flake-parts": "flake-parts", "git-hooks-nix": "git-hooks-nix", "nixpkgs": "nixpkgs", "nixpkgs-23-11": "nixpkgs-23-11", diff --git a/flake.nix b/flake.nix index be93ece607e..2ce520cddca 100644 --- a/flake.nix +++ b/flake.nix @@ -11,12 +11,9 @@ }; # dev tooling - inputs.flake-parts.url = "github:hercules-ci/flake-parts"; inputs.git-hooks-nix.url = "github:cachix/git-hooks.nix"; # work around https://github.com/NixOS/nix/issues/7730 - inputs.flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; inputs.git-hooks-nix.inputs.nixpkgs.follows = "nixpkgs"; - inputs.git-hooks-nix.inputs.nixpkgs-stable.follows = "nixpkgs"; # work around 7730 and https://github.com/NixOS/nix/issues/7807 inputs.git-hooks-nix.inputs.flake-compat.follows = ""; inputs.git-hooks-nix.inputs.gitignore.follows = ""; @@ -82,17 +79,17 @@ forAllStdenvs = lib.genAttrs stdenvs; - # We don't apply flake-parts to the whole flake so that non-development attributes - # load without fetching any development inputs. - devFlake = inputs.flake-parts.lib.mkFlake { inherit inputs; } { - imports = [ ./maintainers/flake-module.nix ]; - systems = lib.subtractLists crossSystems systems; - perSystem = - { system, ... }: - { - _module.args.pkgs = nixpkgsFor.${system}.native; + # Pre-commit hooks configuration + preCommitHooksFor = + system: + let + pkgs = nixpkgsFor.${system}.native; + hookSettings = import ./packaging/pre-commit-hook-settings.nix { + inherit pkgs lib; + src = self; }; - }; + in + inputs.git-hooks-nix.lib.${system}.run hookSettings; # Memoize nixpkgs for different platforms for efficiency. nixpkgsFor = forAllSystems ( @@ -333,6 +330,9 @@ # Since the support is only best-effort there, disable the perl # bindings perlBindings = self.hydraJobs.perlBindings.${system}; + + # i686-linux isn't supported by git-hooks.nix + pre-commit = preCommitHooksFor system; } # Add "passthru" tests // @@ -352,7 +352,6 @@ } )).componentTests ) - // devFlake.checks.${system} or { } ); packages = forAllSystems ( @@ -495,7 +494,7 @@ devShells = let - makeShell = import ./packaging/dev-shell.nix { inherit lib devFlake; }; + makeShell = import ./packaging/dev-shell.nix { inherit lib preCommitHooksFor; }; prefixAttrs = prefix: lib.concatMapAttrs (k: v: { "${prefix}-${k}" = v; }); in forAllSystems ( diff --git a/maintainers/flake-module.nix b/maintainers/flake-module.nix deleted file mode 100644 index 414e6c570ab..00000000000 --- a/maintainers/flake-module.nix +++ /dev/null @@ -1,116 +0,0 @@ -{ - lib, - getSystem, - inputs, - ... -}: - -{ - imports = [ - inputs.git-hooks-nix.flakeModule - ]; - - perSystem = - { config, pkgs, ... }: - { - - # https://flake.parts/options/git-hooks-nix#options - pre-commit.settings = { - hooks = { - # Conflicts are usually found by other checks, but not those in docs, - # and potentially other places. - check-merge-conflicts.enable = true; - # built-in check-merge-conflicts seems ineffective against those produced by mergify backports - check-merge-conflicts-2 = { - enable = true; - entry = "${pkgs.writeScript "check-merge-conflicts" '' - #!${pkgs.runtimeShell} - conflicts=false - for file in "$@"; do - if grep --with-filename --line-number -E '^>>>>>>> ' -- "$file"; then - conflicts=true - fi - done - if $conflicts; then - echo "ERROR: found merge/patch conflicts in files" - exit 1 - fi - ''}"; - }; - meson-format = - let - meson = pkgs.meson.overrideAttrs { - doCheck = false; - doInstallCheck = false; - patches = [ - (pkgs.fetchpatch { - url = "https://github.com/mesonbuild/meson/commit/38d29b4dd19698d5cad7b599add2a69b243fd88a.patch"; - hash = "sha256-PgPBvGtCISKn1qQQhzBW5XfknUe91i5XGGBcaUK4yeE="; - }) - ]; - }; - in - { - enable = true; - files = "(meson.build|meson.options)$"; - entry = "${pkgs.writeScript "format-meson" '' - #!${pkgs.runtimeShell} - for file in "$@"; do - ${lib.getExe meson} format -ic ${../meson.format} "$file" - done - ''}"; - }; - nixfmt-rfc-style = { - enable = true; - excludes = [ - # Invalid - ''^tests/functional/lang/parse-.*\.nix$'' - - # Formatting-sensitive - ''^tests/functional/lang/eval-okay-curpos\.nix$'' - ''^tests/functional/lang/.*comment.*\.nix$'' - ''^tests/functional/lang/.*newline.*\.nix$'' - ''^tests/functional/lang/.*eol.*\.nix$'' - - # Syntax tests - ''^tests/functional/shell.shebang\.nix$'' - ''^tests/functional/lang/eval-okay-ind-string\.nix$'' - - # Not supported by nixfmt - ''^tests/functional/lang/eval-okay-deprecate-cursed-or\.nix$'' - ''^tests/functional/lang/eval-okay-attrs5\.nix$'' - ''^tests/functional/lang/eval-fail-dynamic-attrs-inherit\.nix$'' - ''^tests/functional/lang/eval-fail-dynamic-attrs-inherit-2\.nix$'' - - # More syntax tests - # These tests, or parts of them, should have been parse-* test cases. - ''^tests/functional/lang/eval-fail-eol-2\.nix$'' - ''^tests/functional/lang/eval-fail-path-slash\.nix$'' - ''^tests/functional/lang/eval-fail-toJSON-non-utf-8\.nix$'' - ''^tests/functional/lang/eval-fail-set\.nix$'' - ]; - }; - clang-format = { - enable = true; - # https://github.com/cachix/git-hooks.nix/pull/532 - package = pkgs.llvmPackages_latest.clang-tools; - excludes = [ - # We don't want to format test data - # ''tests/(?!nixos/).*\.nix'' - ''^src/[^/]*-tests/data/.*$'' - - # Don't format vendored code - ''^doc/manual/redirects\.js$'' - ''^doc/manual/theme/highlight\.js$'' - ]; - }; - shellcheck = { - enable = true; - }; - }; - }; - }; - - # We'll be pulling from this in the main flake - flake.getSystem = getSystem; -} diff --git a/packaging/dev-shell.nix b/packaging/dev-shell.nix index 7b2638f4e21..2e8141ad0a8 100644 --- a/packaging/dev-shell.nix +++ b/packaging/dev-shell.nix @@ -1,6 +1,6 @@ { lib, - devFlake, + preCommitHooksFor, }: let @@ -119,7 +119,7 @@ pkgs.nixComponents2.nix-util.overrideAttrs ( let stdenv = pkgs.nixDependencies2.stdenv; buildCanExecuteHost = stdenv.buildPlatform.canExecute stdenv.hostPlatform; - modular = devFlake.getSystem stdenv.buildPlatform.system; + modular = preCommitHooksFor stdenv.buildPlatform.system; transformFlag = prefix: flag: assert builtins.isString flag; @@ -229,6 +229,9 @@ pkgs.nixComponents2.nix-util.overrideAttrs ( # Make bash completion work. XDG_DATA_DIRS+=:$out/share + # Add pre-commit hooks + ${(preCommitHooksFor stdenv.buildPlatform.system).shellHook} + # Make the default phases do the right thing. # FIXME: this wouldn't be needed if the ninja package set buildPhase() instead of $buildPhase. # FIXME: mesonConfigurePhase shouldn't cd to the build directory. It would be better to pass '-C ' to ninja. @@ -271,7 +274,7 @@ pkgs.nixComponents2.nix-util.overrideAttrs ( env = { # For `make format`, to work without installing pre-commit _NIX_PRE_COMMIT_HOOKS_CONFIG = "${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml" - modular.pre-commit.settings.rawConfig + modular.config.rawConfig }"; } // lib.optionalAttrs stdenv.hostPlatform.isLinux { @@ -317,8 +320,7 @@ pkgs.nixComponents2.nix-util.overrideAttrs ( ) pkgs.buildPackages.mesonEmulatorHook ++ [ pkgs.buildPackages.gnused - modular.pre-commit.settings.package - (pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript) + pkgs.buildPackages.pre-commit pkgs.buildPackages.nixfmt-rfc-style pkgs.buildPackages.shellcheck pkgs.buildPackages.include-what-you-use diff --git a/packaging/pre-commit-hook-settings.nix b/packaging/pre-commit-hook-settings.nix new file mode 100644 index 00000000000..45803ad135d --- /dev/null +++ b/packaging/pre-commit-hook-settings.nix @@ -0,0 +1,103 @@ +{ + pkgs, + lib, + src, +}: + +{ + inherit src; + + hooks = { + # Conflicts are usually found by other checks, but not those in docs, + # and potentially other places. + check-merge-conflicts.enable = true; + + # built-in check-merge-conflicts seems ineffective against those produced by mergify backports + check-merge-conflicts-2 = { + enable = true; + entry = "${pkgs.writeScript "check-merge-conflicts" '' + #!${pkgs.runtimeShell} + conflicts=false + for file in "$@"; do + if grep --with-filename --line-number -E '^>>>>>>> ' -- "$file"; then + conflicts=true + fi + done + if $conflicts; then + echo "ERROR: found merge/patch conflicts in files" + exit 1 + fi + ''}"; + }; + + meson-format = + let + meson = pkgs.meson.overrideAttrs { + doCheck = false; + doInstallCheck = false; + patches = [ + (pkgs.fetchpatch { + url = "https://github.com/mesonbuild/meson/commit/38d29b4dd19698d5cad7b599add2a69b243fd88a.patch"; + hash = "sha256-PgPBvGtCISKn1qQQhzBW5XfknUe91i5XGGBcaUK4yeE="; + }) + ]; + }; + in + { + enable = true; + files = "(meson.build|meson.options)$"; + entry = "${pkgs.writeScript "format-meson" '' + #!${pkgs.runtimeShell} + for file in "$@"; do + ${lib.getExe meson} format -ic ${../meson.format} "$file" + done + ''}"; + }; + + nixfmt-rfc-style = { + enable = true; + excludes = [ + # Invalid + ''^tests/functional/lang/parse-.*\.nix$'' + + # Formatting-sensitive + ''^tests/functional/lang/eval-okay-curpos\.nix$'' + ''^tests/functional/lang/.*comment.*\.nix$'' + ''^tests/functional/lang/.*newline.*\.nix$'' + ''^tests/functional/lang/.*eol.*\.nix$'' + + # Syntax tests + ''^tests/functional/shell.shebang\.nix$'' + ''^tests/functional/lang/eval-okay-ind-string\.nix$'' + + # Not supported by nixfmt + ''^tests/functional/lang/eval-okay-deprecate-cursed-or\.nix$'' + ''^tests/functional/lang/eval-okay-attrs5\.nix$'' + ''^tests/functional/lang/eval-fail-dynamic-attrs-inherit\.nix$'' + ''^tests/functional/lang/eval-fail-dynamic-attrs-inherit-2\.nix$'' + + # More syntax tests + # These tests, or parts of them, should have been parse-* test cases. + ''^tests/functional/lang/eval-fail-eol-2\.nix$'' + ''^tests/functional/lang/eval-fail-path-slash\.nix$'' + ''^tests/functional/lang/eval-fail-toJSON-non-utf-8\.nix$'' + ''^tests/functional/lang/eval-fail-set\.nix$'' + ]; + }; + clang-format = { + enable = true; + # https://github.com/cachix/git-hooks.nix/pull/532 + package = pkgs.llvmPackages_latest.clang-tools; + excludes = [ + # We don't want to format test data + # ''tests/(?!nixos/).*\.nix'' + ''^src/[^/]*-tests/data/.*$'' + + # Don't format vendored code + ''^doc/manual/redirects\.js$'' + ''^doc/manual/theme/highlight\.js$'' + ]; + }; + shellcheck.enable = true; + }; +}