From b6f394d3f72ec4f8a6bf87508d9e1a4b29607a4c Mon Sep 17 00:00:00 2001 From: tljuniper <48209000+tljuniper@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:22:04 +0200 Subject: [PATCH] Preserve executable bit in files Some commit hooks such as `pre-commit-hooks/check-executables-have-shebangs` are designed to run only on executable files via `types = ["executable"]` and the python tool `identify` uses the executable bit of a file when generating file tags, so `executable` is only listed when that bit is set. By removing `--no-preserve=mode` we get to keep the executable bit. We still need everything to be writable though. --- modules/pre-commit.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index b5347c1d..4afea0e0 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -163,7 +163,10 @@ let runCommand "pre-commit-run" { buildInputs = [ git ]; } '' set +e HOME=$PWD - cp --no-preserve=mode -R ${cfg.rootSrc} src + # Use `chmod +w` instead of `cp --no-preserve=mode` to be able to write and to + # preserve the executable bit at the same time + cp -R ${cfg.rootSrc} src + chmod -R +w src ln -fs ${configFile} src/.pre-commit-config.yaml cd src rm -rf src/.git