From 4f98d21b71d02c09cab9df9778fcc03df4bcbd4e Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 6 May 2024 22:50:32 -0600 Subject: [PATCH 1/3] flake: move the pre-commit definition to its own file It's a good hundred LOC, and wasn't coupled to the actual flake logic at all. Change-Id: Iebb4667b3197dbd8cb2b019014e99fa651848832 --- flake.nix | 83 +------------------------------------ misc/pre-commit.nix | 99 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 82 deletions(-) create mode 100644 misc/pre-commit.nix diff --git a/flake.nix b/flake.nix index 1c090cadf..6594961ff 100644 --- a/flake.nix +++ b/flake.nix @@ -286,89 +286,8 @@ system: let pkgs = nixpkgsFor.${system}.native; - # Import pre-commit bypassing the flake because flakes don't let - # you have overlays. Also their implementation forces an - # unnecessary reimport of nixpkgs for our use cases. - tools = import (pre-commit-hooks + "/nix/call-tools.nix") pkgs; - pre-commit-run = pkgs.callPackage (pre-commit-hooks + "/nix/run.nix") { - inherit tools; - isFlakes = true; - # unused! - gitignore-nix-src = builtins.throw "gitignore-nix-src is unused"; - }; in - pre-commit-run { - src = self; - hooks = { - no-commit-to-branch = { - enable = true; - settings.branch = [ "main" ]; - }; - check-case-conflicts.enable = true; - check-executables-have-shebangs = { - enable = true; - stages = [ "commit" ]; - }; - check-shebang-scripts-are-executable = { - enable = true; - stages = [ "commit" ]; - }; - check-symlinks = { - enable = true; - excludes = [ "^tests/functional/lang/symlink-resolution/broken$" ]; - }; - check-merge-conflicts.enable = true; - end-of-file-fixer = { - enable = true; - excludes = [ - "\\.drv$" - "^tests/functional/lang/" - ]; - }; - mixed-line-endings = { - enable = true; - excludes = [ "^tests/functional/lang/" ]; - }; - release-notes = { - enable = true; - package = pkgs.build-release-notes; - files = "^doc/manual/rl-next(-dev)?"; - pass_filenames = false; - entry = '' - ${lib.getExe pkgs.build-release-notes} doc/manual/rl-next doc/manual/rl-next-dev - ''; - }; - check-headers = { - enable = true; - package = pkgs.check-headers; - files = "^src/"; - types = [ - "c++" - "file" - "header" - ]; - # generated files; these will never actually be seen by this - # check, and are left here as documentation - excludes = [ - "(parser|lexer)-tab\\.hh$" - "\\.gen\\.hh$" - ]; - entry = lib.getExe pkgs.check-headers; - }; - # TODO: Once the test suite is nicer, clean up and start - # enforcing trailing whitespace on tests that don't explicitly - # check for it. - trim-trailing-whitespace = { - enable = true; - stages = [ "commit" ]; - excludes = [ "^tests/functional/lang/" ]; - }; - treefmt = { - enable = true; - settings.formatters = [ pkgs.nixfmt ]; - }; - }; - } + import ./misc/pre-commit.nix { inherit self pkgs pre-commit-hooks; } ); }; diff --git a/misc/pre-commit.nix b/misc/pre-commit.nix new file mode 100644 index 000000000..b287f3cec --- /dev/null +++ b/misc/pre-commit.nix @@ -0,0 +1,99 @@ +{ + /** + Path to Lix's source, normally the flake's "self" argument + */ + self ? pkgs.lib.cleanSource ./., + /** + Already instantiated Nixpkgs + */ + pkgs, + /** + pre-commit-hooks source path, normally from the flake input + */ + pre-commit-hooks, +}: +let + inherit (pkgs) lib; + # Import pre-commit bypassing the flake because flakes don't let + # you have overlays. Also their implementation forces an + # unnecessary reimport of nixpkgs for our use cases. + tools = import (pre-commit-hooks + "/nix/call-tools.nix") pkgs; + pre-commit-run = pkgs.callPackage (pre-commit-hooks + "/nix/run.nix") { + inherit tools; + isFlakes = true; + # unused! + gitignore-nix-src = builtins.throw "gitignore-nix-src is unused"; + }; +in +pre-commit-run { + src = self; + hooks = { + no-commit-to-branch = { + enable = true; + settings.branch = [ "main" ]; + }; + check-case-conflicts.enable = true; + check-executables-have-shebangs = { + enable = true; + stages = [ "commit" ]; + }; + check-shebang-scripts-are-executable = { + enable = true; + stages = [ "commit" ]; + }; + check-symlinks = { + enable = true; + excludes = [ "^tests/functional/lang/symlink-resolution/broken$" ]; + }; + check-merge-conflicts.enable = true; + end-of-file-fixer = { + enable = true; + excludes = [ + "\\.drv$" + "^tests/functional/lang/" + ]; + }; + mixed-line-endings = { + enable = true; + excludes = [ "^tests/functional/lang/" ]; + }; + release-notes = { + enable = true; + package = pkgs.build-release-notes; + files = "^doc/manual/rl-next(-dev)?"; + pass_filenames = false; + entry = '' + ${lib.getExe pkgs.build-release-notes} doc/manual/rl-next doc/manual/rl-next-dev + ''; + }; + check-headers = { + enable = true; + package = pkgs.check-headers; + files = "^src/"; + types = [ + "c++" + "file" + "header" + ]; + # generated files; these will never actually be seen by this + # check, and are left here as documentation + excludes = [ + "(parser|lexer)-tab\\.hh$" + "\\.gen\\.hh$" + ]; + entry = lib.getExe pkgs.check-headers; + }; + # TODO: Once the test suite is nicer, clean up and start + # enforcing trailing whitespace on tests that don't explicitly + # check for it. + trim-trailing-whitespace = { + enable = true; + stages = [ "commit" ]; + excludes = [ "^tests/functional/lang/" ]; + }; + treefmt = { + enable = true; + settings.formatters = [ pkgs.nixfmt ]; + }; + }; +} From aac32327d5d974cf03fee622558210a37bcdd0e6 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 6 May 2024 22:54:18 -0600 Subject: [PATCH 2/3] flake: fix eval of checks & devshell on i686-linux Change-Id: I62da3161327051005e3f48f83974140efef4417e --- flake.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 6594961ff..3dc9b3ac3 100644 --- a/flake.nix +++ b/flake.nix @@ -96,6 +96,10 @@ ]; forAllSystems = lib.genAttrs systems; + # Same as forAllSystems, but removes nulls, in case something is broken + # on that system. + forAvailableSystems = + f: lib.filterAttrs (name: value: value != null && value != { }) (forAllSystems f); forAllCrossSystems = lib.genAttrs crossSystems; @@ -282,18 +286,21 @@ ); }; - pre-commit = forAllSystems ( + pre-commit = forAvailableSystems ( system: let pkgs = nixpkgsFor.${system}.native; + pre-commit-check = import ./misc/pre-commit.nix { inherit self pkgs pre-commit-hooks; }; + # dotnet-sdk_6, a nativeBuildInputs of pre-commit, is broken on i686-linux. + available = lib.meta.availableOn { inherit system; } pkgs.dotnet-sdk_6; in - import ./misc/pre-commit.nix { inherit self pkgs pre-commit-hooks; } + lib.optionalAttrs available pre-commit-check ); }; # NOTE *do not* add fresh derivations to checks, always add them to # hydraJobs first (so CI will pick them up) and only link them here - checks = forAllSystems ( + checks = forAvailableSystems ( system: { binaryTarball = self.hydraJobs.binaryTarball.${system}; @@ -301,6 +308,7 @@ nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system}; rl-next = self.hydraJobs.rl-next.${system}.user; rl-next-dev = self.hydraJobs.rl-next.${system}.dev; + # Will be empty attr set on i686-linux, and filtered out by forAvailableSystems. pre-commit = self.hydraJobs.pre-commit.${system}; } // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) { From 7e940cc1706397787c66aa8a52b3b8f96cfc2b5a Mon Sep 17 00:00:00 2001 From: Qyriad Date: Mon, 6 May 2024 22:59:41 -0600 Subject: [PATCH 3/3] flake: fix devShell on i686-linux by disabling ClangBuildAnalyzer on it ClangBuildAnalyzer doesn't build on i686-linux due to `long long int`/`size_t` conversion errors, so let's just exclude it from the devshell on that platform Change-Id: If1077a7b3860db4381999c8e304f6d4b2bc96a05 --- flake.nix | 7 ++++--- misc/clangbuildanalyzer.nix | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 3dc9b3ac3..79ac9caea 100644 --- a/flake.nix +++ b/flake.nix @@ -408,9 +408,10 @@ pkgs.buildPackages.meson pkgs.buildPackages.ninja pkgs.buildPackages.cmake - - pkgs.buildPackages.clangbuildanalyzer - ]; + ] + ++ + lib.optionals (lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.buildPackages.clangbuildanalyzer) + [ pkgs.buildPackages.clangbuildanalyzer ]; src = null; diff --git a/misc/clangbuildanalyzer.nix b/misc/clangbuildanalyzer.nix index cee8a0d77..d73fa8bbb 100644 --- a/misc/clangbuildanalyzer.nix +++ b/misc/clangbuildanalyzer.nix @@ -25,6 +25,9 @@ stdenv.mkDerivation (finalAttrs: { maintainers = with lib.maintainers; [ lf- ]; license = lib.licenses.unlicense; platforms = lib.platforms.unix; + # `long long int` != `size_t` + # There's no convenient lib.platforms.32bit or anything, but it's easy enough to do ourselves. + badPlatforms = lib.filter (plat: (lib.systems.elaborate plat).is32bit) lib.platforms.all; mainProgram = "ClangBuildAnalyzer"; }; })