nixfmt: add versionCheckHook

Replace the `passthru.tests` --version test by running versionCheckHook
during the package build.

As `haskellPackages.mkDerivation` is very locked-down and doesn't allow
access to things like `nativeInstallCheckInputs` (or any input lists),
we add a separate `.overrideAttrs` call to the pipeline.

    Running phase: installCheckPhase
    Executing versionCheckPhase
    Successfully managed to find version 1.3.0 in the output of the command /nix/store/3fg7y7qww3c3hvyb66n75d9j5y362n4j-nixfmt-1.3.0/bin/nixfmt --version
    nixfmt 1.3.0
    Finished versionCheckPhase

(cherry picked from commit ce5210e9c7)
This commit is contained in:
Matt Sturgeon
2026-05-30 23:44:21 +01:00
committed by github-actions[bot]
parent 840ebf4210
commit d95a002e88

View File

@@ -2,27 +2,31 @@
haskell,
haskellPackages,
lib,
runCommand,
nixfmt,
stdenv,
versionCheckHook,
}:
let
inherit (haskell.lib.compose) overrideCabal justStaticExecutables;
overrides = {
cabalOverrides = {
passthru.updateScript = ./update.sh;
teams = [ lib.teams.formatter ];
# These tests can be run with the following command.
#
# $ nix-build -A nixfmt.tests
passthru.tests = runCommand "nixfmt-tests" { nativeBuildInputs = [ nixfmt ]; } ''
nixfmt --version > $out
'';
};
# haskellPackages.mkDerivation and haskell.lib.compose.overrideCabal
# do not allow access to `doInstallCheck` or `nativeInstallCheckInputs`,
# so we override directly with `.overrideAttrs`.
lateOverrides = finalAttrs: prevAttrs: {
doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
nativeInstallCheckInputs = prevAttrs.nativeInstallCheckInputs or [ ] ++ [
versionCheckHook
];
};
raw-pkg = haskellPackages.callPackage ./generated-package.nix { };
in
lib.pipe raw-pkg [
(overrideCabal overrides)
(overrideCabal cabalOverrides)
justStaticExecutables
(drv: drv.overrideAttrs lateOverrides)
]