Hi.
I am trying to build a static binary. I am using
{ project ? import ./nix { }
}:
let
pkgs = project.pkgs.pkgsStatic;
stdenv = pkgs.clang10Stdenv;
mkShell = pkgs.mkShell.override { inherit stdenv; };
in
mkShell {
nativeBuildInputs = [pkgs.musl] ++ builtins.attrValues project.devTools;
shellHook = ''
${project.ci.pre-commit-check.shellHook}
'';
}
Running nix-shell
tries to build musl-static-x86_64-unknown-linux-musl-1.2.2 but it fails with:
Moving /nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/bin/musl-gcc to /nix/store/8l99day2gwzvibfvwhvf36sv7skqvv8p-musl-static-x86_64-unknown-linux-musl-1.2.2-dev/bin/musl-gcc
rmdir: failed to remove '/nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/bin': Directory not empty
Moving /nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/bin/musl-clang to /nix/store/8l99day2gwzvibfvwhvf36sv7skqvv8p-musl-static-x86_64-unknown-linux-musl-1.2.2-dev/bin/musl-clang
rmdir: failed to remove '/nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/bin': Directory not empty
Moving /nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/bin/ld.musl-clang to /nix/store/8l99day2gwzvibfvwhvf36sv7skqvv8p-musl-static-x86_64-unknown-linux-musl-1.2.2-dev/bin/ld.musl-clang
rmdir: failed to remove '/nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/bin': Directory not empty
Moving /nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/lib/musl-gcc.specs to /nix/store/8l99day2gwzvibfvwhvf36sv7skqvv8p-musl-static-x86_64-unknown-linux-musl-1.2.2-dev/lib/musl-gcc.specs
rmdir: failed to remove '/nix/store/6kpc2425qs3yjdqrz8x7rcqjhz8722nh-musl-static-x86_64-unknown-linux-musl-1.2.2/lib': Directory not empty
clang-10: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
/nix/store/635hpnadj6rhz2wbi3yfaxpqb5556qsw-x86_64-unknown-linux-musl-binutils-2.35.1/bin/x86_64-unknown-linux-musl-ld:INSTALL: file format not recognized; treating as linker script
/nix/store/635hpnadj6rhz2wbi3yfaxpqb5556qsw-x86_64-unknown-linux-musl-binutils-2.35.1/bin/x86_64-unknown-linux-musl-ld:INSTALL:2: syntax error
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
builder for '/nix/store/k92sv6w9w5564clwzsj58cj0007kqm8a-musl-static-x86_64-unknown-linux-musl-1.2.2.drv' failed with exit code 1
error: build of '/nix/store/k92sv6w9w5564clwzsj58cj0007kqm8a-musl-static-x86_64-unknown-linux-musl-1.2.2.drv' failed
This seems to be caused by some automatic tooling running after the postInstallPhase I suppose. But why is it trying to run the linker on the INSTALL
file? Any ideas?!
BTW, I also tried to build this from nixpkgs (nix-build -A pkgsStatic.musl
) but this gives the same error. I tried to debug this and added
diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix
index ae175a36324..307e237e657 100644
--- a/pkgs/os-specific/linux/musl/default.nix
+++ b/pkgs/os-specific/linux/musl/default.nix
@@ -137,6 +139,7 @@ stdenv.mkDerivation rec {
install -D ${queue_h} $dev/include/sys/queue.h
install -D ${cdefs_h} $dev/include/sys/cdefs.h
install -D ${tree_h} $dev/include/sys/tree.h
+ echo 'postinstall done'
'';
passthru.linuxHeaders = linuxHeaders;
Into the postInstall script. And it builds:
...
Moving /nix/store/n2c8dzgv0ayzq9fjjxn1lc7rdaz26pac-musl-static-x86_64-unknown-linux-musl-1.2.2/lib/musl-gcc.specs to /nix/store/qqsl2z7dc984j3552nk22777vpwdh5gq-musl-static-x86_64-unknown-linux-musl-1.2.2-dev/lib/musl-gcc.specs
rmdir: failed to remove '/nix/store/n2c8dzgv0ayzq9fjjxn1lc7rdaz26pac-musl-static-x86_64-unknown-linux-musl-1.2.2/lib': Directory not empty
done
postinstall done
post-installation fixup
...
TIA