I recently stumbled on an a package for which.overrideAttrs { postInstall = "..." }didn’t work, and after some investigation I figured that package has explicit installPhase without runHook boilerplate.
That got me thinking. Sure, that is not the only package with this problem, and indeed: 900 files missing runHook for installPhase, and more for other phases, so making one pull request a time is going to take a long time.
So, I propose two alternative solutions:
Both would mean a lot of work to polish and finalize, so I’d rather first discuss any concerns and preferences the community has. I personally strongly favor patching stdenv approach to avoid having humans to do machine’s job.
The only existing discussion on this topic seems to agree that some across-the-board solution would be nice (without definitive answer which one it should be), that fixing one package a time is better than nothing.
Recently I have seen some PRs made by different people which besides the main goal of PR insert void runHook here and there
For example libguestfs: 1.38.6 -> 1.40.2 by Amar1729 · Pull Request #67572 · NixOS/nixpkgs · GitHub
The motivation explained by them is very questionable (“support for overriding derivation”), which in my opinion is not needed, but even if I am wrong and it has some usefulness - I wonder, why it is not added treewide, but using a kind of a guerrilla tactics in a irrelevan…
I have a lint for that but it would be nice to fix it once and for all.
The canonical issue: Fix the problem of forgotten `runHook {pre,post}*` calls · Issue #175605 · NixOS/nixpkgs · GitHub
Note that if we start invoking hooks outside phases, we will want to avoid running explicit runHooks in the overridden *Phases since hooks are not guaranteed to be idempotent.
3 Likes
I opened a treewide long ago exactly about missing runHook in installPhase, but it has stayed in draft still
staging ← Sigmanificient:add-missing-install-hooks
opened 08:16PM - 09 Aug 24 UTC
## Description of changes
This was done throw the following command:
```ba… sh
grep -rP "installPhase ="
| cut -d ':' -f 1 \
| xargs -i sh -c "grep -P 'runHook\s+preInstall' {} >/dev/null ||
echo '{}'" | python add_missing_hooks.py
```
with the following script:
https://gist.github.com/Sigmanificient/c68e03d1ad750a83233c6ab05761cbf2
`2432` hits, `68` miss are to be dealt with manually
Applying the following:
```diff
installPhase = ''
+ runHook preInstall
+
...
+
+ runHook postInstall
'';
```
for matching:
```regex
(?P<decl>installPhase\s+=\s+(?:let(?:(?!\s+in\s+)(?:.|\n))+\s+in\s+)?)
'{2,3}\n?(?P<ident>\s+)?(?P<block>(?:(?!'{2,3};)(?:\n|.)?)+)(?P<quotes>'{2,3});
```
and (@emilazy suggestion):
```diff
- installPhase = "...";
+ installPhase = "runHook preInstall; ...; runHook postInstall";
```
matching:
```regex
(?P<ident>[ ]+)?(?P<decl>installPhase\s+=\s+)"(?P<block>.*)";
```
## Extra edits
Some minor adjustment were done to pass green on the CI:
- replaced tabs to spaces in `pkgs/build-support/dotnet/dotnetenv/build-solution.nix`
- removed `stdenv/linux`, `glibc` to avoid rebuilding `stdenv`
## Things done
- Built on platform(s)
- [ ] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
- [ ] `sandbox = relaxed`
- [ ] `sandbox = true`
- [ ] Tested, as applicable:
- [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- and/or [package tests](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
- or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
- made sure NixOS tests are [linked](https://nixos.org/manual/nixpkgs/unstable/#ssec-nixos-tests-linking) to the relevant packages
- [ ] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [ ] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [24.11 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md) (or backporting [23.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2311.section.md) and [24.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2405.section.md) Release notes)
- [ ] (Package updates) Added a release notes entry if the change is major or breaking
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [x] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc
1 Like
Sure, we will need sed '/runHook/ d', more or less. My vision is PR of three parts:
Patch stdenv to run hooks
Patch-out explicit runHook tree-wide
Patch-out runHook from nixpkgs manual
Thanks for the issue link
tejing
October 4, 2026, 11:54pm
5
You need to consider out-of-tree derivations, too. Whatever you do needs to work whether the runHooks are there or not, for a fair while.
1 Like
Something like
if installPhase !~ "runHook preInstall" then
runHook preInstall
fi
I’ll need to research how to do it with pure bash, but it should be doable.
Okay, I think stdenv: run pre/post hooks automatically by KAction · Pull Request #570194 · NixOS/nixpkgs · GitHub now covers all points discussed so far.
Now it has protection against duplicate runHook This makes it unnecessary to do tree-wide removal of explicit runHook right now (although I plan to do it in subsequent PR)
Updated the documentation to stop requiring explicit runHook(we had several places where it was re-iterated)
Looking for a reviewer/committer.
1 Like