diff --git a/overlays.nix b/overlays.nix index d85c7ee..7a66b76 100755 --- a/overlays.nix +++ b/overlays.nix @@ -150,6 +150,35 @@ let ); }; + # usage: nix-build . -A .tests.mainProgram + overlays.withTestMainProgram = mkDerivationOverlay ( + final: prev: prevStdenv: finalAttrs: prevAttrs: { + passthru = prevAttrs.passthru or { } // { + tests = + lib.optionalAttrs ((prevAttrs.meta or { }) ? mainProgram) { + mainProgram = final.runCommandLocal "${finalAttrs.finalPackage.name}-check-mainProgram" { } '' + fname=${lib.getBin finalAttrs.finalPackage}/bin/${lib.escapeShellArg finalAttrs.finalPackage.meta.mainProgram} + if [[ -x "$fname" ]]; then + echo "Found $fname" + touch $out + elif [[ -f "$fname" ]]; then + echo >&2 "ERROR: '$fname' is not executable!" + false + elif [[ -d "$fname" ]]; then + echo >&2 "ERROR: '$fname' is a directory!" + false + else + echo >&2 "ERROR: '$fname' not found!" + (set -x; find ${lib.getBin finalAttrs.finalPackage}/bin -type f) + false + fi + ''; + } + // (prevAttrs.passthru.tests or { }); + }; + } + ); + # usage: nix-build . -A .shellcheck overlays.withShellCheck = mkDerivationOverlay ( final: prev: prevStdenv: finalAttrs: prevAttrs: @@ -509,6 +538,7 @@ in overlays.srcOnly overlays.withInvalidateFetcherByDrvHash overlays.withUnpacked + overlays.withTestMainProgram overlays.withShellCheck # overlays.withCudaOrRocm # WIP overlays.withCcache # WIP