Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
inputs.nixpkgs-23-11.url = "github:NixOS/nixpkgs/a62e6edd6d5e1fa0329b8653c801147986f8d446";

# dev tooling
inputs.flake-parts.url = "https://flakehub.com/f/hercules-ci/flake-parts/0.1";
inputs.git-hooks-nix.url = "https://flakehub.com/f/cachix/git-hooks.nix/0.1.941";
# 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";
# work around 7730 and https://github.com/NixOS/nix/issues/7807
inputs.git-hooks-nix.inputs.gitignore.follows = "";
Expand Down Expand Up @@ -75,17 +73,21 @@

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;
hooksSettings = import ./packaging/pre-commit-hook-settings.nix {
inherit lib pkgs;
src = self;
};
};
git-hooks = inputs.git-hooks-nix.lib.${system};
in
{
check = git-hooks.run hooksSettings;
settings = hooksSettings;
};

# Memoize nixpkgs for different platforms for efficiency.
nixpkgsFor = forAllSystems (
Expand Down Expand Up @@ -345,7 +347,9 @@
}
)).componentTests
)
// devFlake.checks.${system} or { }
// {
pre-commit-check = (preCommitHooksFor system).check;
}
);

packages = forAllSystems (
Expand Down Expand Up @@ -494,7 +498,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 (
Expand Down
114 changes: 0 additions & 114 deletions maintainers/flake-module.nix

This file was deleted.

9 changes: 4 additions & 5 deletions packaging/dev-shell.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
lib,
devFlake,
preCommitHooksFor,
}:

{ pkgs }:
Expand All @@ -11,7 +11,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;
Expand Down Expand Up @@ -74,7 +74,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.settings
}";
}
// lib.optionalAttrs stdenv.hostPlatform.isLinux {
Expand Down Expand Up @@ -115,8 +115,7 @@ pkgs.nixComponents2.nix-util.overrideAttrs (
pkgs.buildPackages.gnused
pkgs.buildPackages.shellcheck
pkgs.buildPackages.changelog-d
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.gdb
Expand Down
78 changes: 78 additions & 0 deletions packaging/pre-commit-hook-settings.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
pkgs,
lib,
src,
}:

{
hooks = {
check-merge-conflicts.enable = true;
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 = [
''^tests/functional/lang/parse-.*\.nix$''
''^tests/functional/lang/eval-okay-curpos\.nix$''
''^tests/functional/lang/.*comment.*\.nix$''
''^tests/functional/lang/.*newline.*\.nix$''
''^tests/functional/lang/.*eol.*\.nix$''
''^tests/functional/shell.shebang\.nix$''
''^tests/functional/lang/eval-okay-ind-string\.nix$''
''^tests/functional/lang/eval-okay-deprecate-cursed-or\.nix$''
''^tests/functional/lang/eval-okay-attrs5\.nix$''
''^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;
package = pkgs.llvmPackages_latest.clang-tools;
excludes = [
''^src/[^/]*-tests/data/.*$''
''^doc/manual/redirects\.js$''
''^doc/manual/theme/highlight\.js$''
];
};
shellcheck.enable = true;
};
}
Loading