{"id":16343237,"url":"https://github.com/fricklerhandwerk/git-hooks","last_synced_at":"2026-05-13T12:46:14.964Z","repository":{"id":240139524,"uuid":"801302179","full_name":"fricklerhandwerk/git-hooks","owner":"fricklerhandwerk","description":"Install Nix packages as Git hooks from your Nix shell environment","archived":false,"fork":false,"pushed_at":"2024-06-05T11:35:50.000Z","size":15,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T03:38:44.519Z","etag":null,"topics":["git","git-hooks","nix","nix-shell","pre-commit"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fricklerhandwerk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-16T01:10:18.000Z","updated_at":"2025-02-17T08:02:17.000Z","dependencies_parsed_at":"2024-06-05T13:13:41.666Z","dependency_job_id":null,"html_url":"https://github.com/fricklerhandwerk/git-hooks","commit_stats":null,"previous_names":["fricklerhandwerk/git-hooks"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/fricklerhandwerk/git-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fgit-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fgit-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fgit-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fgit-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fricklerhandwerk","download_url":"https://codeload.github.com/fricklerhandwerk/git-hooks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fricklerhandwerk%2Fgit-hooks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262996460,"owners_count":23396903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","git-hooks","nix","nix-shell","pre-commit"],"created_at":"2024-10-11T00:23:50.537Z","updated_at":"2025-10-27T10:16:05.105Z","avatar_url":"https://github.com/fricklerhandwerk.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git hooks\nInstall Nix packages as [Git hooks](https://git-scm.com/docs/githooks) from your Nix shell environment.\n\nHeavily inspired by [a hack](https://git.clan.lol/clan/clan-core/src/commit/930923512c03179fe75e4209c27eb3da368e7766/scripts/pre-commit) to get [treefmt](https://github.com/numtide/treefmt) into a pre-commit hook.\n\n## Installation\n\n```shell-session\nnix-shell -p npins\nnpins init\nnpins add github fricklerhandwerk git-hooks -b main\n```\n\n```nix\n## default.nix\nlet\n  sources = import ./npins;\nin\n{\n  pkgs ? import sources.nixpkgs { inherit system; config = { }; overlays = [ ]; },\n  git-hooks ? pkgs.callPackage sources.git-hooks { },\n  system ? builtins.currentSystem,\n}:\nlet\n  inherit (git-hooks) lib;\nin\npkgs.mkShellNoCC {\n  shellHook = ''\n#    # add Git hooks here\n  '';\n}\n```\n\n## `lib.git-hooks.pre-commit`\n\n```\npre-commit :: Derivation -\u003e Path\n```\n\n`pre-commit` takes a derivaton with a [pre-commit hook](https://git-scm.com/docs/githooks#_pre_commit), and returns a path to an executable that will install the hook.\n\nThe derivation must have `meta.mainProgram` set to the name of the executable in `$out/bin/` that implements the hook.\nThe hook is installed in the Git repository that surrounds the working directory of the Nix invocation, and will get run roughly like this:\n\n```bash\ngit stash push --keep-index\nhook\ngit stash pop\n```\n\n\u003e **Example**\n\u003e\n\u003e ### Add a pre-commit hook\n\u003e\n\u003e Entering this shell environment will install a Git hook that prints `Hello, world!` to the console before each commit:\n\u003e\n\u003e ```\n\u003e pkgs.mkShellNoCC {\n\u003e   shellHook = ''\n\u003e     ${lib.git-hooks.pre-commit pkgs.hello}\n\u003e   '';\n\u003e }\n\u003e ```\n\n## `lib.git-hooks.wrap.abort-on-change`\n\n```\nabort-on-change :: Derivation -\u003e Derivation\n```\n\nWrap a hook such that the commit is aborted if the hook changes staged files.\n\n\u003e **Example**\n\u003e\n\u003e ### Wrap a pre-commit hook to abort on changed files\n\u003e\n\u003e The `cursed` hook will add an empty line to each staged file.\n\u003e Wrapping it in `abort-on-change` will prevent files thus changed from being committed.\n\u003e\n\u003e ```\n\u003e let\n\u003e   cursed = pkgs.writeShellApplication {\n\u003e     name = \"pre-commit-hook\";\n\u003e     runtimeInputs = with pkgs; [ git ];\n\u003e     text = ''\n\u003e       for f in $(git diff --name-only --cached); do\n\u003e         echo \u003e\u003e \"$f\"\n\u003e       done\n\u003e     '';\n\u003e   };\n\u003e in\n\u003e pkgs.mkShellNoCC {\n\u003e   shellHook = ''\n\u003e     ${with lib.git-hooks; pre-commit (wrap.abort-on-change cursed)}\n\u003e   '';\n\u003e }\n\u003e ```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffricklerhandwerk%2Fgit-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffricklerhandwerk%2Fgit-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffricklerhandwerk%2Fgit-hooks/lists"}