From eb00b32b899fb7c343f88492eaa1973b3dadf596 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Thu, 3 Oct 2024 01:39:30 -0700 Subject: [PATCH] lantian-pre-commit-hooks: fix treefmt is not applied to all files --- flake-modules/_internal/ci-outputs.nix | 5 +- .../_internal/modules-test-nixos-config.nix | 20 +----- flake-modules/commands.nix | 37 ++++++---- flake-modules/lantian-pre-commit-hooks.nix | 69 ++++++++++++------- flake-modules/lantian-treefmt.nix | 54 ++++++++------- pkgs/uncategorized/calibre-cops/default.nix | 1 - pkgs/uncategorized/unigine-heaven/default.nix | 2 - 7 files changed, 101 insertions(+), 87 deletions(-) diff --git a/flake-modules/_internal/ci-outputs.nix b/flake-modules/_internal/ci-outputs.nix index 5e9fd52d..a9592d6b 100644 --- a/flake-modules/_internal/ci-outputs.nix +++ b/flake-modules/_internal/ci-outputs.nix @@ -1,5 +1,4 @@ { - self, lib, flake-parts-lib, inputs, @@ -19,9 +18,9 @@ in imports = [ ciPackagesOptionModule ]; perSystem = - { pkgs, system, ... }: + { pkgs, ... }: let - inherit (pkgs.callPackage ../../helpers/is-buildable.nix { }) isBuildable isSourceFetchable; + inherit (pkgs.callPackage ../../helpers/is-buildable.nix { }) isBuildable; nvfetcherLoader = pkgs.callPackage ../../helpers/nvfetcher-loader.nix { }; sources = nvfetcherLoader ../../_sources/generated.nix; in diff --git a/flake-modules/_internal/modules-test-nixos-config.nix b/flake-modules/_internal/modules-test-nixos-config.nix index 09b8b37a..32d7d711 100644 --- a/flake-modules/_internal/modules-test-nixos-config.nix +++ b/flake-modules/_internal/modules-test-nixos-config.nix @@ -5,18 +5,6 @@ inputs, ... }: -let - enumerateList = builtins.foldl' ( - l: ll: - l - ++ [ - { - index = builtins.length l; - value = ll; - } - ] - ) [ ]; -in { imports = [ ./ci-outputs.nix ]; @@ -37,11 +25,9 @@ in system.stateVersion = lib.trivial.release; # Add all CI packages - environment.etc = ( - lib.mapAttrs' ( - _n: v: lib.nameValuePair "ci-packages/${v.name}" { source = v; } - ) self.ciPackages.${system} - ); + environment.etc = lib.mapAttrs' ( + _n: v: lib.nameValuePair "ci-packages/${v.name}" { source = v; } + ) self.ciPackages.${system}; } ]; } diff --git a/flake-modules/commands.nix b/flake-modules/commands.nix index cefb596c..9b02c555 100644 --- a/flake-modules/commands.nix +++ b/flake-modules/commands.nix @@ -1,6 +1,8 @@ -{ lib, flake-parts-lib, ... }: { - options.perSystem = flake-parts-lib.mkPerSystemOption - ({ pkgs, config, ... }: { +{ lib, flake-parts-lib, ... }: +{ + options.perSystem = flake-parts-lib.mkPerSystemOption ( + { pkgs, config, ... }: + { options.commands = lib.mkOption { type = lib.types.attrsOf lib.types.str; default = { }; @@ -12,17 +14,24 @@ program = pkgs.writeShellScriptBin n v; }) config.commands; - devShells.default = pkgs.mkShell ({ - buildInputs = lib.mapAttrsToList (n: _v: - pkgs.writeShellScriptBin n '' - exec nix run .#${n} -- "$@" - '') apps; - } // (lib.optionalAttrs (config ? pre-commit) { - nativeBuildInputs = config.pre-commit.settings.enabledPackages - ++ [ config.pre-commit.settings.package ]; - shellHook = config.pre-commit.installationScript; + devShells.default = pkgs.mkShell ( + { + buildInputs = lib.mapAttrsToList ( + n: _v: + pkgs.writeShellScriptBin n '' + exec nix run .#${n} -- "$@" + '' + ) apps; + } + // (lib.optionalAttrs (config ? pre-commit) { + nativeBuildInputs = config.pre-commit.settings.enabledPackages ++ [ + config.pre-commit.settings.package + ]; + shellHook = config.pre-commit.installationScript; - })); + }) + ); }; - }); + } + ); } diff --git a/flake-modules/lantian-pre-commit-hooks.nix b/flake-modules/lantian-pre-commit-hooks.nix index 524a867f..b9346a89 100644 --- a/flake-modules/lantian-pre-commit-hooks.nix +++ b/flake-modules/lantian-pre-commit-hooks.nix @@ -1,32 +1,49 @@ -{ pre-commit-hooks-nix, ... }: { +{ pre-commit-hooks-nix, ... }: +{ imports = [ pre-commit-hooks-nix.flakeModule ]; - perSystem = _: { - pre-commit = { - check.enable = true; - settings = { - excludes = [ "_sources/.*" ]; - hooks = { - actionlint.enable = true; - check-added-large-files.enable = true; - check-builtin-literals.enable = true; - check-case-conflicts.enable = true; - check-json.enable = true; - check-merge-conflicts.enable = true; - check-python.enable = true; - check-shebang-scripts-are-executable.enable = true; - check-symlinks.enable = true; - check-toml.enable = true; - check-vcs-permalinks.enable = true; - check-yaml.enable = true; - detect-private-keys.enable = true; - fix-byte-order-marker.enable = true; - flake-checker.enable = true; - flynt.enable = true; - nil.enable = true; - treefmt.enable = true; + perSystem = + { + options, + config, + pkgs, + ... + }: + { + pre-commit = { + check.enable = true; + settings = { + excludes = [ "_sources/.*" ]; + hooks = { + actionlint.enable = true; + check-added-large-files.enable = true; + check-builtin-literals.enable = true; + check-case-conflicts.enable = true; + check-json.enable = true; + check-merge-conflicts.enable = true; + check-python.enable = true; + check-shebang-scripts-are-executable.enable = true; + check-symlinks.enable = true; + check-toml.enable = true; + check-vcs-permalinks.enable = true; + check-yaml.enable = true; + detect-private-keys.enable = true; + fix-byte-order-marker.enable = true; + flake-checker.enable = true; + flynt.enable = true; + nil.enable = true; + treefmt = { + enable = true; + entry = + let + treefmt = if options ? treefmt then config.treefmt.build.wrapper else pkgs.treefmt; + in + "${treefmt}/bin/treefmt --clear-cache --fail-on-change"; + always_run = true; + pass_filenames = false; + }; + }; }; }; }; - }; } diff --git a/flake-modules/lantian-treefmt.nix b/flake-modules/lantian-treefmt.nix index d57b0389..4a920cdf 100644 --- a/flake-modules/lantian-treefmt.nix +++ b/flake-modules/lantian-treefmt.nix @@ -1,31 +1,37 @@ -{ treefmt-nix, ... }: { +{ treefmt-nix, ... }: +{ imports = [ treefmt-nix.flakeModule ]; - perSystem = { config, pkgs, ... }: { - treefmt = { - flakeFormatter = false; - projectRootFile = "flake.nix"; + perSystem = + { config, pkgs, ... }: + { + treefmt = { + flakeFormatter = false; + projectRootFile = "flake.nix"; - settings = { - formatter.deadnix.excludes = [ "**/composer2nix/**" ]; - global.excludes = [ "**/_sources/**" ]; - }; + settings = { + formatter.deadnix.excludes = [ "**/composer2nix/**" ]; + global.excludes = [ + "**/_sources/**" + "_sources/**" + ]; + }; - programs = { - black.enable = true; - deadnix.enable = true; - isort.enable = true; - nixfmt.enable = true; - statix.enable = true; + programs = { + black.enable = true; + deadnix.enable = true; + isort.enable = true; + nixfmt.enable = true; + statix.enable = true; + }; }; - }; - formatter = pkgs.writeShellScriptBin "treefmt-auto" '' - for i in {1..5}; do - echo "Running treefmt for the ''${i}th time" - ${config.treefmt.build.wrapper}/bin/treefmt --clear-cache --fail-on-change "$@" && exit 0 - done - exit $? - ''; - }; + formatter = pkgs.writeShellScriptBin "treefmt-auto" '' + for i in {1..5}; do + echo "Running treefmt for the ''${i}th time" + ${config.treefmt.build.wrapper}/bin/treefmt --clear-cache --fail-on-change "$@" && exit 0 + done + exit $? + ''; + }; } diff --git a/pkgs/uncategorized/calibre-cops/default.nix b/pkgs/uncategorized/calibre-cops/default.nix index 7f1a9980..ea3b5ecf 100644 --- a/pkgs/uncategorized/calibre-cops/default.nix +++ b/pkgs/uncategorized/calibre-cops/default.nix @@ -2,7 +2,6 @@ sources, lib, stdenvNoCC, - dos2unix, unzip, ... }: diff --git a/pkgs/uncategorized/unigine-heaven/default.nix b/pkgs/uncategorized/unigine-heaven/default.nix index a1e35867..ba6434eb 100644 --- a/pkgs/uncategorized/unigine-heaven/default.nix +++ b/pkgs/uncategorized/unigine-heaven/default.nix @@ -3,7 +3,6 @@ lib, stdenv, autoPatchelfHook, - buildFHSEnv, copyDesktopItems, makeDesktopItem, makeWrapper, @@ -11,7 +10,6 @@ fontconfig, freetype, glib, - glxinfo, libglvnd, openal, xorg,