nix: refactor derivation tests for static package

Instead of rolling our own, we can use some tooling from nix / nixpkgs.

We drop the "statically linked" check, because our goal is to compile
mostly-static executables to darwin, too. However, those will never be
fully static, because they always link to the platform's libc.
This commit is contained in:
Wolfgang Walther
2025-07-11 15:53:06 +00:00
parent 55eafdf352
commit 83c533e557
2 changed files with 13 additions and 26 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ jobs:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Build static executable - name: Build static executable
run: nix-build -A postgrestStatic run: nix-build -A postgrestStatic -A postgrestStatic.tests
- name: Save built executable as artifact - name: Save built executable as artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with: with:
+12 -25
View File
@@ -41,32 +41,19 @@ let
lib.compose.justStaticExecutables lib.compose.justStaticExecutables
# To successfully compile a redistributable, fully static executable we need to: # To successfully compile a redistributable, fully static executable we need to:
# 1. make executable really statically linked. # 1. avoid any references to /nix/store to prevent blowing up the closure size.
# 2. avoid any references to /nix/store to prevent blowing up the closure size. (drv: drv.overrideAttrs {
# 3. be able to run the executable. allowedReferences = [
# When checking for references, we ignore the following: pkgsStatic.openssl.etc
# - eeee... are removed references which don't actually exist ];
# - openssl-etc references are purposely designed to be very small })
(lib.compose.overrideCabal (drv: {
postFixup = drv.postFixup + ''
exe="$out/bin/postgrest"
if ! (file "$exe" | grep 'statically linked') then # 2. be able to run the executable.
echo "not a static executable, ldd output:" (drv: drv.overrideAttrs {
ldd "$exe" passthru.tests.version = pkgsStatic.testers.testVersion {
exit 1 package = drv;
fi };
})
echo "Checking for references to /nix/store..."
(${pkgsStatic.binutils}/bin/strings "$exe" \
| grep -v /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee \
| grep -v -etc/etc/ssl \
| grep /nix/store || exit 0 && exit 1)
echo "No references to /nix/store found"
"$exe" --help
'';
}))
]; ];
in in