Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 3 additions & 27 deletions flake.lock

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

29 changes: 14 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
//
Expand All @@ -352,7 +352,6 @@
}
)).componentTests
)
// devFlake.checks.${system} or { }
);

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

This file was deleted.

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

let
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 <dir>' to ninja.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
103 changes: 103 additions & 0 deletions packaging/pre-commit-hook-settings.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
Loading