Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "CI"
on:
pull_request:
merge_group:
push:
jobs:
shellcheck:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Publish
on:
pull_request:
merge_group:
push:
branches:
- '*'
Expand Down
47 changes: 47 additions & 0 deletions flake.lock

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

65 changes: 56 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

# 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 = "";

outputs =
{ self, nixpkgs }:
inputs@{ self, nixpkgs, ... }:

let
inherit (nixpkgs) lib;
Expand Down Expand Up @@ -38,13 +49,23 @@

patchelfFor =
pkgs:
let
# this is only
in
# this is only
pkgs.callPackage ./patchelf.nix {
inherit version src;
};

# 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 = supportedSystems;
perSystem =
{ system, ... }:
{
_module.args.pkgs = nixpkgs.legacyPackages.${system};
};
};

in

{
Expand Down Expand Up @@ -126,18 +147,44 @@

};

checks = forAllSystems (system: {
build = self.hydraJobs.build.${system};
});
checks = forAllSystems (
system:
{
build = self.hydraJobs.build.${system};
}
// devFlake.checks.${system} or { }
);

devShells = forAllSystems (
system:
let
mkShell =
patchelf:
patchelf.overrideAttrs (
old:
let
pkgs = nixpkgs.legacyPackages.${system};
modular = devFlake.getSystem pkgs.stdenv.buildPlatform.system;
in
{
env = (old.env or { }) // {
_NIX_PRE_COMMIT_HOOKS_CONFIG = "${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml"
modular.pre-commit.settings.rawConfig
}";
};
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
modular.pre-commit.settings.package
(pkgs.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
];
}
);
in
{
glibc = self.packages.${system}.patchelf;
glibc = mkShell self.packages.${system}.patchelf;
default = self.devShells.${system}.glibc;
}
// lib.optionalAttrs (system != "i686-linux") {
musl = self.packages.${system}.patchelf-musl;
musl = mkShell self.packages.${system}.patchelf-musl;
}
);

Expand Down
70 changes: 70 additions & 0 deletions maintainers/flake-module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
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
''}";
};
nixfmt-rfc-style = {
enable = true;
};
clang-format = {
enable = true;
# https://github.com/cachix/git-hooks.nix/pull/532
package = pkgs.llvmPackages_latest.clang-tools;
# Not yet formatted
excludes = [
''^src/elf.h$''
''^src/patchelf.cc$''
''^src/patchelf.h$''
''^tests/bar.c$''
''^tests/foo.c$''
''^tests/main.c$''
''^tests/no-rpath.c$''
''^tests/simple.c$''
''^tests/too-many-strtab.c$''
''^tests/void.c$''
];
};
shellcheck = {
enable = true;
};
};
};
};

# We'll be pulling from this in the main flake
flake.getSystem = getSystem;
}
16 changes: 16 additions & 0 deletions maintainers/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

if ! type -p pre-commit &>/dev/null; then
echo "format.sh: pre-commit not found. Please use \`nix develop -c ./maintainers/format.sh\`.";
exit 1;
fi;
if test -z "$_NIX_PRE_COMMIT_HOOKS_CONFIG"; then
echo "format.sh: _NIX_PRE_COMMIT_HOOKS_CONFIG not set. Please use \`nix develop -c ./maintainers/format.sh\`.";
exit 1;
fi;

while ! pre-commit run --config "$_NIX_PRE_COMMIT_HOOKS_CONFIG" --all-files; do
if [ "${1:-}" != "--until-stable" ]; then
exit 1
fi
done
Loading