From 281ffa987c258b62de853178b382da1eaa9abd61 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 30 May 2026 23:44:21 +0100 Subject: [PATCH] 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 ce5210e9c728c8a89a103d7a6c8c6662cac081c3) --- pkgs/by-name/ni/nixfmt/package.nix | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkgs/by-name/ni/nixfmt/package.nix b/pkgs/by-name/ni/nixfmt/package.nix index 93a198f73f2a..ebd16230063c 100644 --- a/pkgs/by-name/ni/nixfmt/package.nix +++ b/pkgs/by-name/ni/nixfmt/package.nix @@ -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) ]